{"cells":[{"metadata":{},"cell_type":"markdown","source":"# MMDetection pipeline","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"Due to the rapid development of mmdetection, official documentation and tutorials do not always have time to be updated. When you try to use mmdetection, you may encounter difficulties, which are most likely related to problems caused by incorrect library versions or their incorrect installation. \n\nI would like to Express my gratitude to the authors of this software. I hope that this pipeline will help you get started using this software faster and appreciate its full potential.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"https://github.com/open-mmlab/mmdetection","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport os\nimport torch\nimport random\nimport sys\n\nfrom IPython.display import clear_output","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"code","source":"!nvidia-smi","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"https://github.com/NVIDIA/apex","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"!git clone https://github.com/NVIDIA/apex && cd apex && pip install -v --no-cache-dir --global-option=\"--cpp_ext\" --global-option=\"--cuda_ext\" . --user && cd .. && rm -rf apex\nclear_output(wait=True)\nprint('Done!')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Check out your own CUDA version, version below is Google Colab's version.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# install dependencies: (use cu101 because colab has CUDA 10.1)\n!pip install -U torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html\n\n# install mmcv-full thus we could use CUDA operators\n!pip install mmcv-full\n\nclear_output(wait=True)\nprint('Done!')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"You can state below link to your copy of this MMDetection repo. Add .git in the end.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# Install mmdetection\n!rm -rf mmdetection\n!git clone https://github.com/open-mmlab/mmdetection.git  # !git clone https://github.com/t0efL/mmdetection.git\n%cd mmdetection\n\nclear_output(wait=True)\nprint('Done!')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install -e .\n\n# install Pillow 7.0.0 back in order to avoid bug in colab\n!pip install Pillow==7.0.0\n\nclear_output(wait=True)\nprint('Done!')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Fixing a new version  bug.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install \"git+https://github.com/open-mmlab/cocoapi.git#subdirectory=pycocotools\"\nclear_output(wait=True)\nprint('Done!')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Make a simple restart of runtime at this point.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check Pytorch installation\nimport torch, torchvision\nprint(torch.__version__, torch.cuda.is_available())\n\n# Check MMDetection installation\nimport mmdet\nprint(mmdet.__version__)\n\n# Check mmcv installation\nfrom mmcv.ops import get_compiling_cuda_version, get_compiler_version\nprint(get_compiling_cuda_version())\nprint(get_compiler_version())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def set_seed(seed=27):\n    \"\"\"Sets the random seeds.\"\"\"\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n    os.environ['PYTHONHASHSEED'] = str(seed)\n \nset_seed()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"State below the path to your config.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"!python /content/mmdetection/tools/train.py /content/mmdetection/configs/faster_rcnn_r101_fpn_1x.py","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}