pavankumarvk commited on
Commit
9c5fca6
·
verified ·
1 Parent(s): 73dc161

Update pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +43 -0
pipeline.py CHANGED
@@ -165,5 +165,48 @@ def deepfakes_image_predict(input_image):
165
  else:
166
  text2 = "The image is FAKE. \n Deepfakes Confidence: " + str(round(fake*100, 3)) + "%"
167
  return text2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
 
 
165
  else:
166
  text2 = "The image is FAKE. \n Deepfakes Confidence: " + str(round(fake*100, 3)) + "%"
167
  return text2
168
+
169
+ def load_audio_model():
170
+ d_args = {
171
+ "nb_samp": 64600,
172
+ "first_conv": 1024,
173
+ "in_channels": 1,
174
+ "filts": [20, [20, 20], [20, 128], [128, 128]],
175
+ "blocks": [2, 4],
176
+ "nb_fc_node": 1024,
177
+ "gru_node": 1024,
178
+ "nb_gru_layer": 3,
179
+ "nb_classes": 2}
180
+
181
+ model = RawNet(d_args = d_args, device='cpu')
182
+
183
+ #Load ckpt.
184
+ model_dict = model.state_dict()
185
+ ckpt = torch.load('RawNet2.pth', map_location=torch.device('cpu'))
186
+ model.load_state_dict(ckpt, model_dict)
187
+ return model
188
+
189
+ audio_label_map = {
190
+ 0: "Real audio",
191
+ 1: "Fake audio"
192
+ }
193
+
194
+ def deepfakes_audio_predict(input_audio):
195
+ #Perform inference on audio.
196
+ x, sr = input_audio
197
+ x_pt = torch.Tensor(x)
198
+ x_pt = torch.unsqueeze(x_pt, dim = 0)
199
+
200
+ #Load model.
201
+ model = load_audio_model()
202
+
203
+ #Perform inference.
204
+ grads = model(x_pt)
205
+
206
+ #Get the argmax.
207
+ grads_np = grads.detach().numpy()
208
+ result = np.argmax(grads_np)
209
+
210
+ return audio_label_map[result]
211
 
212