{"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":"code","source":"import torch\nfrom IPython.display import Image, clear_output  # to display images\n\nclear_output()\nprint('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ..","metadata":{"execution":{"iopub.status.busy":"2021-06-24T21:23:57.147954Z","iopub.execute_input":"2021-06-24T21:23:57.148284Z","iopub.status.idle":"2021-06-24T21:23:57.157949Z","shell.execute_reply.started":"2021-06-24T21:23:57.148217Z","shell.execute_reply":"2021-06-24T21:23:57.157212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!git clone https://github.com/ultralytics/yolov5.git  # clone repo","metadata":{"execution":{"iopub.status.busy":"2021-06-24T21:24:16.879868Z","iopub.execute_input":"2021-06-24T21:24:16.880207Z","iopub.status.idle":"2021-06-24T21:24:19.352042Z","shell.execute_reply.started":"2021-06-24T21:24:16.880173Z","shell.execute_reply":"2021-06-24T21:24:19.351139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd yolov5","metadata":{"execution":{"iopub.status.busy":"2021-06-24T21:24:29.813234Z","iopub.execute_input":"2021-06-24T21:24:29.813562Z","iopub.status.idle":"2021-06-24T21:24:29.819545Z","shell.execute_reply.started":"2021-06-24T21:24:29.813530Z","shell.execute_reply":"2021-06-24T21:24:29.818064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pip install -qr requirements.txt # install dependencies","metadata":{"execution":{"iopub.status.busy":"2021-06-20T18:57:40.680781Z","iopub.execute_input":"2021-06-20T18:57:40.6811Z","iopub.status.idle":"2021-06-20T18:57:48.277205Z","shell.execute_reply.started":"2021-06-20T18:57:40.681067Z","shell.execute_reply":"2021-06-20T18:57:48.276315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!WANDB_MODE=\"dryrun\" python train.py --img 640 --batch 16 --epochs 88 --data ../input/siim-640x640-yaml/siim_data_640x640.yaml --hyp ../input/siim-640x640-yaml/siim640_hyp.scratch.yaml --cfg models/yolov5x.yaml --weights ../input/yolov5-weights/best.pt --name siim","metadata":{"execution":{"iopub.status.busy":"2021-06-24T21:41:24.922683Z","iopub.execute_input":"2021-06-24T21:41:24.923039Z","iopub.status.idle":"2021-06-25T06:01:47.520044Z","shell.execute_reply.started":"2021-06-24T21:41:24.923003Z","shell.execute_reply":"2021-06-25T06:01:47.519108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see that the mAP score hover around ~0.48 after the 32nd epoch, so training again with a lower learning rate might help to get higher mAP score!","metadata":{}},{"cell_type":"code","source":"%cd ..\n%cd working","metadata":{"execution":{"iopub.status.busy":"2021-06-25T06:11:47.427566Z","iopub.execute_input":"2021-06-25T06:11:47.427912Z","iopub.status.idle":"2021-06-25T06:11:47.438632Z","shell.execute_reply.started":"2021-06-25T06:11:47.427875Z","shell.execute_reply":"2021-06-25T06:11:47.437663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Saving the weights**","metadata":{}},{"cell_type":"code","source":"%%time\n!tar -zcf yolov5.tar.gz -C \"/kaggle/yolov5\" .\n#!tar -zcf labels.tar.gz -C \"/kaggle/tmp/labels/\" .","metadata":{"execution":{"iopub.status.busy":"2021-06-25T06:11:51.083976Z","iopub.execute_input":"2021-06-25T06:11:51.084315Z","iopub.status.idle":"2021-06-25T06:13:15.592156Z","shell.execute_reply.started":"2021-06-25T06:11:51.084284Z","shell.execute_reply":"2021-06-25T06:13:15.591185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Download the tar file in the working directory.","metadata":{}},{"cell_type":"code","source":"%cd ..\n%cd yolov5","metadata":{"execution":{"iopub.status.busy":"2021-06-25T06:13:58.387833Z","iopub.execute_input":"2021-06-25T06:13:58.388172Z","iopub.status.idle":"2021-06-25T06:13:58.396421Z","shell.execute_reply.started":"2021-06-25T06:13:58.388134Z","shell.execute_reply":"2021-06-25T06:13:58.395373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize = (15, 15))\nplt.imshow(plt.imread('runs/train/siim5/train_batch0.jpg'))\n\nplt.figure(figsize = (15, 15))\nplt.imshow(plt.imread('runs/train/siim5/train_batch1.jpg'))\n\nplt.figure(figsize = (15, 15))\nplt.imshow(plt.imread('runs/train/siim5/train_batch2.jpg'))","metadata":{"execution":{"iopub.status.busy":"2021-06-25T06:14:23.007056Z","iopub.execute_input":"2021-06-25T06:14:23.007420Z","iopub.status.idle":"2021-06-25T06:14:24.702556Z","shell.execute_reply.started":"2021-06-25T06:14:23.007390Z","shell.execute_reply":"2021-06-25T06:14:24.701541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(3, 2, figsize = (2*5,3*5), constrained_layout = True)\nfor row in range(3):\n    ax[row][0].imshow(plt.imread(f'runs/train/siim5/test_batch{row}_labels.jpg'))\n    ax[row][0].set_xticks([])\n    ax[row][0].set_yticks([])\n    ax[row][0].set_title(f'runs/train/siim5/test_batch{row}_labels.jpg', fontsize = 12)\n    \n    ax[row][1].imshow(plt.imread(f'runs/train/siim5/test_batch{row}_pred.jpg'))\n    ax[row][1].set_xticks([])\n    ax[row][1].set_yticks([])\n    ax[row][1].set_title(f'runs/train/siim5/test_batch{row}_pred.jpg', fontsize = 12)","metadata":{"execution":{"iopub.status.busy":"2021-06-25T06:15:00.155928Z","iopub.execute_input":"2021-06-25T06:15:00.156263Z","iopub.status.idle":"2021-06-25T06:15:01.714282Z","shell.execute_reply.started":"2021-06-25T06:15:00.156229Z","shell.execute_reply":"2021-06-25T06:15:01.713230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30,15))\nplt.axis('off')\nplt.imshow(plt.imread('runs/train/siim5/results.png'));","metadata":{"execution":{"iopub.status.busy":"2021-06-25T06:16:02.327640Z","iopub.execute_input":"2021-06-25T06:16:02.327951Z","iopub.status.idle":"2021-06-25T06:16:03.169788Z","shell.execute_reply.started":"2021-06-25T06:16:02.327922Z","shell.execute_reply":"2021-06-25T06:16:03.168868Z"},"trusted":true},"execution_count":null,"outputs":[]}]}