File size: 20,973 Bytes
3da0952
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import torch\n",
    "from onnx2pytorch import ConvertModel\n",
    "from keras.models import load_model\n",
    "import onnx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Metal device set to: Apple M1\n",
      "\n",
      "systemMemory: 8.00 GB\n",
      "maxCacheSize: 2.67 GB\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-02-01 19:38:26.414359: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.\n",
      "2024-02-01 19:38:26.414541: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)\n"
     ]
    }
   ],
   "source": [
    "\n",
    "model1 = load_model('/Users/jarvis/pymycod/Deepfakes/DeepDetect/mesonet_trained.hdf5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1/1 [==============================] - 0s 198ms/step\n",
      "the image is realllll boii\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-02-01 14:03:47.045296: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz\n",
      "2024-02-01 14:03:47.118034: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:113] Plugin optimizer for device_type GPU is enabled.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import keras.utils as image\n",
    "\n",
    "img_width, img_height = 256,256\n",
    "img = image.load_img(f'/Users/jarvis/Downloads/im6.jpeg', target_size = (img_width, img_height))\n",
    "img = image.img_to_array(img)\n",
    "img = np.expand_dims(img, axis = 0)\n",
    "ans = model1.predict(img)\n",
    "if ans[0] ==0:\n",
    "    print(\"the image is fake afff\")\n",
    "else:\n",
    "    print(\"the image is realllll boii\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "DecodeError",
     "evalue": "Wrong wire type in tag.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mDecodeError\u001b[0m                               Traceback (most recent call last)",
      "Input \u001b[0;32mIn [11]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m onnx_model \u001b[38;5;241m=\u001b[39m \u001b[43monnx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/Users/jarvis/pymycod/Deepfakes/multimodal_deepfake_detection/checkpoints/efficientnet.onnx\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/onnx/__init__.py:208\u001b[0m, in \u001b[0;36mload_model\u001b[0;34m(f, format, load_external_data)\u001b[0m\n\u001b[1;32m    187\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload_model\u001b[39m(\n\u001b[1;32m    188\u001b[0m     f: IO[\u001b[38;5;28mbytes\u001b[39m] \u001b[38;5;241m|\u001b[39m \u001b[38;5;28mstr\u001b[39m \u001b[38;5;241m|\u001b[39m os\u001b[38;5;241m.\u001b[39mPathLike,\n\u001b[1;32m    189\u001b[0m     \u001b[38;5;28mformat\u001b[39m: _SupportedFormat \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m    190\u001b[0m     load_external_data: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m    191\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ModelProto:\n\u001b[1;32m    192\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Loads a serialized ModelProto into memory.\u001b[39;00m\n\u001b[1;32m    193\u001b[0m \n\u001b[1;32m    194\u001b[0m \u001b[38;5;124;03m    Args:\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    206\u001b[0m \u001b[38;5;124;03m        Loaded in-memory ModelProto.\u001b[39;00m\n\u001b[1;32m    207\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m--> 208\u001b[0m     model \u001b[38;5;241m=\u001b[39m \u001b[43m_get_serializer\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdeserialize_proto\u001b[49m\u001b[43m(\u001b[49m\u001b[43m_load_bytes\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mModelProto\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    210\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m load_external_data:\n\u001b[1;32m    211\u001b[0m         model_filepath \u001b[38;5;241m=\u001b[39m _get_file_path(f)\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/onnx/serialization.py:118\u001b[0m, in \u001b[0;36m_ProtobufSerializer.deserialize_proto\u001b[0;34m(self, serialized, proto)\u001b[0m\n\u001b[1;32m    114\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(serialized, \u001b[38;5;28mbytes\u001b[39m):\n\u001b[1;32m    115\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\n\u001b[1;32m    116\u001b[0m         \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mParameter \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mserialized\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m must be bytes, but got type: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mtype\u001b[39m(serialized)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    117\u001b[0m     )\n\u001b[0;32m--> 118\u001b[0m decoded \u001b[38;5;241m=\u001b[39m typing\u001b[38;5;241m.\u001b[39mcast(Optional[\u001b[38;5;28mint\u001b[39m], \u001b[43mproto\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mParseFromString\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserialized\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m    119\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m decoded \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m decoded \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mlen\u001b[39m(serialized):\n\u001b[1;32m    120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m google\u001b[38;5;241m.\u001b[39mprotobuf\u001b[38;5;241m.\u001b[39mmessage\u001b[38;5;241m.\u001b[39mDecodeError(\n\u001b[1;32m    121\u001b[0m         \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mProtobuf decoding consumed too few bytes: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdecoded\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m out of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlen\u001b[39m(serialized)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    122\u001b[0m     )\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/google/protobuf/message.py:202\u001b[0m, in \u001b[0;36mMessage.ParseFromString\u001b[0;34m(self, serialized)\u001b[0m\n\u001b[1;32m    194\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Parse serialized protocol buffer data into this message.\u001b[39;00m\n\u001b[1;32m    195\u001b[0m \n\u001b[1;32m    196\u001b[0m \u001b[38;5;124;03mLike :func:`MergeFromString()`, except we clear the object first.\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    199\u001b[0m \u001b[38;5;124;03m  message.DecodeError if the input cannot be parsed.\u001b[39;00m\n\u001b[1;32m    200\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m    201\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mClear()\n\u001b[0;32m--> 202\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mMergeFromString\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserialized\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/google/protobuf/internal/python_message.py:1128\u001b[0m, in \u001b[0;36m_AddMergeFromStringMethod.<locals>.MergeFromString\u001b[0;34m(self, serialized)\u001b[0m\n\u001b[1;32m   1126\u001b[0m length \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlen\u001b[39m(serialized)\n\u001b[1;32m   1127\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 1128\u001b[0m   \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_InternalParse\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserialized\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlength\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;241m!=\u001b[39m length:\n\u001b[1;32m   1129\u001b[0m     \u001b[38;5;66;03m# The only reason _InternalParse would return early is if it\u001b[39;00m\n\u001b[1;32m   1130\u001b[0m     \u001b[38;5;66;03m# encountered an end-group tag.\u001b[39;00m\n\u001b[1;32m   1131\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m message_mod\u001b[38;5;241m.\u001b[39mDecodeError(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUnexpected end-group tag.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m   1132\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (\u001b[38;5;167;01mIndexError\u001b[39;00m, \u001b[38;5;167;01mTypeError\u001b[39;00m):\n\u001b[1;32m   1133\u001b[0m   \u001b[38;5;66;03m# Now ord(buf[p:p+1]) == ord('') gets TypeError.\u001b[39;00m\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/google/protobuf/internal/python_message.py:1181\u001b[0m, in \u001b[0;36m_AddMergeFromStringMethod.<locals>.InternalParse\u001b[0;34m(self, buffer, pos, end)\u001b[0m\n\u001b[1;32m   1179\u001b[0m \u001b[38;5;66;03m# TODO(jieluo): remove old_pos.\u001b[39;00m\n\u001b[1;32m   1180\u001b[0m old_pos \u001b[38;5;241m=\u001b[39m new_pos\n\u001b[0;32m-> 1181\u001b[0m (data, new_pos) \u001b[38;5;241m=\u001b[39m \u001b[43mdecoder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_DecodeUnknownField\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m   1182\u001b[0m \u001b[43m    \u001b[49m\u001b[43mbuffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_pos\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mwire_type\u001b[49m\u001b[43m)\u001b[49m  \u001b[38;5;66;03m# pylint: disable=protected-access\u001b[39;00m\n\u001b[1;32m   1183\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_pos \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m   1184\u001b[0m   \u001b[38;5;28;01mreturn\u001b[39;00m pos\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/google/protobuf/internal/decoder.py:965\u001b[0m, in \u001b[0;36m_DecodeUnknownField\u001b[0;34m(buffer, pos, wire_type)\u001b[0m\n\u001b[1;32m    963\u001b[0m   \u001b[38;5;28;01mreturn\u001b[39;00m (\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m    964\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 965\u001b[0m   \u001b[38;5;28;01mraise\u001b[39;00m _DecodeError(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mWrong wire type in tag.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m    967\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (data, pos)\n",
      "\u001b[0;31mDecodeError\u001b[0m: Wrong wire type in tag."
     ]
    }
   ],
   "source": [
    "\n",
    "onnx_model = onnx.load('/Users/jarvis/pymycod/Deepfakes/multimodal_deepfake_detection/checkpoints/efficientnet.onnx')\n",
    "# pytorch_model = ConvertModel(onnx_model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def load_img_modality_model(args):\n",
    "    '''Loads image modality model.'''\n",
    "    rgb_encoder = pytorch_model\n",
    "\n",
    "    ckpt = torch.load('checkpoints/model.pth', map_location = torch.device('cpu'))\n",
    "    rgb_encoder.load_state_dict(ckpt['rgb_encoder'], strict = True)\n",
    "    rgb_encoder.eval()\n",
    "    return rgb_encoder\n",
    "img_model = load_img_modality_model(args)\n",
    "\n",
    "def preprocess_img(face):\n",
    "    face = face / 255\n",
    "    face = cv2.resize(face, (256, 256))\n",
    "    # face = face.transpose(2, 0, 1) #(W, H, C) -> (C, W, H)\n",
    "    face_pt = torch.unsqueeze(torch.Tensor(face), dim = 0) \n",
    "    return face_pt\n",
    "def preprocess_video(input_video, n_frames = 3):\n",
    "    v_cap = cv2.VideoCapture(input_video)\n",
    "    v_len = int(v_cap.get(cv2.CAP_PROP_FRAME_COUNT))\n",
    "\n",
    "    # Pick 'n_frames' evenly spaced frames to sample\n",
    "    if n_frames is None:\n",
    "        sample = np.arange(0, v_len)\n",
    "    else:\n",
    "        sample = np.linspace(0, v_len - 1, n_frames).astype(int)\n",
    "\n",
    "    #Loop through frames.\n",
    "    frames = []\n",
    "    for j in range(v_len):\n",
    "        success = v_cap.grab()\n",
    "        if j in sample:\n",
    "            # Load frame\n",
    "            success, frame = v_cap.retrieve()\n",
    "            if not success:\n",
    "                continue\n",
    "            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n",
    "            frame = preprocess_img(frame)\n",
    "            frames.append(frame)\n",
    "    v_cap.release()\n",
    "    return frames\n",
    "\n",
    "\n",
    "def deepfakes_video_predict(input_video):\n",
    "    '''Perform inference on a video.'''\n",
    "    video_frames = preprocess_video(input_video)\n",
    "    real_faces_list = []\n",
    "    fake_faces_list = []\n",
    "\n",
    "    for face in video_frames:\n",
    "        # face = preprocess_img(face)\n",
    "\n",
    "        img_grads = img_model.forward(face)\n",
    "        img_grads = img_grads.cpu().detach().numpy()\n",
    "        img_grads_np = np.squeeze(img_grads)\n",
    "        real_faces_list.append(img_grads_np[0])\n",
    "        fake_faces_list.append(img_grads_np[1])\n",
    "\n",
    "    real_faces_mean = np.mean(real_faces_list)\n",
    "    fake_faces_mean = np.mean(fake_faces_list)\n",
    "\n",
    "    if real_faces_mean > 0.5:\n",
    "        preds = round(real_faces_mean * 100, 3)\n",
    "        text2 = f\"The video is REAL. \\nConfidence score is: {preds}%\"\n",
    "\n",
    "    else:\n",
    "        preds = round(fake_faces_mean * 100, 3)\n",
    "        text2 = f\"The video is FAKE. \\nConfidence score is: {preds}%\"\n",
    "\n",
    "    return text2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Functional' object has no attribute 'forward'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Input \u001b[0;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdeepfakes_video_predict\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/Users/jarvis/Documents/Ss/ras_df.mov\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "Input \u001b[0;32mIn [24]\u001b[0m, in \u001b[0;36mdeepfakes_video_predict\u001b[0;34m(input_video)\u001b[0m\n\u001b[1;32m     37\u001b[0m fake_faces_list \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m     39\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m face \u001b[38;5;129;01min\u001b[39;00m video_frames:\n\u001b[1;32m     40\u001b[0m     \u001b[38;5;66;03m# face = preprocess_img(face)\u001b[39;00m\n\u001b[0;32m---> 42\u001b[0m     img_grads \u001b[38;5;241m=\u001b[39m \u001b[43mmodel1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mforward\u001b[49m(face)\n\u001b[1;32m     43\u001b[0m     img_grads \u001b[38;5;241m=\u001b[39m img_grads\u001b[38;5;241m.\u001b[39mcpu()\u001b[38;5;241m.\u001b[39mdetach()\u001b[38;5;241m.\u001b[39mnumpy()\n\u001b[1;32m     44\u001b[0m     img_grads_np \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39msqueeze(img_grads)\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'Functional' object has no attribute 'forward'"
     ]
    }
   ],
   "source": [
    "deepfakes_video_predict(\"/Users/jarvis/Documents/Ss/ras_df.mov\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValidationError",
     "evalue": "Unable to parse proto from file: /Users/jarvis/pymycod/Deepfakes/multimodal_deepfake_detection/checkpoints/efficientnet.onnx. Please check if it is a valid protobuf file of proto. ",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValidationError\u001b[0m                           Traceback (most recent call last)",
      "Input \u001b[0;32mIn [10]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01monnx\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m checker\n\u001b[0;32m----> 3\u001b[0m \u001b[43mchecker\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcheck_model\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/Users/jarvis/pymycod/Deepfakes/multimodal_deepfake_detection/checkpoints/efficientnet.onnx\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/anaconda3/envs/tensor/lib/python3.8/site-packages/onnx/checker.py:137\u001b[0m, in \u001b[0;36mcheck_model\u001b[0;34m(model, full_check, skip_opset_compatibility_check)\u001b[0m\n\u001b[1;32m    135\u001b[0m \u001b[38;5;66;03m# If model is a path instead of ModelProto\u001b[39;00m\n\u001b[1;32m    136\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(model, (\u001b[38;5;28mstr\u001b[39m, os\u001b[38;5;241m.\u001b[39mPathLike)):\n\u001b[0;32m--> 137\u001b[0m     \u001b[43mC\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcheck_model_path\u001b[49m\u001b[43m(\u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfspath\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfull_check\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mskip_opset_compatibility_check\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    138\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m    139\u001b[0m     protobuf_string \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m    140\u001b[0m         model \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(model, \u001b[38;5;28mbytes\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m model\u001b[38;5;241m.\u001b[39mSerializeToString()\n\u001b[1;32m    141\u001b[0m     )\n",
      "\u001b[0;31mValidationError\u001b[0m: Unable to parse proto from file: /Users/jarvis/pymycod/Deepfakes/multimodal_deepfake_detection/checkpoints/efficientnet.onnx. Please check if it is a valid protobuf file of proto. "
     ]
    }
   ],
   "source": [
    "from onnx import checker\n",
    "\n",
    "checker.check_model(\"/Users/jarvis/pymycod/Deepfakes/multimodal_deepfake_detection/checkpoints/efficientnet.onnx\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tensor",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}