{"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-27T01:13:35.751795Z","iopub.execute_input":"2024-05-27T01:13:35.752152Z","iopub.status.idle":"2024-05-27T01:15:27.689862Z","shell.execute_reply.started":"2024-05-27T01:13:35.752124Z","shell.execute_reply":"2024-05-27T01:15:27.688674Z"},"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-27T01:15:27.692297Z","iopub.execute_input":"2024-05-27T01:15:27.693192Z","iopub.status.idle":"2024-05-27T01:15:28.141826Z","shell.execute_reply.started":"2024-05-27T01:15:27.693152Z","shell.execute_reply":"2024-05-27T01:15:28.141069Z"},"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-27T01:15:28.143035Z","iopub.execute_input":"2024-05-27T01:15:28.143584Z","iopub.status.idle":"2024-05-27T01:16:02.872025Z","shell.execute_reply.started":"2024-05-27T01:15:28.143545Z","shell.execute_reply":"2024-05-27T01:16:02.870892Z"},"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-27T01:16:02.874375Z","iopub.execute_input":"2024-05-27T01:16:02.874711Z","iopub.status.idle":"2024-05-27T01:16:04.905208Z","shell.execute_reply.started":"2024-05-27T01:16:02.874670Z","shell.execute_reply":"2024-05-27T01:16:04.904283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U openmim\nclear_output()","metadata":{"execution":{"iopub.status.busy":"2024-05-27T01:16:04.908076Z","iopub.execute_input":"2024-05-27T01:16:04.908528Z","iopub.status.idle":"2024-05-27T01:16:28.257997Z","shell.execute_reply.started":"2024-05-27T01:16:04.908501Z","shell.execute_reply":"2024-05-27T01:16:28.256855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p configs/Enigma","metadata":{"execution":{"iopub.status.busy":"2024-05-27T01:16:28.259660Z","iopub.execute_input":"2024-05-27T01:16:28.259966Z","iopub.status.idle":"2024-05-27T01:16:29.235721Z","shell.execute_reply.started":"2024-05-27T01:16:28.259934Z","shell.execute_reply":"2024-05-27T01:16:29.234331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile configs/Enigma/custom_config.py\n\n_base_ = '/kaggle/working/mmdetection/configs/cascade_rcnn/cascade-rcnn_r50_fpn_1x_coco.py'\nmodel = dict(\n    roi_head=dict(\n     bbox_head=[\n             dict(\n                type='Shared2FCBBoxHead',\n                in_channels=256,\n                fc_out_channels=1024,\n                roi_feat_size=7,\n                num_classes=13,\n                bbox_coder=dict(\n                    type='DeltaXYWHBBoxCoder',\n                    target_means=[0., 0., 0., 0.],\n                    target_stds=[0.1, 0.1, 0.2, 0.2]),\n                reg_class_agnostic=True,\n                loss_cls=dict(\n                    type='CrossEntropyLoss',\n                    use_sigmoid=False,\n                    loss_weight=1.0),\n                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,\n                               loss_weight=1.0)),\n         dict(\n                type='Shared2FCBBoxHead',\n                in_channels=256,\n                fc_out_channels=1024,\n                roi_feat_size=7,\n                num_classes=13,\n                bbox_coder=dict(\n                    type='DeltaXYWHBBoxCoder',\n                    target_means=[0., 0., 0., 0.],\n                    target_stds=[0.05, 0.05, 0.1, 0.1]),\n                reg_class_agnostic=True,\n                loss_cls=dict(\n                    type='CrossEntropyLoss',\n                    use_sigmoid=False,\n                    loss_weight=1.0),\n                loss_bbox=dict(type='SmoothL1Loss', beta=1.0,\n                               loss_weight=1.0)),\n          dict(\n                type='Shared2FCBBoxHead',\n                in_channels=256,\n                fc_out_channels=1024,\n                roi_feat_size=7,\n                num_classes=13,\n                bbox_coder=dict(\n                    type='DeltaXYWHBBoxCoder',\n                    target_means=[0., 0., 0., 0.],\n                    target_stds=[0.033, 0.033, 0.067, 0.067]),\n                reg_class_agnostic=True,\n                loss_cls=dict(\n                    type='CrossEntropyLoss',\n                    use_sigmoid=False,\n                    loss_weight=1.0),\n                loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0))\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=1000),\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=6,\n    num_workers=4,\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=6,\n    num_workers=4,\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='https://download.openmmlab.com/mmdetection/v2.0/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco/cascade_rcnn_r50_fpn_1x_coco_20200316-3dc56deb.pth'\ntest_evaluator = val_evaluator\nfp16=dict(loss_scale=512.)\nresume_from = None","metadata":{"execution":{"iopub.status.busy":"2024-05-27T01:36:50.521262Z","iopub.execute_input":"2024-05-27T01:36:50.521809Z","iopub.status.idle":"2024-05-27T01:36:50.531795Z","shell.execute_reply.started":"2024-05-27T01:36:50.521775Z","shell.execute_reply":"2024-05-27T01:36:50.530983Z"},"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-27T01:36:52.660350Z","iopub.execute_input":"2024-05-27T01:36:52.661008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}