{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## 00. Imports","metadata":{}},{"cell_type":"code","source":"import os\n\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:08.096874Z","iopub.execute_input":"2023-01-03T20:57:08.097369Z","iopub.status.idle":"2023-01-03T20:57:08.120030Z","shell.execute_reply.started":"2023-01-03T20:57:08.097290Z","shell.execute_reply":"2023-01-03T20:57:08.119238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 01. Settings","metadata":{}},{"cell_type":"code","source":"SOURCE_DIRECTORY_PATH = '/kaggle/input/nfl-player-contact-detection'\n\nMODEL_WEIGHTS_PATH = '/kaggle/input/yolov5-v6-0-helmet-detection/yolov5_weight/exp/weights/best.pt'","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:16.919271Z","iopub.execute_input":"2023-01-03T20:57:16.919641Z","iopub.status.idle":"2023-01-03T20:57:16.924768Z","shell.execute_reply.started":"2023-01-03T20:57:16.919608Z","shell.execute_reply":"2023-01-03T20:57:16.923617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GAME_PLAY_COLUMN = 'game_play'","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:18.474582Z","iopub.execute_input":"2023-01-03T20:57:18.475178Z","iopub.status.idle":"2023-01-03T20:57:18.479928Z","shell.execute_reply.started":"2023-01-03T20:57:18.475144Z","shell.execute_reply":"2023-01-03T20:57:18.478872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 02. Install YOLOv5","metadata":{}},{"cell_type":"code","source":"!git clone https://github.com/ultralytics/yolov5\n%cd yolov5\n!pip install -r requirements.txt","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:20.816590Z","iopub.execute_input":"2023-01-03T20:57:20.816959Z","iopub.status.idle":"2023-01-03T20:57:35.353720Z","shell.execute_reply.started":"2023-01-03T20:57:20.816926Z","shell.execute_reply":"2023-01-03T20:57:35.352485Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 03. Test inference with YOLOv5","metadata":{}},{"cell_type":"code","source":"SOURCE_VIDEO_PATH_1 = '/kaggle/input/nfl-player-contact-detection/train/58168_003392_All29.mp4'\nSOURCE_VIDEO_PATH_2 = '/kaggle/input/nfl-player-contact-detection/train/58168_003392_Endzone.mp4'\nSOURCE_VIDEO_PATH_3 = '/kaggle/input/nfl-player-contact-detection/train/58168_003392_Sideline.mp4'","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:38.296092Z","iopub.execute_input":"2023-01-03T20:57:38.296500Z","iopub.status.idle":"2023-01-03T20:57:38.302393Z","shell.execute_reply.started":"2023-01-03T20:57:38.296461Z","shell.execute_reply":"2023-01-03T20:57:38.300659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cd /kaggle/working/yolov5","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:39.170503Z","iopub.execute_input":"2023-01-03T20:57:39.170870Z","iopub.status.idle":"2023-01-03T20:57:40.104838Z","shell.execute_reply.started":"2023-01-03T20:57:39.170840Z","shell.execute_reply":"2023-01-03T20:57:40.103558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python detect.py --weights $MODEL_WEIGHTS_PATH --img 800 --conf 0.4 --source $SOURCE_VIDEO_PATH_1","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:57:41.536528Z","iopub.execute_input":"2023-01-03T20:57:41.536921Z","iopub.status.idle":"2023-01-03T20:58:33.272369Z","shell.execute_reply.started":"2023-01-03T20:57:41.536886Z","shell.execute_reply":"2023-01-03T20:58:33.271183Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python detect.py --weights $MODEL_WEIGHTS_PATH --img 800 --conf 0.4 --source $SOURCE_VIDEO_PATH_2","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:58:57.969525Z","iopub.execute_input":"2023-01-03T20:58:57.969910Z","iopub.status.idle":"2023-01-03T20:59:34.248356Z","shell.execute_reply.started":"2023-01-03T20:58:57.969877Z","shell.execute_reply":"2023-01-03T20:59:34.247227Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python detect.py --weights $MODEL_WEIGHTS_PATH --img 800 --conf 0.4 --source $SOURCE_VIDEO_PATH_3","metadata":{"execution":{"iopub.status.busy":"2023-01-03T21:00:04.793697Z","iopub.execute_input":"2023-01-03T21:00:04.794109Z","iopub.status.idle":"2023-01-03T21:00:41.493758Z","shell.execute_reply.started":"2023-01-03T21:00:04.794073Z","shell.execute_reply":"2023-01-03T21:00:41.492578Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_player_tracking = pd.read_csv(os.path.join(SOURCE_DIRECTORY_PATH, 'train_player_tracking.csv'))","metadata":{"execution":{"iopub.status.busy":"2023-01-03T19:44:56.853524Z","iopub.execute_input":"2023-01-03T19:44:56.854006Z","iopub.status.idle":"2023-01-03T19:45:01.944472Z","shell.execute_reply.started":"2023-01-03T19:44:56.853969Z","shell.execute_reply":"2023-01-03T19:45:01.942820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import FileLink","metadata":{"execution":{"iopub.status.busy":"2023-01-03T21:01:53.401709Z","iopub.execute_input":"2023-01-03T21:01:53.402411Z","iopub.status.idle":"2023-01-03T21:01:53.410125Z","shell.execute_reply.started":"2023-01-03T21:01:53.402364Z","shell.execute_reply":"2023-01-03T21:01:53.409114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FileLink(r'/kaggle/working/yolov5/runs/detect/exp/58168_003392_All29.mp4')","metadata":{"execution":{"iopub.status.busy":"2023-01-03T21:03:02.518552Z","iopub.execute_input":"2023-01-03T21:03:02.518964Z","iopub.status.idle":"2023-01-03T21:03:02.528670Z","shell.execute_reply.started":"2023-01-03T21:03:02.518929Z","shell.execute_reply":"2023-01-03T21:03:02.527727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls /kaggle/working/yolov5/runs/detect/exp/58168_003392_All29.mp4","metadata":{"execution":{"iopub.status.busy":"2023-01-03T21:02:39.281040Z","iopub.execute_input":"2023-01-03T21:02:39.281425Z","iopub.status.idle":"2023-01-03T21:02:40.225700Z","shell.execute_reply.started":"2023-01-03T21:02:39.281391Z","shell.execute_reply":"2023-01-03T21:02:40.224496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nos.chdir(r'/kaggle/working')","metadata":{"execution":{"iopub.status.busy":"2023-01-03T21:05:44.893415Z","iopub.execute_input":"2023-01-03T21:05:44.894174Z","iopub.status.idle":"2023-01-03T21:05:44.899225Z","shell.execute_reply.started":"2023-01-03T21:05:44.894134Z","shell.execute_reply":"2023-01-03T21:05:44.897973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!tar -czf detect.tar.gz /kaggle/working/yolov5/runs/detect\n\nfrom IPython.display import FileLink\n\nFileLink(r'detect.tar.gz')","metadata":{"execution":{"iopub.status.busy":"2023-01-03T21:06:23.250973Z","iopub.execute_input":"2023-01-03T21:06:23.251338Z","iopub.status.idle":"2023-01-03T21:06:28.554277Z","shell.execute_reply.started":"2023-01-03T21:06:23.251306Z","shell.execute_reply":"2023-01-03T21:06:28.553252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_player_tracking","metadata":{"execution":{"iopub.status.busy":"2023-01-03T19:45:11.388862Z","iopub.execute_input":"2023-01-03T19:45:11.390352Z","iopub.status.idle":"2023-01-03T19:45:11.437563Z","shell.execute_reply.started":"2023-01-03T19:45:11.390297Z","shell.execute_reply":"2023-01-03T19:45:11.436269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls ../input/nfl-player-contact-detection/train | grep 58580_001136","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:01:01.823903Z","iopub.execute_input":"2023-01-03T20:01:01.824441Z","iopub.status.idle":"2023-01-03T20:01:02.953450Z","shell.execute_reply.started":"2023-01-03T20:01:01.824399Z","shell.execute_reply":"2023-01-03T20:01:02.952181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_player_tracking[df_train_player_tracking[GAME_PLAY_COLUMN] == '58580_001136']","metadata":{"execution":{"iopub.status.busy":"2023-01-03T20:04:24.324693Z","iopub.execute_input":"2023-01-03T20:04:24.325106Z","iopub.status.idle":"2023-01-03T20:04:24.507173Z","shell.execute_reply.started":"2023-01-03T20:04:24.325073Z","shell.execute_reply":"2023-01-03T20:04:24.505597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}