{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":16880,"databundleVersionId":858837,"sourceType":"competition"},{"sourceId":9442073,"sourceType":"datasetVersion","datasetId":5738021}],"dockerImageVersionId":29844,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input/deepfake-detection-challenge/train_sample_videos'):\n    for filename in filenames:\n        (os.path.join(dirname, filename))\n    json_file = [file for file in filenames if  file.endswith('json')][0]\n    path = os.path.join(dirname, json_file)\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-09-23T05:04:48.033246Z","iopub.execute_input":"2024-09-23T05:04:48.033716Z","iopub.status.idle":"2024-09-23T05:04:48.043716Z","shell.execute_reply.started":"2024-09-23T05:04:48.033507Z","shell.execute_reply":"2024-09-23T05:04:48.042877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dff = pd.read_json(path)\ndff = dff.T\ndff.head()","metadata":{"execution":{"iopub.status.busy":"2024-09-23T05:06:52.924668Z","iopub.execute_input":"2024-09-23T05:06:52.925003Z","iopub.status.idle":"2024-09-23T05:06:53.104206Z","shell.execute_reply.started":"2024-09-23T05:06:52.92495Z","shell.execute_reply":"2024-09-23T05:06:53.103087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"/kaggle/input/dataset-with-label/data.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-09-21T03:38:32.499809Z","iopub.execute_input":"2024-09-21T03:38:32.500071Z","iopub.status.idle":"2024-09-21T03:38:32.514003Z","shell.execute_reply.started":"2024-09-21T03:38:32.50002Z","shell.execute_reply":"2024-09-21T03:38:32.51327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[data['filename']=='aapnvogymq.mp4']","metadata":{"execution":{"iopub.status.busy":"2024-09-21T03:38:32.521152Z","iopub.execute_input":"2024-09-21T03:38:32.521685Z","iopub.status.idle":"2024-09-21T03:38:32.545104Z","shell.execute_reply.started":"2024-09-21T03:38:32.521461Z","shell.execute_reply":"2024-09-21T03:38:32.54421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:34:42.12073Z","iopub.execute_input":"2024-09-21T09:34:42.121024Z","iopub.status.idle":"2024-09-21T09:34:42.382873Z","shell.execute_reply.started":"2024-09-21T09:34:42.120987Z","shell.execute_reply":"2024-09-21T09:34:42.382252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"video_dir = \"/kaggle/input/deepfake-detection-challenge/train_sample_videos\"\n\ndef open_file(file_name):\n    file_path = os.path.join(video_dir, file_name)\n    \n    cap = cv2.VideoCapture(file_path)\n    return cap","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:34:42.500605Z","iopub.execute_input":"2024-09-21T09:34:42.500849Z","iopub.status.idle":"2024-09-21T09:34:42.50525Z","shell.execute_reply.started":"2024-09-21T09:34:42.500808Z","shell.execute_reply":"2024-09-21T09:34:42.504535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"open_file('aapnvogymq.mp4')","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:36:11.331466Z","iopub.execute_input":"2024-09-21T09:36:11.332157Z","iopub.status.idle":"2024-09-21T09:36:11.526736Z","shell.execute_reply.started":"2024-09-21T09:36:11.33177Z","shell.execute_reply":"2024-09-21T09:36:11.525978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install timm","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:34:46.947128Z","iopub.execute_input":"2024-09-21T09:34:46.947416Z","iopub.status.idle":"2024-09-21T09:36:10.572118Z","shell.execute_reply.started":"2024-09-21T09:34:46.947373Z","shell.execute_reply":"2024-09-21T09:36:10.571315Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import Xception","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:36:32.082989Z","iopub.execute_input":"2024-09-21T09:36:32.083344Z","iopub.status.idle":"2024-09-21T09:36:36.706873Z","shell.execute_reply.started":"2024-09-21T09:36:32.083268Z","shell.execute_reply":"2024-09-21T09:36:36.705875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing import image\nfrom tensorflow.keras.applications.xception import preprocess_input, decode_predictions\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:36:36.709123Z","iopub.execute_input":"2024-09-21T09:36:36.709502Z","iopub.status.idle":"2024-09-21T09:36:36.71568Z","shell.execute_reply.started":"2024-09-21T09:36:36.709441Z","shell.execute_reply":"2024-09-21T09:36:36.714771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_Xception = Xception(weights='imagenet')","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:36:36.718376Z","iopub.execute_input":"2024-09-21T09:36:36.718917Z","iopub.status.idle":"2024-09-21T09:36:44.526469Z","shell.execute_reply.started":"2024-09-21T09:36:36.718669Z","shell.execute_reply":"2024-09-21T09:36:44.525481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"video_path = '/kaggle/input/deepfake-detection-challenge/train_sample_videos/aagfhgtpmv.mp4'\ncap = cv2.VideoCapture(video_path)\n\nwhile cap.isOpened():\n    ret, frame = cap.read()\n    \n    if not ret:\n        break\n\n    frame_resized = cv2.resize(frame, (299, 299))\n\n    img_array = image.img_to_array(frame_resized)\n\n    img_array = np.expand_dims(img_array, axis=0)\n\n    img_array = preprocess_input(img_array)\n\n    predictions = model_Xception.predict(img_array)\n\n    decoded_predictions = decode_predictions(predictions, top=5)[0]\n\n    print(\"Frame Predictions:\")\n    for i, (imagenet_id, label, score) in enumerate(decoded_predictions):\n        print(f\"{i + 1}: {label} ({score:.2f})\")\n\n# Release the video capture object\ncap.release()\ncv2.destroyAllWindows()","metadata":{"execution":{"iopub.status.busy":"2024-09-21T09:36:44.529043Z","iopub.execute_input":"2024-09-21T09:36:44.529444Z","iopub.status.idle":"2024-09-21T09:37:05.551714Z","shell.execute_reply.started":"2024-09-21T09:36:44.529375Z","shell.execute_reply":"2024-09-21T09:37:05.55081Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Apprach second","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}