### Update get_started Guide Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog Updates the 'Get Started' guide, providing the latest instructions for setting up and beginning to use MMDetection. ```Markdown # Getting Started with MMDetection ## Installation 1. **Clone the repository:** ```bash git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection ``` 2. **Install MMDetection:** ```bash pip install -v . # install editable mode ``` ``` -------------------------------- ### Install TrackEval Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs the TrackEval library, which is used for evaluating tracking performance. This is a necessary step after installing MMDetection for tracking tasks. ```bash pip install trackeval ``` -------------------------------- ### Install MMDetection with MIM Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs MMDetection as a package using the MIM package manager. This is recommended when using MMDetection as a dependency. ```bash mim install mmdet ``` -------------------------------- ### Install PyTorch (CPU) Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs PyTorch on CPU platforms following official instructions. This is suitable for systems without a compatible GPU. ```bash pip3 install torch torchvision torchaudio ``` -------------------------------- ### Install MMDetection from Source Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs MMDetection directly from its source code, allowing for development and local modifications. The '-v' flag enables verbose output, and '-e' installs in editable mode. ```bash cd mmdetection pip install -v -e . ``` -------------------------------- ### Install MMDetection for Tracking (MIM) Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs MMDetection with tracking capabilities enabled using the MIM package manager. This command installs the base MMDetection package along with the tracking extra. ```bash mim install mmdet[tracking] ``` -------------------------------- ### Install MMDetection for Specific Features Source: https://mmdetection.readthedocs.io/en/latest/notes/faq Shows example commands for installing MMDetection with extra dependencies required for specific algorithms or datasets, such as Instaboost, Panoptic Segmentation, and LVIS dataset. ```Shell # for instaboost pip install mmcv-full ``` ```Shell # for panoptic segmentation pip install mmcv-full ``` ```Shell # for LVIS dataset pip install mmcv-full ``` ```Shell pip install mmcv-full ``` -------------------------------- ### Download Config and Checkpoint Source: https://mmdetection.readthedocs.io/en/latest/get_started Downloads necessary configuration and checkpoint files for running inference demos. These files are essential for initializing the detection model. ```bash mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest . ``` -------------------------------- ### Install MMCV with MIM Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs the MMCV library, a foundational component for MMDetection, using the MIM package manager. It specifies a minimum version of MMCV. ```bash mim install "mmcv>=2.0.0" ``` -------------------------------- ### Verify MMDetection installation with Python Source: https://mmdetection.readthedocs.io/en/latest/get_started This snippet verifies the MMDetection installation by importing the mmdet module and printing its version. It confirms that the library is correctly installed and accessible in the Python environment. ```Python import mmdet print(mmdet.__version__) # Example output: 3.0.0, or an another version. ``` -------------------------------- ### Verify Inference Demo (from Source) Source: https://mmdetection.readthedocs.io/en/latest/get_started Runs an inference demo using MMDetection installed from source. This command executes a Python script to perform detection on a sample image. ```bash python demo/image_demo.py --config /path/to/rtmdet_tiny_8xb32-300e_coco.py --checkpoint /path/to/rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth --img demo/demo.jpg --out-file outputs/vis/demo.jpg ``` -------------------------------- ### Install MMEngine with pip Source: https://mmdetection.readthedocs.io/en/latest/get_started This command demonstrates how to install MMEngine using pip instead of MIM. This approach requires manually specifying the find-url based on the PyTorch version and its CUDA version. ```Shell "mmcv>=2.0.0" ``` -------------------------------- ### Install PyTorch (GPU) Source: https://mmdetection.readthedocs.io/en/latest/get_started Installs PyTorch on GPU platforms following official instructions. Ensure your CUDA version is compatible with the PyTorch version you choose. ```bash pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### Install MMEngine and MMCV on Google Colab Source: https://mmdetection.readthedocs.io/en/latest/get_started These commands install MMEngine and MMCV on Google Colab using MIM. This is a necessary step before installing MMDetection from source on Google Colab. ```Shell "mmcv>=2.0.0,<2.1.0" ``` -------------------------------- ### Verify Inference Demo (Python Interpreter) Source: https://mmdetection.readthedocs.io/en/latest/get_started Verifies the MMDetection installation by running inference within a Python interpreter. It initializes a detector and performs inference on a sample image. ```python from mmdet.apis import init_detector, inference_detector config_file = 'rtmdet_tiny_8xb32-300e_coco.py' checkpoint_file = 'rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth' model = init_detector(config_file, checkpoint_file, device='cpu') # or device='cuda:0' inference_detector(model, 'demo/demo.jpg') ``` -------------------------------- ### Update user guide: `finetune.md` and `inference.md` Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog This updates the user guide documentation, specifically the files related to finetuning models (`finetune.md`) and performing inference (`inference.md`). These updates likely include new examples or clarifications. ```Markdown pass # Represents updates to finetune.md and inference.md ``` -------------------------------- ### Run MMDetection with Docker Source: https://mmdetection.readthedocs.io/en/latest/get_started This command runs the MMDetection Docker image, mounting the data directory to enable access to datasets. Adjust the DATA_DIR variable to point to the correct data location. ```Shell =8g{DATA_DIR}:/mmdetection/data ``` -------------------------------- ### Install MMDetection Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio Installs the MMDetection toolbox, a comprehensive object detection framework. This command navigates to the directory and installs the package. ```shell cd ``` -------------------------------- ### Create Conda Environment Source: https://mmdetection.readthedocs.io/en/latest/get_started This command creates a new conda environment with a specified Python version. It's a prerequisite for installing MMDetection and its dependencies. ```bash conda create -n openmmlab python=3.8 -y ``` -------------------------------- ### Install MMDetection from source on Google Colab Source: https://mmdetection.readthedocs.io/en/latest/get_started This command installs MMDetection from source after MMEngine and MMCV have been installed. This step is required to use the latest version of MMDetection on Google Colab. ```Shell ``` -------------------------------- ### Install Cython for Miniconda Environment Source: https://mmdetection.readthedocs.io/en/latest/notes/faq Installs Cython manually, which is sometimes required when using miniconda to resolve setuptools.sandbox.UnpickleableException errors during package installation. ```Shell pip install -r requirements.txt ``` -------------------------------- ### Start MMYOLO Backend Inference Service Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio This snippet shows how to start the backend inference service using MMYOLO. It includes setting configuration files, checkpoint files, and specifying the device for inference (CPU or GPU). ```Shell cd\ config_file=\ checkpoint_file=\ device=cpu\ --port8003 # device=cpu is for using CPU inference. If using GPU inference, replace cpu with cuda:0. ``` -------------------------------- ### Setup Environment Source: https://mmdetection.readthedocs.io/en/latest/_modules/index Initializes and configures the environment for running MMDetection. This may involve setting up distributed training, configuring logging, or other necessary preparations. ```Python from mmdet.utils import setup_env ``` -------------------------------- ### Download Example Cat Images Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio Downloads example cat images for annotation. This command is used to prepare the dataset for the semi-automatic annotation process in Label-Studio. ```shell cd&&cd&& ``` -------------------------------- ### Install Label-Studio and ML Backend Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio Installs Label Studio, an open-source data labeling tool, and its machine learning backend. This enables integration with ML models for annotation assistance. ```shell # Installing Label-Studio may take some time, if the version is not found, please use the official source pip==1.7.2 pip==1.0.9 ``` -------------------------------- ### Setup Multi-Processing Environment Variables Source: https://mmdetection.readthedocs.io/en/latest/_modules/mmdet/utils/setup_env Configures multi-processing settings, including the start method (fork on non-Windows systems), OpenCV thread count, and OMP/MKL thread counts. It aims to optimize performance and prevent system overload by managing thread allocation across multiple processes. The configuration is read from the provided configuration object. ```python def setup_multi_processes(cfg): """Setup multi-processing environment variables.""" # set multi-process start method as `fork` to speed up the training if platform.system() != 'Windows': mp_start_method = cfg.get('mp_start_method', 'fork') current_method = mp.get_start_method(allow_none=True) if current_method is not None and current_method != mp_start_method: warnings.warn( f'Multi-processing start method `{mp_start_method}` is ' f'different from the previous setting `{current_method}`.' f'It will be force set to `{mp_start_method}`. You can change ' f'this behavior by changing `mp_start_method` in your config.') mp.set_start_method(mp_start_method, force=True) # disable opencv multithreading to avoid system being overloaded opencv_num_threads = cfg.get('opencv_num_threads', 0) cv2.setNumThreads(opencv_num_threads) # setup OMP threads # This code is referred from https://github.com/pytorch/pytorch/blob/master/torch/distributed/run.py # noqa workers_per_gpu = cfg.data.get('workers_per_gpu', 1) if 'train_dataloader' in cfg.data: workers_per_gpu = \ max(cfg.data.train_dataloader.get('workers_per_gpu', 1), workers_per_gpu) if 'OMP_NUM_THREADS' not in os.environ and workers_per_gpu > 1: omp_num_threads = 1 warnings.warn( f'Setting OMP_NUM_THREADS environment variable for each process ' f'to be {omp_num_threads} in default, to avoid your system being ' f'overloaded, please further tune the variable for optimal ' f'performance in your application as needed.') os.environ['OMP_NUM_THREADS'] = str(omp_num_threads) # setup MKL threads if 'MKL_NUM_THREADS' not in os.environ and workers_per_gpu > 1: mkl_num_threads = 1 warnings.warn( f'Setting MKL_NUM_THREADS environment variable for each process ' f'to be {mkl_num_threads} in default, to avoid your system being ' f'overloaded, please further tune the variable for optimal ' f'performance in your application as needed.') os.environ['MKL_NUM_THREADS'] = str(mkl_num_threads) ``` -------------------------------- ### SDK Model Inference with MMDeploy Detector Source: https://mmdetection.readthedocs.io/en/latest/user_guides/deploy Performs inference using the MMDeploy SDK's Detector class. This method simplifies the inference process by abstracting away much of the configuration. It takes an image, performs detection, and returns bounding boxes, labels, and masks. The example includes basic visualization by drawing rectangles around detected objects. ```Python from mmdeploy_python import Detector import cv2 img = cv2.imread('demo/demo.jpg') # create a detector detector = Detector(model_path='mmdeploy_models/mmdet/onnx', device_name='cpu', device_id=0) # perform inference bboxes, labels, masks = detector(img) # visualize inference result indices = [i for i in range(len(bboxes))] for index, bbox, label_id in zip(indices, bboxes, labels): [left, top, right, bottom], score = bbox[0:4].astype(int), bbox[4] if score < 0.3: continue cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0)) cv2.imwrite('output_detection.png', img) ``` -------------------------------- ### Initialize DetInferencer with Custom Config and Weights Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Explains how to initialize the DetInferencer using a custom configuration file and its corresponding weight file. This is useful for custom model setups. ```python inferencer = DetInferencer(model='path/to/rtmdet_config.py', weights='path/to/rtmdet.pth') ``` -------------------------------- ### Install MMCV Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio Installs the MMCV library, which is a foundational library for computer vision research and development. Installing MMCV also automatically installs MMEngine. ```shell "mmcv>=2.0.0" ``` -------------------------------- ### Start TorchServe with MMDetection Model Source: https://mmdetection.readthedocs.io/en/latest/user_guides/useful_tools Starts the TorchServe runtime with a specified MMDetection model. Requires the model store directory and the model's .mar file name. Assumes TorchServe is installed and configured. ```bash torchserve --start --model-store ${MODEL_STORE} --models ${MODEL_NAME}.mar ``` -------------------------------- ### Update Guide About Model Deployment Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog Offers an updated guide focused on model deployment strategies. This may include information on optimizing models for inference or deploying them to specific platforms. ```Markdown ## Model Deployment Guide This guide details how to deploy your trained MMDetection models efficiently. ### ONNX Export Export your model to ONNX format for broader compatibility: ```bash python tools/deployment/convert_to_onnx.py --output-file model.onnx ``` ``` -------------------------------- ### Check MMDetection Environment Setup Source: https://mmdetection.readthedocs.io/en/latest/notes/faq Utility script to verify the environment setup for MMDetection, PyTorch, and torchvision, checking for compatibility and correct GPU architecture builds. Helps diagnose 'invalid device function' or 'no kernel image is available' errors. ```Python python mmdet/utils/collect_env.py ``` -------------------------------- ### Install MMDetection Dependencies for Albumentations Source: https://mmdetection.readthedocs.io/en/latest/notes/faq Provides commands to install MMDetection with specific support for the Albumentations library. It highlights the recommended way to install Albumentations to avoid conflicts with OpenCV versions. ```Shell pip install -r requirements/albu.txt ``` ```Shell pip install -U albumentations --no-binary qudida,albumentations ``` -------------------------------- ### Add RTMDet-Ins deployment guide Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog This entry indicates the addition of a guide focused on deploying RTMDet-Ins models. This documentation helps users integrate RTMDet-Ins into their production environments. ```Markdown pass # Represents the addition of an RTMDet-Ins deployment guide ``` -------------------------------- ### Install PyTorch Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio Installs PyTorch with specific versions for different operating systems and CUDA support. It also includes torchvision and torchaudio. ```shell # Linux and Windows CPU only piptorch==1.10.1+cputorchvision==0.11.2+cputorchaudio==0.10.1# Linux and Windows CUDA 11.3 piptorch==1.10.1+cu113torchvision==0.11.2+cu113torchaudio==0.10.1# OSX piptorch==1.10.1torchvision==0.11.2torchaudio==0.10.1 ``` -------------------------------- ### MMDetection Inference Example (With Checkpoint) Source: https://mmdetection.readthedocs.io/en/latest/user_guides/tracking_inference An example command for running MMDetection inference where model weights are loaded using the --checkpoint argument. This is the standard method for many models not requiring separate detector and reid weights. ```python python ``` -------------------------------- ### Build Docker image for MMDetection Source: https://mmdetection.readthedocs.io/en/latest/get_started This Dockerfile snippet builds an image with PyTorch 1.9 and CUDA 11.1. Users can modify the Dockerfile to use different versions of PyTorch and CUDA. ```Docker # build an image with PyTorch 1.9, CUDA 11.1 # If you prefer other versions, just modified the Dockerfile docker ``` -------------------------------- ### Add config migration guide Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog This entry indicates the creation of a guide to help users migrate their existing MMDetection configuration files to newer versions or formats. This is crucial for maintaining compatibility and facilitating upgrades. ```Markdown pass # Represents the addition of a config migration guide ``` -------------------------------- ### Install Image Corruption Functions Source: https://mmdetection.readthedocs.io/en/latest/user_guides/robustness_benchmarking Installs the image corruption functions separately. These functions are used to apply various corruptions to images for benchmarking robustness. ```bash pip install imagecorruptions ``` -------------------------------- ### Start RTMDet Backend Inference Service Source: https://mmdetection.readthedocs.io/en/latest/user_guides/label_studio Starts the RTMDet backend inference service using specified configuration and checkpoint files. It allows configuration for CPU or GPU inference. ```shell cd\ config_file=configs/rtmdet/rtmdet_m_8xb32-300e_coco.py\ checkpoint_file=./work_dirs/rtmdet_m_8xb32-300e_coco_20220719_112220-229f527c.pth\ device=cpu\ --port8003 # Set device=cpu to use CPU inference, and replace cpu with cuda:0 to use GPU inference. ``` -------------------------------- ### Update Deployment Guide Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog Provides updated documentation for model deployment, likely including new methods, best practices, or support for different deployment environments. ```Markdown ## Deploying MMDetection Models This guide covers deploying your trained MMDetection models to various platforms. ### TorchServe Deployment 1. Install TorchServe. 2. Convert your model to TorchScript. 3. Create a `mar` file. 4. Serve the model using TorchServe CLI. ``` -------------------------------- ### Troubleshoot MMCV Installation Errors Source: https://mmdetection.readthedocs.io/en/latest/notes/faq Offers solutions for common MMDetection installation errors related to MMCV compatibility. It includes steps to uninstall conflicting versions and install the correct MMCV package. ```Shell pip uninstall mmcv-lite ``` -------------------------------- ### MMDetection Inference Example (No Checkpoint) Source: https://mmdetection.readthedocs.io/en/latest/user_guides/tracking_inference An example command for running MMDetection inference without explicitly specifying the --checkpoint argument. This typically implies that the model weights will be loaded via the --detector argument, which is common for certain tracking algorithms. ```python python ``` -------------------------------- ### Initialize DetInferencer on CPU Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Illustrates how to initialize the DetInferencer to run inference on the CPU. This is useful when GPU is not available or for specific testing scenarios. ```python inferencer = DetInferencer(model='rtmdet_tiny_8xb32-300e_coco', device='cpu') ``` -------------------------------- ### Install MMDetection with Editable Mode Source: https://mmdetection.readthedocs.io/en/latest/notes/faq Explains how to install MMDetection in editable mode using pip. This allows local code modifications to take effect immediately without requiring reinstallation, which is a best practice for development. ```Shell pip install -e . ``` -------------------------------- ### Training Configuration (MMDetection v2.x) Source: https://mmdetection.readthedocs.io/en/latest/migration/config_migration Example of training configuration in MMDetection v2.x, specifying the runner type, maximum epochs, and evaluation interval. ```python runner = dict( type='EpochBasedRunner', max_epochs=12) evaluation = dict(interval=2) ``` -------------------------------- ### Initialize DetInferencer on a Specific GPU Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Demonstrates how to specify the inference device when initializing the DetInferencer. This example shows how to bind the inferencer to a specific GPU, in this case, 'cuda:1'. ```python inferencer = DetInferencer(model='rtmdet_tiny_8xb32-300e_coco', device='cuda:1') ``` -------------------------------- ### Visualize Test Results via Command Line Source: https://mmdetection.readthedocs.io/en/latest/user_guides/visualization Explains how to use command-line arguments `--show` and `--show-dir` to visualize test results without modifying the configuration file. ```bash # Show test results python# Specify where to store the prediction results python ``` -------------------------------- ### Create and Populate DetDataSample Source: https://mmdetection.readthedocs.io/en/latest/_modules/mmdet/structures/det_data_sample Demonstrates how to create an instance of DetDataSample and populate it with ground truth instance data, including bounding boxes and labels. It also shows how to access metadata associated with the instance data. ```Python >>> import torch >>> import numpy as np >>> from mmengine.structures import InstanceData >>> from mmdet.structures import DetDataSample >>> data_sample = DetDataSample() >>> img_meta = dict(img_shape=(800, 1196), ... pad_shape=(800, 1216)) >>> gt_instances = InstanceData(metainfo=img_meta) >>> gt_instances.bboxes = torch.rand((5, 4)) >>> gt_instances.labels = torch.rand((5,)) >>> data_sample.gt_instances = gt_instances >>> assert 'img_shape' in data_sample.gt_instances.metainfo_keys() >>> len(data_sample.gt_instances) 5 >>> print(data_sample) ) at 0x7f21fb1b9880> ``` -------------------------------- ### Run Distributed Test for Evaluation Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference This snippet shows how to perform distributed testing for model evaluation using the `dist_test.sh` script. It provides examples for running evaluation on a single GPU or across 8 GPUs. ```Shell ./tools/dist_test.sh ``` ```Shell # 1 gpu ./tools/dist_test.sh 1 ``` ```Shell # 8 GPU ./tools/dist_test.sh 8 ``` -------------------------------- ### Set MMDetection PYTHONPATH Source: https://mmdetection.readthedocs.io/en/latest/get_started This snippet demonstrates how to modify the PYTHONPATH environment variable to ensure that training and testing scripts use a specific version of MMDetection. It prepends the parent directory of the current script to the PYTHONPATH. ```bash PYTHONPATH="$(dirname$0)/..":$PYTHONPATH ``` -------------------------------- ### Configure Visualization Backends Source: https://mmdetection.readthedocs.io/en/latest/user_guides/visualization Sets up different visualization backends for MMDetection, including local storage, Tensorboard, and Weights & Biases. ```python _base_.visualizer.vis_backends = [ dict(type='LocalVisBackend'), # dict(type='TensorboardVisBackend'), dict(type='WandbVisBackend'),] ``` -------------------------------- ### Customize Optimizer with PyTorch's Adam Source: https://mmdetection.readthedocs.io/en/latest/advanced_guides/customize_runtime Demonstrates how to switch to a different optimizer supported by PyTorch, such as Adam, by modifying the `optimizer` field within the `optim_wrapper` configuration. This example shows a basic Adam optimizer setup. ```python optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='Adam', lr=0.0003, weight_decay=0.0001)) ``` -------------------------------- ### Download ADE20K Dataset Source: https://mmdetection.readthedocs.io/en/latest/user_guides/dataset_prepare This command downloads the ADE20K dataset, which includes images and annotations for semantic, instance, and panoptic segmentation tasks. After downloading, annotations need to be moved and a preprocess script run. ```Shell tools/misc/download_dataset.py ADE20K ``` -------------------------------- ### Clarify installation documentation Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog_v2 Enhances the clarity and completeness of the installation documentation, making it easier for new users to set up the environment. ```Python installation documentation ``` -------------------------------- ### MMDetection Config Name Style Example Source: https://mmdetection.readthedocs.io/en/latest/user_guides/tracking_config Illustrates the recommended naming convention for MMDetection configuration files. The pattern follows {method}_{module}_{train_cfg}_{train_data}_{test_data}, providing a structured approach to organizing training and testing configurations. ```text {method}_{module}_{train_cfg}_{train_data}_{test_data} ``` -------------------------------- ### Update FAQ about Windows Installation of pycocotools Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog Provides updated information in the FAQ section regarding potential issues and solutions for installing `pycocotools` on Windows systems. ```Markdown ## FAQ - Windows Installation Issues **Q: `pycocotools` installation fails on Windows.** A: Ensure you have Microsoft Visual C++ Build Tools installed. You might need to compile `pycocotools` from source if pip installation fails. ``` -------------------------------- ### Add documentation about init_cfg Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog_v2 Provides comprehensive documentation for the `init_cfg` (initialization configuration) parameter, explaining its usage for model initialization strategies. ```Python init_cfg ``` -------------------------------- ### Prepare Model for Publishing Source: https://mmdetection.readthedocs.io/en/latest/user_guides/useful_tools This script prepares a model for publishing by converting weights to CPU tensors, deleting optimizer states, and computing a hash for the checkpoint file. It takes input and output filenames as arguments. ```shell python tools/model_converters/publish_model.py ${INPUT_FILENAME}${OUTPUT_FILENAME} ``` -------------------------------- ### Train with Slurm using MMDetection Source: https://mmdetection.readthedocs.io/en/latest/user_guides/tracking_train_test This snippet demonstrates how to train MMDetection models using Slurm, a job scheduling system. It utilizes `slurm_train.sh` and requires specifying parameters such as partition, job name, configuration file, work directory, and number of GPUs. The example shows a configuration for training the QDTrack model. ```bash ${PARTITION}${JOB_NAME}${CONFIG_FILE}${WORK_DIR}${GPUS} ``` ```bash PORT=29501\ GPUS_PER_NODE=8\ SRUN_ARGS="--quotatype=reserved"\ bash\ mypartition\ mottrack configs/qdtrack/qdtrack_faster-rcnn_r50_fpn_8xb2-4e_mot17halftrain_test-mot17halfval.py ./work_dirs/QDTrack 8 ``` -------------------------------- ### MMDetection Webcam Inference Demo Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Live inference demo from a webcam using MMDetection. Requires config file, checkpoint file, and optionally device, camera ID, and score threshold. ```bash python demo/webcam_demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--camera-id ${CAMERA-ID}] [--score-thr ${SCORE_THR}] ``` -------------------------------- ### Verify PyTorch CUDA Availability Source: https://mmdetection.readthedocs.io/en/latest/notes/faq A simple Python command to check if PyTorch is correctly installed and can utilize the CUDA capabilities of the GPU. Essential for diagnosing 'Segmentation fault' errors related to PyTorch installation. ```Python import torch; print(torch.cuda.is_available()) ``` -------------------------------- ### Add Tutorials for Building New Models Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog_v2 This improvement adds tutorials to guide users on building new models using existing datasets within MMDetection. It addresses issue #4396. ```Python # Conceptual example of how a tutorial might be structured. # Actual tutorial content would be in separate markdown or Python files. # # # tutorial_build_new_model.py # from mmdet.models import build_detector # from mmcv import Config # # # Load a base config # cfg = Config.fromfile('configs/your_base_model.py') # # # Modify the model configuration for a new model # cfg.model.backbone.type = 'NewBackbone' # cfg.model.neck.type = 'NewNeck' # cfg.model.bbox_head.type = 'NewBBoxHead' # # # Build the new model # new_model = build_detector(cfg.model) # print('New model built successfully!') ``` -------------------------------- ### MMDetection Slurm Training Source: https://mmdetection.readthedocs.io/en/latest/user_guides/train Illustrates how to manage MMDetection training jobs using Slurm. It shows the basic usage of slurm_train.sh and provides an example for training with 16 GPUs on a specific Slurm partition, including setting the work directory. ```bash # Basic usage: # bash tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} ${WORK_DIR} [GPUS=${GPUS}] # Example with 16 GPUs: GPUS=16 # bash tools/slurm_train.sh _dev_ mask_rcnn_r50_fpn_1x_coco ./configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py ./workdirs/mask_rcnn_r50_fpn_1x_coco --gpus 16 ``` -------------------------------- ### Download RefCOCO Datasets Source: https://mmdetection.readthedocs.io/en/latest/user_guides/dataset_prepare This command downloads the RefCOCO series datasets, including images and annotations, using a provided script. Ensure the script is available in the tools/misc directory. ```Shell tools/misc/download_dataset.py RefCOCO ``` -------------------------------- ### MMDetection Middle Data Format Example (JSON) Source: https://mmdetection.readthedocs.io/en/latest/advanced_guides/customize_dataset An example of the standard data annotation format used by MMDetection. It includes 'metainfo' for dataset metadata like class names and 'data_list' containing image paths, dimensions, and instance annotations with bounding boxes and labels. ```json { "metainfo": { "classes": ("person", "bicycle", "car", "motorcycle"), "...": "..." }, "data_list": [ { "img_path": "xxx/xxx_1.jpg", "height": 604, "width": 640, "instances": [ { "bbox": [0, 0, 10, 20], "bbox_label": 1, "ignore_flag": 0 }, { "bbox": [10, 10, 110, 120], "bbox_label": 2, "ignore_flag": 0 } ] }, { "img_path": "xxx/xxx_2.jpg", "height": 320, "width": 460, "instances": [ { "bbox": [10, 0, 20, 20], "bbox_label": 3, "ignore_flag": 1 } ] }, "..." ] } ``` -------------------------------- ### Inference with Directory Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Explains how to process all images within a specified directory using the inferencer. ```Python inferencer('path/to/your_imgs/') ``` -------------------------------- ### Configure TensorBoard and Wandb Backends Source: https://mmdetection.readthedocs.io/en/latest/user_guides/visualization This code snippet demonstrates how to configure MMDetection's visualizer to use TensorBoard and Wandb as backends for storing visualization data. By modifying the `vis_backends` list in the configuration file, users can easily integrate with these popular logging tools for monitoring training processes. ```python vis_backends = [ dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend'), dict(type='WandbVisBackend', init_kwargs={'project': 'my_project'}) ] visualizer = dict( type='DetLocalVisualizer', vis_backends=vis_backends, name='visualizer') ``` -------------------------------- ### Inference with Image Path Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Demonstrates how to perform inference by providing a direct path or URL to an image file. ```Python inferencer('demo/demo.jpg') ``` -------------------------------- ### Get COCO Dataset Classes (Python) Source: https://mmdetection.readthedocs.io/en/latest/_modules/mmdet/evaluation/functional/class_names Retrieves the list of class names for the COCO dataset. This function has no external dependencies beyond standard Python. ```Python def coco_classes() -> list: """Class names of COCO.""" return [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant', 'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports_ball', 'kite', 'baseball_bat', 'baseball_glove', 'skateboard', 'surfboard', 'tennis_racket', 'bottle', 'wine_glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot_dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted_plant', 'bed', 'dining_table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell_phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy_bear', 'hair_drier', 'toothbrush' ] ``` -------------------------------- ### Get WIDERFace Dataset Classes (Python) Source: https://mmdetection.readthedocs.io/en/latest/_modules/mmdet/evaluation/functional/class_names Retrieves the list of class names for the WIDERFace dataset. This function has no external dependencies beyond standard Python. ```Python from mmengine.utils import is_str def wider_face_classes() -> list: """Class names of WIDERFace.""" return ['face'] ``` -------------------------------- ### Saving Inference Results Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Demonstrates how to save inference predictions and visualizations to an output directory. Allows control over saving predictions and visualizations. ```Python inferencer('demo/demo.jpg', out_dir='outputs/', no_save_pred=False) ``` -------------------------------- ### Refactor setup.cfg Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog Refactors the `setup.cfg` file, likely to improve project configuration, metadata management, or build process. ```INI [metadata] name = mmdetection version = 3.0.0rc4 [options] packages = find: python_requires = >=3.7 ``` -------------------------------- ### MMDetection Training Command Line Arguments Source: https://mmdetection.readthedocs.io/en/latest/user_guides/train Lists common command-line arguments for MMDetection training scripts, such as specifying the working directory, resuming training from checkpoints, and overriding configuration options. ```bash bash tools/train.sh ${CONFIG_FILE} ${GPU_NUM} [--work-dir ${WORK_DIR}] [--resume ${CHECKPOINT_FILE}] [--cfg-options 'Key=value'] ``` -------------------------------- ### Inference with List of Inputs Source: https://mmdetection.readthedocs.io/en/latest/user_guides/inference Illustrates performing inference on multiple images or a mix of image paths and NumPy arrays provided in a list. ```Python inferencer(['img_1.jpg', 'img_2.jpg]) # You can even mix the types inferencer(['img_1.jpg', array]) ``` -------------------------------- ### Backend Model Inference with MMDeploy Source: https://mmdetection.readthedocs.io/en/latest/user_guides/deploy Performs inference using a converted ONNX model. It requires specifying deployment and model configuration files, the backend model path, and an input image. The process involves building a task processor, creating model inputs, running inference, and visualizing the results. ```Python from mmdeploy.apis.utils import build_task_processor from mmdeploy.utils import get_input_shape, load_config import torch deploy_cfg = '../mmdeploy/configs/mmdet/detection/detection_onnxruntime_dynamic.py' model_cfg = 'configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py' device = 'cpu' backend_model = ['mmdeploy_models/mmdet/onnx/end2end.onnx'] image = 'demo/demo.jpg' # read deploy_cfg and model_cfg deploy_cfg, model_cfg = load_config(deploy_cfg, model_cfg) # build task and backend model task_processor = build_task_processor(model_cfg, deploy_cfg, device) model = task_processor.build_backend_model(backend_model) # process input image input_shape = get_input_shape(deploy_cfg) model_inputs, _ = task_processor.create_input(image, input_shape) # do model inference with torch.no_grad(): result = model.test_step(model_inputs) # visualize results task_processor.visualize( image=image, model=model, result=result[0], window_name='visualize', output_file='output_detection.png') ``` -------------------------------- ### Setup Multi-Processes in mmdet Source: https://mmdetection.readthedocs.io/en/latest/api Configures environment variables for multi-processing. This is crucial for setting up distributed training or parallel data loading pipelines. ```Python mmdet.utils.setup_multi_processes(_cfg_) ``` -------------------------------- ### Install MMCV using provided URL Source: https://mmdetection.readthedocs.io/en/latest/notes/changelog_v2 Provides the correct URL for installing MMCV, ensuring users can access the necessary distribution files. ```bash pip install -U openmim mim install mmcv-full -f https://download.openmmlab.com/mmcv/dist/index.html ``` -------------------------------- ### Configure Visualization Backends in MMDetection Source: https://mmdetection.readthedocs.io/en/latest/migration/config_migration Defines the visualization backends to be used with MMDetection, including local file storage, TensorBoard, and WandB. It configures initialization arguments for WandB, specifying the project and group for organizing experiments. ```python vis_backends = [ dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend'), dict(type='WandbVisBackend', init_kwargs={ 'project': 'mmdetection', 'group': 'maskrcnn-r50-fpn-1x-coco' }) ] visualizer = dict( type='DetLocalVisualizer', vis_backends=vis_backends, name='visualizer') ``` -------------------------------- ### Browse MOT Dataset Script Source: https://mmdetection.readthedocs.io/en/latest/user_guides/tracking_analysis_tools Demonstrates how to use the `browse_dataset.py` script to visualize the training dataset for MOT models, helping to verify dataset configurations. It includes placeholders for configuration files and optional arguments. ```Shell tools/analysis_tools/mot/browse_dataset.py ${CONFIG_FILE}[--show-interval${SHOW_INTERVAL}] [--show] ```