{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import torch, torchaudio, timm, transformers\nprint(\"torch:\", torch.__version__)\nprint(\"transformers:\", transformers.__version__)\nprint(\"CUDA available:\", torch.cuda.is_available())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:20:00.441992Z","iopub.execute_input":"2026-08-09T17:20:00.442784Z","iopub.status.idle":"2026-08-09T17:20:23.055881Z","shell.execute_reply.started":"2026-08-09T17:20:00.442752Z","shell.execute_reply":"2026-08-09T17:20:23.055152Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls /kaggle/input/datasets/","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:21:07.666412Z","iopub.execute_input":"2026-08-09T17:21:07.667451Z","iopub.status.idle":"2026-08-09T17:21:07.797593Z","shell.execute_reply.started":"2026-08-09T17:21:07.667416Z","shell.execute_reply":"2026-08-09T17:21:07.796909Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls /kaggle/input/datasets/shuvochakraborty35/","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:21:12.869889Z","iopub.execute_input":"2026-08-09T17:21:12.870218Z","iopub.status.idle":"2026-08-09T17:21:13.001332Z","shell.execute_reply.started":"2026-08-09T17:21:12.870187Z","shell.execute_reply":"2026-08-09T17:21:13.000601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp -r /kaggle/input/datasets/shuvochakraborty35/multimodaldeepfake-complete1/MultimodalDeepfake /kaggle/working/\n%cd /kaggle/working/MultimodalDeepfake\n!ls","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:21:22.949328Z","iopub.execute_input":"2026-08-09T17:21:22.949645Z","iopub.status.idle":"2026-08-09T17:21:23.245417Z","shell.execute_reply.started":"2026-08-09T17:21:22.949615Z","shell.execute_reply":"2026-08-09T17:21:23.244636Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python scripts/build_manifest.py","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:21:27.794334Z","iopub.execute_input":"2026-08-09T17:21:27.794647Z","iopub.status.idle":"2026-08-09T17:27:01.279702Z","shell.execute_reply.started":"2026-08-09T17:21:27.794616Z","shell.execute_reply":"2026-08-09T17:27:01.278934Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!rm -rf outputs/checkpoints/* outputs/logs/* 2>/dev/null","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:31:30.940473Z","iopub.execute_input":"2026-08-09T17:31:30.941195Z","iopub.status.idle":"2026-08-09T17:31:31.072665Z","shell.execute_reply.started":"2026-08-09T17:31:30.941136Z","shell.execute_reply":"2026-08-09T17:31:31.071632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"path = \"datasets/dataset.py\"\ncontent = open(path).read()\ncontent = content.replace(\n    '    \"\"\"Convenience factory: reads the manifest, splits it, wraps in DataLoaders.\"\"\"\\n    from torch.utils.data import DataLoader, WeightedRandomSampler',\n    '    \"\"\"Convenience factory: reads the manifest, splits it, wraps in DataLoaders.\"\"\"\\n    import torch\\n    from torch.utils.data import DataLoader, WeightedRandomSampler'\n)\nopen(path, \"w\").write(content)\nprint(\"Patched — 'import torch' added to get_dataloaders()\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-09T17:31:33.398897Z","iopub.execute_input":"2026-08-09T17:31:33.399197Z","iopub.status.idle":"2026-08-09T17:31:33.406223Z","shell.execute_reply.started":"2026-08-09T17:31:33.399167Z","shell.execute_reply":"2026-08-09T17:31:33.405558Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python main.py --mode train --config configs/config.yaml","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python main.py --mode test --config configs/config.yaml --checkpoint outputs/checkpoints/best_model.pt","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import json\nwith open(\"outputs/test_metrics.json\") as f:\n    metrics = json.load(f)\nprint(json.dumps(metrics, indent=4))","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python scripts/tta_test.py --config configs/config.yaml --checkpoint outputs/checkpoints/best_model.pt","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import json\nwith open(\"outputs/test_metrics.json\") as f:\n    normal = json.load(f)\nwith open(\"outputs/test_metrics_tta.json\") as f:\n    tta = json.load(f)\n\nprint(\"Metric\".ljust(20), \"Normal\".ljust(10), \"TTA\")\nfor key in [\"accuracy\", \"precision_macro\", \"recall_macro\", \"f1_macro\", \"roc_auc_ovr\", \"binary_accuracy\", \"binary_f1\"]:\n    print(key.ljust(20), f\"{normal[key]:.4f}\".ljust(10), f\"{tta[key]:.4f}\")","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python scripts/tune_threshold.py","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.display import Image, display\nimport os\nfor fname in [\"confusion_matrix.png\", \"confusion_matrix_tta.png\", \"binary_confusion_matrix.png\",\n              \"binary_confusion_matrix_tta.png\", \"roc_curve.png\", \"roc_curve_tta.png\",\n              \"pr_curve.png\", \"loss_curves.png\", \"tsne_embeddings.png\"]:\n    path = f\"outputs/figures/{fname}\"\n    if os.path.exists(path):\n        print(fname)\n        display(Image(path))","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!zip -r /kaggle/working/final_results.zip outputs/\nprint(\"Done — download final_results.zip from the Output tab\")","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}