{"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":"In this notebook I will try object detection for DFL data using yolov7's pre-training model.\n\nAs you can see below, it shows reasonable accuracy without fine tuning.\n\nPlease forgive the time it takes to display the page.","metadata":{}},{"cell_type":"code","source":"from IPython.display import Video\nimport os\n\nwidth = 600\nsource = '/kaggle/input/dfl-bundesliga-data-shootout/clips/08fd33_0.mp4'","metadata":{"execution":{"iopub.status.busy":"2022-08-13T05:42:31.475963Z","iopub.execute_input":"2022-08-13T05:42:31.476535Z","iopub.status.idle":"2022-08-13T05:42:31.485012Z","shell.execute_reply.started":"2022-08-13T05:42:31.476497Z","shell.execute_reply":"2022-08-13T05:42:31.484067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!git clone https://github.com/WongKinYiu/yolov7 \n!cd yolov7 && wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt\n!cd yolov7 && wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e.pt","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-08-13T05:42:31.486886Z","iopub.execute_input":"2022-08-13T05:42:31.487504Z","iopub.status.idle":"2022-08-13T05:44:26.773908Z","shell.execute_reply.started":"2022-08-13T05:42:31.487469Z","shell.execute_reply":"2022-08-13T05:44:26.772678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# helper tools\ndef convert_images(input_path, output_path):\n    # adding more codec\n    if os.path.exists(output_path):\n        os.remove(output_path)\n    !ffmpeg -i $input_path -crf 18 -preset veryfast -vcodec libx264 -hide_banner -loglevel error $output_path","metadata":{"execution":{"iopub.status.busy":"2022-08-13T05:44:26.777284Z","iopub.execute_input":"2022-08-13T05:44:26.777723Z","iopub.status.idle":"2022-08-13T05:44:26.784833Z","shell.execute_reply.started":"2022-08-13T05:44:26.777689Z","shell.execute_reply":"2022-08-13T05:44:26.783875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# base model: yolov7\nWith this model, most of the players are detected, but the ball seems to be undetectable enought.","metadata":{}},{"cell_type":"code","source":"!cd yolov7 && python detect.py --weights yolov7.pt --img-size 1280 --source $source --name base","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-08-13T05:44:26.785974Z","iopub.execute_input":"2022-08-13T05:44:26.787763Z","iopub.status.idle":"2022-08-13T05:46:22.105706Z","shell.execute_reply.started":"2022-08-13T05:44:26.787720Z","shell.execute_reply":"2022-08-13T05:46:22.104426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_video = 'yolov7/runs/detect/base/08fd33_0.mp4'\nconvert_images(example_video, '/tmp/out.mp4')\nVideo(data='/tmp/out.mp4',\n              embed=True,\n              width=width)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T05:46:22.108626Z","iopub.execute_input":"2022-08-13T05:46:22.109063Z","iopub.status.idle":"2022-08-13T05:47:07.567087Z","shell.execute_reply.started":"2022-08-13T05:46:22.109018Z","shell.execute_reply":"2022-08-13T05:47:07.564889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# large model: yolov7-e6e with fullsize and confidence 0.1\nThere is a little more noise, but the ball detection accuracy is higher.","metadata":{}},{"cell_type":"code","source":"!cd yolov7 && python detect.py --weights yolov7-e6e.pt --img-size 1920 --source $source --name e6e_full_cnf_01 --conf-thres 0.1","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-08-13T05:47:07.569565Z","iopub.execute_input":"2022-08-13T05:47:07.570072Z","iopub.status.idle":"2022-08-13T05:52:16.181961Z","shell.execute_reply.started":"2022-08-13T05:47:07.570014Z","shell.execute_reply":"2022-08-13T05:52:16.180771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_video = 'yolov7/runs/detect/e6e_full_cnf_01/08fd33_0.mp4'\nconvert_images(example_video, '/tmp/out.mp4')\nVideo(data='/tmp/out.mp4',\n              embed=True,\n              width=width)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T05:52:16.184169Z","iopub.execute_input":"2022-08-13T05:52:16.184583Z","iopub.status.idle":"2022-08-13T05:53:01.691037Z","shell.execute_reply.started":"2022-08-13T05:52:16.184537Z","shell.execute_reply":"2022-08-13T05:53:01.689273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Although the slow detection speed is an issue, the larger models show a reasonably good level of accuracy with respect to ball detection.\n","metadata":{}}]}