{"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":"Hey guys,\n\nThis Yolov7-e6e model gives us the most efficient results with consistent accuracy and less time. It is a very simple and beginner friendly pre-trained model to label and track the football and yet incredibly potent used to resolve a dynamic range of computer vision problems.\n\nReference: https://www.kaggle.com/code/its7171/yolov7-demo-with-dfl","metadata":{}},{"cell_type":"markdown","source":"# Imports and Set Up","metadata":{}},{"cell_type":"code","source":"# import sys\n# sys.path.append(\"../input/yolov7-weights/yolov7-e6e.pt\")\n# WEIGHTS = \"/kaggle/input/yolov7-weights/yolov7.pt\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import Video\nimport os\nimport sys\n\nsys.path.append(\"../input/yolov7-weights/yolov7-e6e.pt\")\nWEIGHTS = \"/kaggle/input/yolov7-weights/yolov7.pt\"\n\nwidth = 600\nsource = '/kaggle/input/dfl-bundesliga-data-shootout/clips/08fd33_0.mp4'\n# model = '/kaggle/input/yolov7-weights/YOLOv7_weights/yolov7-e6e.pt'","metadata":{"execution":{"iopub.status.busy":"2022-08-14T07:07:05.862224Z","iopub.execute_input":"2022-08-14T07:07:05.862720Z","iopub.status.idle":"2022-08-14T07:07:05.876321Z","shell.execute_reply.started":"2022-08-14T07:07:05.862594Z","shell.execute_reply":"2022-08-14T07:07:05.874973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Note that we are using the first clip from the given dataset","metadata":{}},{"cell_type":"markdown","source":"Cloning the repository in our code","metadata":{}},{"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-e6e.pt","metadata":{"_kg_hide-output":true,"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-14T07:07:19.642997Z","iopub.execute_input":"2022-08-14T07:07:19.643412Z","iopub.status.idle":"2022-08-14T07:07:19.650676Z","shell.execute_reply.started":"2022-08-14T07:07:19.643379Z","shell.execute_reply":"2022-08-14T07:07:19.649206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Training yolov7-e6e with fullsize and confidence 0.5\n","metadata":{}},{"cell_type":"markdown","source":"This results with a formidable accuracy, although, some time could be compromised a bit.\n\nYou can furthermore decrease the confidence threshold to 0.1 to achieve an outstanding accuracy of highest degree. However, it's not just time you are compensating on but also the amount of noise and inaccurate bounding boxes that spread across the video.\n\nTo save some time you could use different Yolov7 model such as yolov7-tiny, yolov7-X or just yolov7.","metadata":{}},{"cell_type":"code","source":"!cd yolov7 && python detect.py --weights $WEIGHTS --img-size 1920 --source $source --name e6e_full_cnf_01 --conf-thres 0.5","metadata":{"_kg_hide-output":true,"_kg_hide-input":false,"execution":{"iopub.status.busy":"2022-08-14T07:07:35.376538Z","iopub.execute_input":"2022-08-14T07:07:35.376981Z","iopub.status.idle":"2022-08-14T07:08:53.782862Z","shell.execute_reply.started":"2022-08-14T07:07:35.376945Z","shell.execute_reply":"2022-08-14T07:08:53.781793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Displaying Results","metadata":{}},{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Thank you for joining!**","metadata":{}}]}