{"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":"## RNSA ROI detector - yolov5 - training part\n\n1.     Labelled 300 images (taken from competion train DS)\n1.     Trained Yolov5 1024 im size as input\n1.     Validated model_1 (on all images in competion train DS - ~56.000 images) and check missed images - relabeled missed images (50 images - most characteristic patterns). Add new labeled data to train and valid (check to prevent from leak - I was looking on patient_id) - 350 images\n1.     Trained Yolov5 again\n1.     Validated model_2 and check missed images (model_2 improved a lot) - relabeled missed images (50). Add new labeled data to train and valid- 400 images in yolo DS\n1.     Trained Yolov5 again -> model_3 (it performed very well).\n\n\nDataset created using yolo ROI extractor: https://www.kaggle.com/datasets/remekkinas/rsna-breast-cancer-detection-poi-images","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"%%capture \n\n!git clone https://github.com/ultralytics/yolov5\n    \n%cd yolov5\n!wandb disabled","metadata":{"execution":{"iopub.status.busy":"2022-12-11T12:12:30.730066Z","iopub.execute_input":"2022-12-11T12:12:30.730799Z","iopub.status.idle":"2022-12-11T12:12:39.65063Z","shell.execute_reply.started":"2022-12-11T12:12:30.73071Z","shell.execute_reply":"2022-12-11T12:12:39.64905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python train.py --img 1024\\\n--batch 24\\\n--epochs 50\\\n--data /kaggle/input/rsna-roi-detector-annotations-yolo/rsna_annotations/yolo_ds/data.yaml\\\n--hyp /kaggle/input/rsna-roi-detector-annotations-yolo/hyp.bre.yaml --weights yolov5n6.pt","metadata":{"execution":{"iopub.status.busy":"2022-12-11T12:12:39.653317Z","iopub.execute_input":"2022-12-11T12:12:39.653951Z","iopub.status.idle":"2022-12-11T12:24:57.732342Z","shell.execute_reply.started":"2022-12-11T12:12:39.653907Z","shell.execute_reply":"2022-12-11T12:24:57.731196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python detect.py --weights /kaggle/working/yolov5/runs/train/exp/weights/best.pt\\\n--img 1024\\\n--conf 0.5\\\n--source /kaggle/input/rsna-roi-detector-annotations-yolo/roi_samples/roi_samples","metadata":{"execution":{"iopub.status.busy":"2022-12-11T12:24:57.734089Z","iopub.execute_input":"2022-12-11T12:24:57.734468Z","iopub.status.idle":"2022-12-11T12:25:21.837043Z","shell.execute_reply.started":"2022-12-11T12:24:57.734424Z","shell.execute_reply":"2022-12-11T12:25:21.835881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport glob \nimport random\nfrom matplotlib import pyplot as plt\n\nn = 2\nout_files = glob.glob(\"/kaggle/working/yolov5/runs/detect/exp/*.png\")\n\nfig, axs = plt.subplots(1, n, figsize=(25, 25))\nfor idx, im_file in enumerate(random.sample(out_files, n)):\n    im = cv2.imread(im_file)\n    axs[idx].imshow(im)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T12:25:21.839657Z","iopub.execute_input":"2022-12-11T12:25:21.840366Z","iopub.status.idle":"2022-12-11T12:25:25.849317Z","shell.execute_reply.started":"2022-12-11T12:25:21.840323Z","shell.execute_reply":"2022-12-11T12:25:25.84817Z"},"trusted":true},"execution_count":null,"outputs":[]}]}