{"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":"# Install Dependencies","metadata":{}},{"cell_type":"code","source":"import torch\nprint(f\"The preinstalled torch version is: {torch.__version__}\")\nversion_cuda = float(torch.version.cuda)\nprint(f\"The preinstalled CUDA version is: {torch.version.cuda}\")","metadata":{"execution":{"iopub.status.busy":"2021-06-20T09:55:08.957666Z","iopub.execute_input":"2021-06-20T09:55:08.957996Z","iopub.status.idle":"2021-06-20T09:55:08.963015Z","shell.execute_reply.started":"2021-06-20T09:55:08.957968Z","shell.execute_reply":"2021-06-20T09:55:08.962148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!conda install '/kaggle/input/pydicom-conda-helper/libjpeg-turbo-2.1.0-h7f98852_0.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/libgcc-ng-9.3.0-h2828fa1_19.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/gdcm-2.8.9-py37h500ead1_1.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/conda-4.10.1-py37h89c1867_0.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/certifi-2020.12.5-py37h89c1867_1.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/openssl-1.1.1k-h7f98852_0.tar.bz2' -c conda-forge -y","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:04:02.101372Z","iopub.execute_input":"2021-06-18T18:04:02.101707Z","iopub.status.idle":"2021-06-18T18:05:12.612433Z","shell.execute_reply.started":"2021-06-18T18:04:02.101676Z","shell.execute_reply":"2021-06-18T18:05:12.611472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if version_cuda >= 11.0:\n    # Install torch==1.8.0, torchvision==0.9.0 cuda==11.1\n    !pip install ../input/icevision08-kagcuda/torch-1.8.0cu111-cp37-cp37m-linux_x86_64.whl\n    !pip install ../input/icevision08-kagcuda/torchvision-0.9.0cu111-cp37-cp37m-linux_x86_64.whl\nelse:\n    # Install torch==1.8.0, torchvision==0.9.0 cuda==10.1\n    !pip install ../input/icevision08-kagcuda/torch-1.8.0cu101-cp37-cp37m-linux_x86_64.whl\n    !pip install ../input/icevision08-kagcuda/torchvision-0.9.0cu101-cp37-cp37m-linux_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-20T09:55:17.001883Z","iopub.execute_input":"2021-06-20T09:55:17.002218Z","iopub.status.idle":"2021-06-20T09:57:30.988932Z","shell.execute_reply.started":"2021-06-20T09:55:17.002166Z","shell.execute_reply":"2021-06-20T09:57:30.987979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Install fastai\n!pip install /kaggle/input/icevision08-kagcuda/fastai-2.3.1-py3-none-any.whl\n!pip install /kaggle/input/icevision08-kagcuda/fastcore-1.3.20-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-20T09:57:30.990707Z","iopub.execute_input":"2021-06-20T09:57:30.991039Z","iopub.status.idle":"2021-06-20T09:58:23.027864Z","shell.execute_reply.started":"2021-06-20T09:57:30.991Z","shell.execute_reply":"2021-06-20T09:58:23.026908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## STOP: Restart Kernel","metadata":{}},{"cell_type":"code","source":"import torch\nprint(f\"The preinstalled torch version is: {torch.__version__}\")\nprint(f\"The preinstalled CUDA version is: {torch.version.cuda}\")","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:08:19.194455Z","iopub.execute_input":"2021-06-18T18:08:19.194802Z","iopub.status.idle":"2021-06-18T18:08:19.202847Z","shell.execute_reply.started":"2021-06-18T18:08:19.194763Z","shell.execute_reply":"2021-06-18T18:08:19.19964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install /kaggle/input/icevision08-kagcuda/torchtext-0.9.0-cp37-cp37m-linux_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:08:19.2044Z","iopub.execute_input":"2021-06-18T18:08:19.20484Z","iopub.status.idle":"2021-06-18T18:08:47.113087Z","shell.execute_reply.started":"2021-06-18T18:08:19.204801Z","shell.execute_reply":"2021-06-18T18:08:47.110194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Modify .xyz files to .tar.gz","metadata":{}},{"cell_type":"code","source":"import os\n\npath_dep_src = '/kaggle/input/icevision08-kagcuda/'\npath_dep_targ = '/kaggle/working/icevision_dependencies/'\n\n%mkdir $path_dep_targ","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:08:47.114678Z","iopub.execute_input":"2021-06-18T18:08:47.115067Z","iopub.status.idle":"2021-06-18T18:08:47.777572Z","shell.execute_reply.started":"2021-06-18T18:08:47.115021Z","shell.execute_reply":"2021-06-18T18:08:47.776572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Copy xyz files to output directory\nfor root, dirs, files in os.walk(path_dep_src):\n    for file in files:\n        path_dep_src_file = ''\n        root, ext = os.path.splitext(file)\n        if str(ext) == '.xyz':\n            path_dep_src_file = path_dep_src + file\n#             print(path_dep_src_file)\n            %cp $path_dep_src_file $path_dep_targ\n            \n# Modify xyz --> tar.gz in output directory\nfor root, dirs, files in os.walk(path_dep_targ):\n    for file in files:\n        path_dep_targ_file = ''\n        root, ext = os.path.splitext(file)\n        if str(ext) == '.xyz':\n            src_file_mod = path_dep_targ + file\n            targ_file_mod = path_dep_targ + root + '.tar.gz'\n            print(targ_file_mod)\n            %mv $src_file_mod $targ_file_mod","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:08:47.780823Z","iopub.execute_input":"2021-06-18T18:08:47.781085Z","iopub.status.idle":"2021-06-18T18:08:54.572309Z","shell.execute_reply.started":"2021-06-18T18:08:47.781056Z","shell.execute_reply":"2021-06-18T18:08:54.571411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Instll Icevision Pre-reqs\n!pip install ./icevision_dependencies/pycocotools-2.0.2.tar.gz\n!pip install ../input/icevision08-kagcuda/loguru-0.5.3-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/Pillow-8.2.0-cp37-cp37m-manylinux1_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:08:54.576513Z","iopub.execute_input":"2021-06-18T18:08:54.576829Z","iopub.status.idle":"2021-06-18T18:10:20.283616Z","shell.execute_reply.started":"2021-06-18T18:08:54.576798Z","shell.execute_reply":"2021-06-18T18:10:20.282592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install /kaggle/input/icevision08-kagcuda/icevision-0.8.0-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:10:20.285469Z","iopub.execute_input":"2021-06-18T18:10:20.28583Z","iopub.status.idle":"2021-06-18T18:10:46.662868Z","shell.execute_reply.started":"2021-06-18T18:10:20.285789Z","shell.execute_reply":"2021-06-18T18:10:46.661879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Install IcevisionData Pre-reqs\n!pip install ../input/icevision08-kagcuda/iopath-0.1.8-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/pyDeprecate-0.3.0-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/timm-0.4.9-py3-none-any.whl\n!pip install ./icevision_dependencies/fvcore-0.1.5.post20210604.tar.gz\n!pip install ./icevision_dependencies/fire-0.4.0.tar.gz\n\n!pip install ../input/icevision08-kagcuda/resnest-0.0.6b20210605-py3-none-any.whl\n!pip install ./icevision_dependencies/antlr4-python3-runtime-4.8.tar.gz\n!pip install ../input/icevision08-kagcuda/fsspec-2021.5.0-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/omegaconf-2.1.0-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/pytorch_lightning-1.3.5-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/effdet-0.2.4-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/timm-0.4.9-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:10:46.664636Z","iopub.execute_input":"2021-06-18T18:10:46.665022Z","iopub.status.idle":"2021-06-18T18:16:08.626124Z","shell.execute_reply.started":"2021-06-18T18:10:46.66498Z","shell.execute_reply":"2021-06-18T18:16:08.625129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install /kaggle/\n!pip install /kaggle/input/icevision08-kagcuda/icedata-0.4.0-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:16:08.627927Z","iopub.execute_input":"2021-06-18T18:16:08.628305Z","iopub.status.idle":"2021-06-18T18:16:35.769142Z","shell.execute_reply.started":"2021-06-18T18:16:08.628263Z","shell.execute_reply":"2021-06-18T18:16:35.768162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Install MMDet Pre-reqs\n!pip install ../input/icevision08-kagcuda/pytest_runner-5.3.1-py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/yapf-0.31.0-py2.py3-none-any.whl\n!pip install ../input/icevision08-kagcuda/addict-2.4.0-py3-none-any.whl\n\n# Restart Kernel\nimport IPython\nIPython.Application.instance().kernel.do_shutdown(True) #automatically restarts kernel","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:16:35.770596Z","iopub.execute_input":"2021-06-18T18:16:35.770964Z","iopub.status.idle":"2021-06-18T18:17:54.885376Z","shell.execute_reply.started":"2021-06-18T18:16:35.770925Z","shell.execute_reply":"2021-06-18T18:17:54.884533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nversion_cuda = torch.version.cuda\nif version_cuda >= '11.0':\n#     !pip install mmcv-full==\"1.3.3\" -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html --upgrade  \n#     !pip install mmcv-full==\"1.3.3\" -f ../input/icevision08-kagcuda/mmcv_torch180-cu111_full-1.3.3-cp37-cp37m-manylinux1_x86_64.whl --upgrade    \n#     !pip install ./icevision_dependencies/mmcv-1.3.3.tar.gz\n    !pip install ../input/icevision08-kagcuda/mmc-cu111/mmc-cu111/mmcv_full-1.3.3-cp37-cp37m-manylinux1_x86_64.whl\n    \nelse:\n    !pip install ../input/icevision08-kagcuda/mmcv_torch180-cu101_full-1.3.3-cp37-cp37m-manylinux1_x86_64.whl\n","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:21:49.931257Z","iopub.execute_input":"2021-06-18T18:21:49.931714Z","iopub.status.idle":"2021-06-18T18:22:18.434851Z","shell.execute_reply.started":"2021-06-18T18:21:49.931592Z","shell.execute_reply":"2021-06-18T18:22:18.43386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n!pip install /kaggle/input/icevision08-kagcuda/mmdet-2.13.0-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:22:22.558747Z","iopub.execute_input":"2021-06-18T18:22:22.559193Z","iopub.status.idle":"2021-06-18T18:22:49.427408Z","shell.execute_reply.started":"2021-06-18T18:22:22.559102Z","shell.execute_reply":"2021-06-18T18:22:49.426417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Install Yolo5\n!pip install ../input/icevision08-kagcuda/yolov5_icevision-4.0.0-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:22:49.429203Z","iopub.execute_input":"2021-06-18T18:22:49.429585Z","iopub.status.idle":"2021-06-18T18:23:16.054162Z","shell.execute_reply.started":"2021-06-18T18:22:49.42954Z","shell.execute_reply":"2021-06-18T18:23:16.053095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Restart Kernel    \nimport IPython\nIPython.Application.instance().kernel.do_shutdown(True) #automatically restarts kernel\n    ","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:23:16.056155Z","iopub.execute_input":"2021-06-18T18:23:16.056534Z","iopub.status.idle":"2021-06-18T18:23:16.06978Z","shell.execute_reply.started":"2021-06-18T18:23:16.056495Z","shell.execute_reply":"2021-06-18T18:23:16.068905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Copy additional dependencies and models to destination folder\n%mkdir -p /root/.icevision/fonts\n%cp /kaggle/input/icevision08-kagcuda/SpaceGrotesk-Medium.ttf /root/.icevision/fonts/\n%mkdir -p /root/.icevision/yolo\n%cp /kaggle/input/icevision08-kagcuda/yolov5s.pt /root/.icevision/yolo/\n%mkdir -p /root/.cache/torch/hub/checkpoints\n%cp /kaggle/input/icevision08-kagcuda/tf_efficientdet_d0_34-f153e0cf.pth /root/.cache/torch/hub/checkpoints/\n","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:23:45.05706Z","iopub.execute_input":"2021-06-18T18:23:45.057496Z","iopub.status.idle":"2021-06-18T18:23:50.046274Z","shell.execute_reply.started":"2021-06-18T18:23:45.057402Z","shell.execute_reply":"2021-06-18T18:23:50.045129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #Copy MMDetConfigs\n%rm -r /root/.icevision/mmdetection_configs\n%cp /kaggle/input/icevision08-kagcuda/mmdetection_configs-2.10.0/mmdetection_configs-2.10.0 /root/.icevision/mmdetection_configs -R","metadata":{"execution":{"iopub.status.busy":"2021-06-18T19:10:34.646252Z","iopub.execute_input":"2021-06-18T19:10:34.646626Z","iopub.status.idle":"2021-06-18T19:10:36.525648Z","shell.execute_reply.started":"2021-06-18T19:10:34.646578Z","shell.execute_reply":"2021-06-18T19:10:36.524512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Setup","metadata":{}},{"cell_type":"code","source":"# ALERT: Still can't keep icevision from trying to download mmdet configs, need to figure this out.  \n# Can turn on internet for this cell to work around\n\nfrom icevision.all import *\n\n# Trying to load other models besides mmdet doesn't work\n# from icevision.data import *\n# from icevision.metrics import *\n# from icevision.models import yolo5\n# from icevision.backbones import yolo5\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-18T19:11:06.712667Z","iopub.execute_input":"2021-06-18T19:11:06.713053Z","iopub.status.idle":"2021-06-18T19:11:26.811895Z","shell.execute_reply.started":"2021-06-18T19:11:06.713022Z","shell.execute_reply":"2021-06-18T19:11:26.807872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom datetime import *\nimport pytz\nfrom icevision.widgets import *","metadata":{"execution":{"iopub.status.busy":"2021-06-18T17:58:52.214075Z","iopub.execute_input":"2021-06-18T17:58:52.214437Z","iopub.status.idle":"2021-06-18T17:58:52.220657Z","shell.execute_reply.started":"2021-06-18T17:58:52.214402Z","shell.execute_reply":"2021-06-18T17:58:52.219399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"params = dict(\n    size=256,\n    size_trans=256,\n    batch_size=8,\n    ds_size=500\n    )\n\npath = Path('./')\nextra_args = {}\n\n# Kaggle\npath_dicom = Path('../input/siimcovid19coco256px')\n\npath_output_patches = path_dicom / ('DS-COCO_' + str(params['size']))\n\nclasslabels = ['Negative', 'Typical', 'Indeterminate', 'Atypical']","metadata":{"execution":{"iopub.status.busy":"2021-06-18T17:58:53.058019Z","iopub.execute_input":"2021-06-18T17:58:53.058354Z","iopub.status.idle":"2021-06-18T17:58:53.063554Z","shell.execute_reply.started":"2021-06-18T17:58:53.058323Z","shell.execute_reply":"2021-06-18T17:58:53.062572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load Data","metadata":{}},{"cell_type":"code","source":"# Parser\nparser = parsers.COCOBBoxParser(annotations_filepath=str(path_output_patches) + '/coco_train_annotations_' + str(params['size']) + 'px.json', img_dir=path_output_patches / 'train')","metadata":{"execution":{"iopub.status.busy":"2021-06-18T17:58:53.738105Z","iopub.execute_input":"2021-06-18T17:58:53.738458Z","iopub.status.idle":"2021-06-18T17:58:54.02729Z","shell.execute_reply.started":"2021-06-18T17:58:53.738428Z","shell.execute_reply":"2021-06-18T17:58:54.02644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Parsing\ntrain_rs, valid_rs = parser.parse()","metadata":{"execution":{"iopub.status.busy":"2021-06-18T17:58:55.035641Z","iopub.execute_input":"2021-06-18T17:58:55.035973Z","iopub.status.idle":"2021-06-18T17:59:38.755522Z","shell.execute_reply.started":"2021-06-18T17:58:55.035941Z","shell.execute_reply":"2021-06-18T17:59:38.754516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_map = ClassMap(classlabels)\nprint(len(class_map))\nclass_map","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:06.955463Z","iopub.execute_input":"2021-06-18T18:00:06.955844Z","iopub.status.idle":"2021-06-18T18:00:06.964215Z","shell.execute_reply.started":"2021-06-18T18:00:06.955808Z","shell.execute_reply":"2021-06-18T18:00:06.963186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_records(train_rs[:6], ncols=3, class_map=class_map)","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:07.948024Z","iopub.execute_input":"2021-06-18T18:00:07.948364Z","iopub.status.idle":"2021-06-18T18:00:09.15162Z","shell.execute_reply.started":"2021-06-18T18:00:07.948332Z","shell.execute_reply":"2021-06-18T18:00:09.150616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Transforms\ntrain_tfms = tfms.A.Adapter([*tfms.A.aug_tfms(size=params['size'], presize=params['size_trans']), tfms.A.Normalize()])\nvalid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(params['size']), tfms.A.Normalize()])","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:19.502138Z","iopub.execute_input":"2021-06-18T18:00:19.502504Z","iopub.status.idle":"2021-06-18T18:00:19.509172Z","shell.execute_reply.started":"2021-06-18T18:00:19.502471Z","shell.execute_reply":"2021-06-18T18:00:19.506632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Datasets\ntrain_ds = Dataset(train_rs, train_tfms)\nvalid_ds = Dataset(valid_rs, valid_tfms)","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:20.524735Z","iopub.execute_input":"2021-06-18T18:00:20.525067Z","iopub.status.idle":"2021-06-18T18:00:20.529683Z","shell.execute_reply.started":"2021-06-18T18:00:20.525036Z","shell.execute_reply":"2021-06-18T18:00:20.528502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Currently only yolov5 works in offline mode \n# TODO - Add rest of models to offline dataset\n\nselection = 3\n\nextra_args = {}\n\nif selection == 0:\n  model_type = models.mmdet.retinanet\n  backbone = model_type.backbones.resnet50_fpn_1x\n\nelif selection == 1:\n  # The Retinanet model is also implemented in the torchvision library\n  model_type = models.torchvision.retinanet\n  backbone = model_type.backbones.resnet50_fpn\n\nelif selection == 2:\n  model_type = models.ross.efficientdet\n#   backbone = model_type.backbones.tf_lite0\n  backbone = model_type.backbones.tf_d0\n  # The efficientdet model requires an img_size parameter\n  extra_args['img_size'] = params['size']\n\nelif selection == 3:\n  model_type = models.ultralytics.yolov5\n  backbone = model_type.backbones.small\n  # The yolov5 model requires an img_size parameter\n  extra_args['img_size'] = params['size']\n\nmodel_type, backbone, extra_args","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:21.493784Z","iopub.execute_input":"2021-06-18T18:00:21.494117Z","iopub.status.idle":"2021-06-18T18:00:21.503325Z","shell.execute_reply.started":"2021-06-18T18:00:21.494085Z","shell.execute_reply":"2021-06-18T18:00:21.502415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Instantiate the mdoel\nmodel = model_type.model(backbone=backbone(pretrained=True), num_classes=len(class_map), **extra_args) ","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:24.506443Z","iopub.execute_input":"2021-06-18T18:00:24.506777Z","iopub.status.idle":"2021-06-18T18:00:28.10158Z","shell.execute_reply.started":"2021-06-18T18:00:24.506746Z","shell.execute_reply":"2021-06-18T18:00:28.100702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# DataLoaders\ntrain_dl = model_type.train_dl(train_ds, batch_size=params['batch_size'], num_workers=0, shuffle=True)\nvalid_dl = model_type.valid_dl(valid_ds, batch_size=params['batch_size'], num_workers=0, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:29.02406Z","iopub.execute_input":"2021-06-18T18:00:29.024423Z","iopub.status.idle":"2021-06-18T18:00:29.029663Z","shell.execute_reply.started":"2021-06-18T18:00:29.024391Z","shell.execute_reply":"2021-06-18T18:00:29.028341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"params['run_datetime'] = datetime.now(pytz.timezone('US/Pacific')).strftime(\"%m%d%Y-%H%M\")\n\n\nmodel_save_name = 'ModelName' + '_'  \nmodel_save_name += str(len(parser.class_map)) + 'cls_' \nmodel_save_name += str((params['size'])) + 'px_'\nmodel_save_name += str(len(train_ds)) + 'ds_'\nmodel_save_name += params['run_datetime']\nprint(model_save_name)","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:29.812084Z","iopub.execute_input":"2021-06-18T18:00:29.812438Z","iopub.status.idle":"2021-06-18T18:00:29.842775Z","shell.execute_reply.started":"2021-06-18T18:00:29.812405Z","shell.execute_reply":"2021-06-18T18:00:29.841969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics = [COCOMetric(metric_type=COCOMetricType.bbox)]","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:31.142032Z","iopub.execute_input":"2021-06-18T18:00:31.142397Z","iopub.status.idle":"2021-06-18T18:00:31.146803Z","shell.execute_reply.started":"2021-06-18T18:00:31.142362Z","shell.execute_reply":"2021-06-18T18:00:31.14584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = model_type.fastai.learner(dls=[train_dl, valid_dl], model=model, metrics=metrics)","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:31.672858Z","iopub.execute_input":"2021-06-18T18:00:31.673181Z","iopub.status.idle":"2021-06-18T18:00:31.680892Z","shell.execute_reply.started":"2021-06-18T18:00:31.673152Z","shell.execute_reply":"2021-06-18T18:00:31.680098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# learn.freeze()\nlearn.lr_find()","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:32.413856Z","iopub.execute_input":"2021-06-18T18:00:32.41419Z","iopub.status.idle":"2021-06-18T18:00:45.824887Z","shell.execute_reply.started":"2021-06-18T18:00:32.41416Z","shell.execute_reply":"2021-06-18T18:00:45.824075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"params.update(lr1 = 1e-3)\nparams.update (epochs1 = 1)\n\nlearn.fit(params['epochs1'], params['lr1'])","metadata":{"execution":{"iopub.status.busy":"2021-06-18T18:00:45.8279Z","iopub.execute_input":"2021-06-18T18:00:45.828177Z","iopub.status.idle":"2021-06-18T18:01:48.660048Z","shell.execute_reply.started":"2021-06-18T18:00:45.828148Z","shell.execute_reply":"2021-06-18T18:01:48.659221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"params.update(current_saved_model='stage-1-' + model_save_name)\nparams['current_saved_model']\nlearn.save(path/ params['current_saved_model'])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}