{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Use this notebook to make submission.\n## Make sure to check these requirements\n1. Internet should be turned off for notebook from the left panel -> settings.\n2. Personal dataset containing model weights should not be taken from any link or google drive. It should be uploaded from you computer or uploaded via kaggle api.\n3. You only need to implement predict_on_video function and it should return a float value. \n4. Confirm the time limit by setting speed_test = True in just the cell below predict_on_video function. And remember to set it to False when commiting."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"#Don't change this\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport time","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Space for extra imports"},{"metadata":{"trusted":true},"cell_type":"code","source":"# import here\n\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Don't change this\ntest_dir = \"/kaggle/input/deepfake-detection-challenge/test_videos/\"\ntest_videos = sorted([x for x in os.listdir(test_dir) if x[-4:] == \".mp4\"])\nlen(test_videos)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Use this space to define and load model weights. "},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Implement the prediction function"},{"metadata":{"trusted":true},"cell_type":"code","source":"def predict_on_video(video_path):\n    # Implement this function. It will take video path and should output the prediction as float.\n    \n    \n    return 0.5","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Prediction"},{"metadata":{},"cell_type":"markdown","source":"### Set speed test to true and see the output after prediction on starting ten vids. Confirm it matches the requirement."},{"metadata":{"trusted":true},"cell_type":"code","source":"speed_test = False ## Remember to set it to False when commiting the notebook for submission","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Don't change this\nstart = time.perf_counter()\nn = 10 if speed_test else len(test_videos)\npredictions = []\nfor i,video in enumerate(test_videos):\n    if i==n:\n        # if speed test\n        break\n        \n    if i%20 ==19:\n        # log at commit screen\n        os.system(f'echo {str(i)} {predictions[-1]:.2f}')\n    \n    try:\n        prediction = predict_on_video(test_dir+video)\n        \n        #test for valid prediction\n        if prediction is not None: \n            predictions.append(prediction)\n        else:\n            predictions.append(0.5)\n        \n    except Exception as e:\n        # Report Error at Commit \n        os.system(f'echo {str(e)}')\n        predictions.append(0.5)\n\nprint(f'{(time.perf_counter()-start)/n:.2f}s per video. Should be less then 8s for a valid submission')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Cleaning extra files created during prediction"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Don't change this\nimport os, shutil\nfolder = '/kaggle/working'\nfor filename in os.listdir(folder):\n    file_path = os.path.join(folder, filename)\n    try:\n        if os.path.isfile(file_path) or os.path.islink(file_path):\n            os.unlink(file_path)\n        elif os.path.isdir(file_path):\n            shutil.rmtree(file_path)\n    except Exception as e:\n        print('Failed to delete %s. Reason: %s' % (file_path, e))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Writing Csv"},{"metadata":{"trusted":true},"cell_type":"code","source":"#Don't change this\n# creating and writing csv\nsubmission_df = pd.DataFrame({\"filename\": test_videos, \"label\": predictions})\nsubmission_df.to_csv(\"submission.csv\", index=False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}