{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":67836,"databundleVersionId":7527339,"sourceType":"competition"},{"sourceId":6063037,"sourceType":"datasetVersion","datasetId":3469773},{"sourceId":6063590,"sourceType":"datasetVersion","datasetId":3470137},{"sourceId":8521750,"sourceType":"datasetVersion","datasetId":5088299}],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from IPython.display import clear_output\n\n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/pycocotools-2.0.6-cp310-cp310-linux_x86_64.whl\n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/torch-1.12.1+cu116-cp310-cp310-linux_x86_64.whl\n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/torchvision-0.13.1+cu116-cp310-cp310-linux_x86_64.whl\n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/mmcv-2.0.1-cp310-cp310-manylinux1_x86_64.whl \n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/openmim-0.3.9-py2.py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/mmengine-0.7.4-py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmdetectron-31-wheel/addict-2.4.0-py3-none-any.whl\n!pip install yapf==0.40.1\n!pip install --no-index --no-deps /kaggle/input/mmpretrain/einops-0.6.1-py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmpretrain/mat4py-0.5.0-py2.py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmpretrain/ordered_set-4.1.0-py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmpretrain/model_index-0.1.11-py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmpretrain/modelindex-0.0.2-py3-none-any.whl\n!pip install --no-index --no-deps /kaggle/input/mmpretrain/mmpretrain-1.0.0rc8-py2.py3-none-any.whl\nclear_output()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-26T12:30:17.082021Z","iopub.execute_input":"2024-05-26T12:30:17.082383Z","iopub.status.idle":"2024-05-26T12:32:17.147226Z","shell.execute_reply.started":"2024-05-26T12:30:17.082355Z","shell.execute_reply":"2024-05-26T12:32:17.145917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.notebook import tqdm\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\nfrom PIL import Image\n\nfrom glob import glob\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-05-26T12:32:17.149644Z","iopub.execute_input":"2024-05-26T12:32:17.150033Z","iopub.status.idle":"2024-05-26T12:32:17.601159Z","shell.execute_reply.started":"2024-05-26T12:32:17.149991Z","shell.execute_reply":"2024-05-26T12:32:17.600437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!git clone -bv3.1.0 https://github.com/open-mmlab/mmdetection.git\n%cd /kaggle/working/mmdetection\n!pip install -v -e .\n\nclear_output()","metadata":{"execution":{"iopub.status.busy":"2024-05-26T12:32:17.602480Z","iopub.execute_input":"2024-05-26T12:32:17.602874Z","iopub.status.idle":"2024-05-26T12:32:43.380040Z","shell.execute_reply.started":"2024-05-26T12:32:17.602848Z","shell.execute_reply":"2024-05-26T12:32:43.378970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch, torchvision,mmdet\nprint(\"PyTorch version= \",torch.__version__,torch.cuda.is_available())\nprint(\"mmdet version= \",mmdet.__version__)\n\nfrom mmcv.ops import get_compiling_cuda_version\nprint(\"THE CUDA version \", get_compiling_cuda_version())","metadata":{"execution":{"iopub.status.busy":"2024-05-26T12:32:43.382110Z","iopub.execute_input":"2024-05-26T12:32:43.382436Z","iopub.status.idle":"2024-05-26T12:32:45.510295Z","shell.execute_reply.started":"2024-05-26T12:32:43.382406Z","shell.execute_reply":"2024-05-26T12:32:45.509384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U openmim\nclear_output()","metadata":{"execution":{"iopub.status.busy":"2024-05-26T13:04:32.509323Z","iopub.execute_input":"2024-05-26T13:04:32.509764Z","iopub.status.idle":"2024-05-26T13:04:35.065192Z","shell.execute_reply.started":"2024-05-26T13:04:32.509723Z","shell.execute_reply":"2024-05-26T13:04:35.064114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p configs/Enigma","metadata":{"execution":{"iopub.status.busy":"2024-05-26T13:04:48.915449Z","iopub.execute_input":"2024-05-26T13:04:48.916271Z","iopub.status.idle":"2024-05-26T13:04:49.870713Z","shell.execute_reply.started":"2024-05-26T13:04:48.916234Z","shell.execute_reply":"2024-05-26T13:04:49.869339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile configs/Enigma/custom_config.py\n\n_base_ = '/kaggle/working/mmdetection/configs/faster_rcnn/faster-rcnn_r50_fpn_amp-1x_coco.py'\nmodel = dict(\n    roi_head=dict(\n        bbox_head=dict(\n            num_classes=13\n        )\n    ),\n    test_cfg=dict(\n        rcnn=dict(\n            score_thr=0.05,\n            nms=dict(type='soft_nms', iou_threshold=0.5, min_score=0.05),\n            max_per_img=100))\n)\n\nclasses = ('auto_rickshaw',\n'bicycle',\n'bus',\n'car',\n'cart_vehicle',\n'construction_vehicle',\n'motorbike',\n'person',\n'priority_vehicle',\n'three_wheeler',\n'train',\n'truck',\n'wheelchair') # Added\nbackend_args = None\ndata_root = '/kaggle/input/dl-enigma-cocodataset/' # Modified\ntrain_cfg = dict(type='EpochBasedTrainLoop', max_epochs=12, val_interval=1)\nval_cfg = dict(type='ValLoop')\ntest_cfg = dict(type='TestLoop')\n\n\nparam_scheduler = [\n    dict(type='LinearLR', start_factor=0.001, by_epoch=False, begin=0, end=900),\n    dict(\n        type='MultiStepLR',\n        begin=0,\n        end=12,\n        by_epoch=True,\n        milestones=[8, 11],\n        gamma=0.1)\n]\n\n\ntrain_pipeline = [\n    dict(type='LoadImageFromFile', backend_args=backend_args),\n    dict(type='LoadAnnotations', with_bbox=True),\n    dict(\n        type='Resize',  # Pipeline that resizes the images and their annotations\n        scale=(1333, 800),  # The largest scale of the images\n        keep_ratio=True  # Whether to keep the ratio between height and width\n        ),\n    dict(type='RandomFlip', prob=0.5),\n    dict(type='PackDetInputs')\n]\ntest_pipeline = [\n    dict(type='LoadImageFromFile', backend_args=backend_args),\n    dict(type='LoadAnnotations', with_bbox=True),\n    dict(\n        type='Resize',  # Pipeline that resizes the images and their annotations\n        scale=(1333, 800),  # The largest scale of the images\n        keep_ratio=True  # Whether to keep the ratio between height and width\n        ),\n    dict(\n        type='PackDetInputs',\n        meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',\n                   'scale_factor'))\n]\n\ntrain_dataloader = dict(\n    batch_size=8,\n    num_workers=2,\n    persistent_workers=True,\n    dataset=dict(\n        type='CocoDataset',\n        data_root=data_root,\n        metainfo=dict(classes=classes),\n        ann_file=data_root + 'annotations_train.json',\n        data_prefix=dict(img='train2017/'),\n        pipeline=train_pipeline,\n        backend_args=backend_args))\nval_dataloader = dict(\n    batch_size=8,\n    num_workers=2,\n    persistent_workers=True,\n    drop_last=False,\n    dataset=dict(\n        type='CocoDataset',\n        data_root=data_root,\n        metainfo=dict(classes=classes),\n        ann_file=data_root + 'annotations_valid.json',\n        data_prefix=dict(img='valid2017/'),\n        test_mode=True,\n        pipeline=test_pipeline,\n        backend_args=backend_args))\ntest_dataloader = val_dataloader\n\ntest_cfg=dict(\n        rpn=dict(\n            nms_pre=1000,\n            max_per_img=1000,\n            nms=dict(type='nms', iou_threshold=0.7),\n            min_bbox_size=0),\n        rcnn=dict(\n            score_thr=0.05,\n            nms=dict(type='soft_nms', iou_threshold=0.5),\n            max_per_img=100)\n        # soft-nms is also supported for rcnn testing\n        # e.g., nms=dict(type='soft_nms', iou_threshold=0.5, min_score=0.05)\n    )\n\nval_evaluator = dict(\nann_file=data_root + 'annotations_valid.json', metric=['bbox'])\nload_from='http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'\ntest_evaluator = val_evaluator\nfp16=dict(loss_scale=512.)\nresume_from = None","metadata":{"execution":{"iopub.status.busy":"2024-05-26T13:53:45.216916Z","iopub.execute_input":"2024-05-26T13:53:45.217742Z","iopub.status.idle":"2024-05-26T13:53:45.228153Z","shell.execute_reply.started":"2024-05-26T13:53:45.217701Z","shell.execute_reply":"2024-05-26T13:53:45.227116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python tools/train.py /kaggle/working/mmdetection/configs/Enigma/custom_config.py","metadata":{"execution":{"iopub.status.busy":"2024-05-26T13:53:47.265483Z","iopub.execute_input":"2024-05-26T13:53:47.266154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}