{"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 os\nHOME = os.getcwd()\nprint(HOME)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-06-14T10:23:46.905421Z","iopub.execute_input":"2023-06-14T10:23:46.906125Z","iopub.status.idle":"2023-06-14T10:23:46.914069Z","shell.execute_reply.started":"2023-06-14T10:23:46.906089Z","shell.execute_reply":"2023-06-14T10:23:46.913094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%capture\n!mkdir /kaggle/working/packages\n!cp -r /kaggle/input/pycocotools/* /kaggle/working/packages\nos.chdir(\"/kaggle/working/packages/pycocotools-2.0.6/\")\n!python setup.py install\n!pip install . --no-index --find-links /kaggle/working/packages/\nos.chdir(\"/kaggle/working\")\n\nfrom pycocotools import _mask as coco_mask","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:23:46.916158Z","iopub.execute_input":"2023-06-14T10:23:46.916960Z","iopub.status.idle":"2023-06-14T10:24:04.195786Z","shell.execute_reply.started":"2023-06-14T10:23:46.916927Z","shell.execute_reply":"2023-06-14T10:24:04.194468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Pip install method (recommended)\n# %pip install ultralytics\n%pip install --no-index -f /kaggle/input/ultralytics-offline ultralytics\n\nimport ultralytics","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:04.198598Z","iopub.execute_input":"2023-06-14T10:24:04.199015Z","iopub.status.idle":"2023-06-14T10:24:15.828052Z","shell.execute_reply.started":"2023-06-14T10:24:04.198977Z","shell.execute_reply":"2023-06-14T10:24:15.826892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import base64\nimport numpy as np\nfrom pycocotools import _mask as coco_mask\nimport typing as t\nimport zlib\nfrom ultralytics import YOLO\nfrom PIL import Image\nimport cv2\nimport pandas as pd\nimport os\nimport wandb\nfrom itertools import groupby\nfrom skimage.measure import label, regionprops","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:15.829768Z","iopub.execute_input":"2023-06-14T10:24:15.830400Z","iopub.status.idle":"2023-06-14T10:24:15.837564Z","shell.execute_reply.started":"2023-06-14T10:24:15.830361Z","shell.execute_reply":"2023-06-14T10:24:15.836261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!nvidia-smi","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:15.841002Z","iopub.execute_input":"2023-06-14T10:24:15.841335Z","iopub.status.idle":"2023-06-14T10:24:16.824038Z","shell.execute_reply.started":"2023-06-14T10:24:15.841300Z","shell.execute_reply":"2023-06-14T10:24:16.822822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wandb.init(mode=\"disabled\")\nultralytics.checks()\n# os.makedirs('datasets', exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:16.827024Z","iopub.execute_input":"2023-06-14T10:24:16.827368Z","iopub.status.idle":"2023-06-14T10:24:16.857630Z","shell.execute_reply.started":"2023-06-14T10:24:16.827339Z","shell.execute_reply":"2023-06-14T10:24:16.856732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\ndest = shutil.copytree(\n    \"/kaggle/input/yolo-format-human-vasculature/datasets\",\n    \"/kaggle/working\", dirs_exist_ok=True\n)","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:16.859055Z","iopub.execute_input":"2023-06-14T10:24:16.860078Z","iopub.status.idle":"2023-06-14T10:24:17.655442Z","shell.execute_reply.started":"2023-06-14T10:24:16.860046Z","shell.execute_reply":"2023-06-14T10:24:17.653257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dest = shutil.copy(\n    \"/kaggle/input/yolo-format-human-vasculature/hub-map.yaml\",\n    \"/kaggle/working\"\n)","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:17.656613Z","iopub.status.idle":"2023-06-14T10:24:17.658265Z","shell.execute_reply.started":"2023-06-14T10:24:17.658010Z","shell.execute_reply":"2023-06-14T10:24:17.658035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wandb disabled","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:17.659752Z","iopub.status.idle":"2023-06-14T10:24:17.660538Z","shell.execute_reply.started":"2023-06-14T10:24:17.660292Z","shell.execute_reply":"2023-06-14T10:24:17.660317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!yolo task=segment mode=train model=yolov8m-seg.pt data=hub-map.yaml epochs=120 imgsz=512 batch=16 lr0=0.01 name=yolo_hubmap exist_ok=True patience=10 device=0 pretrained=True cos_lr=True iou=0.7 scale=0.9 label_smoothing=0.5 mosaic=0.0 mixup=0.6 retina_masks=True hsv_h=0.0, hsv_s=0.0, hsv_v=0.0 copy_paste=0.1 translate=0.1","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls -la {HOME}/runs/segment/yolo_hubmap/","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:17.666312Z","iopub.status.idle":"2023-06-14T10:24:17.667112Z","shell.execute_reply.started":"2023-06-14T10:24:17.666856Z","shell.execute_reply":"2023-06-14T10:24:17.666894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cat {HOME}/runs/segment/yolo_hubmap/results.csv | head -10","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:17.668491Z","iopub.status.idle":"2023-06-14T10:24:17.669277Z","shell.execute_reply.started":"2023-06-14T10:24:17.669030Z","shell.execute_reply":"2023-06-14T10:24:17.669053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd {HOME}\n!yolo task=segment mode=val model={HOME}/runs/segment/yolo_hubmap/weights/best.pt data=hub-map.yaml iou=0.8 device=0","metadata":{"execution":{"iopub.status.busy":"2023-06-14T10:24:17.670654Z","iopub.status.idle":"2023-06-14T10:24:17.671439Z","shell.execute_reply.started":"2023-06-14T10:24:17.671189Z","shell.execute_reply":"2023-06-14T10:24:17.671213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}}]}