### Detectron2 Installation Guide Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst Instructions for installing the Detectron2 library, including system requirements and build steps. This typically involves cloning the repository and running a setup script. ```bash git clone https://github.com/facebookresearch/detectron2.git cd detectron2 python setup.py install ``` -------------------------------- ### DensePose Installation Source: https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/GETTING_STARTED.md Command to install DensePose as a Python package from its GitHub repository. ```bash pip install git+https://github.com/facebookresearch/detectron2@main#subdirectory=projects/DensePose ``` -------------------------------- ### DensePose Training Example (8 GPUs) Source: https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/GETTING_STARTED.md Shows how to launch end-to-end DensePose-RCNN training with ResNet-50 FPN backbone on 8 GPUs using the s1x schedule. ```bash python train_net.py --config-file configs/densepose_rcnn_R_50_FPN_s1x.yaml --num-gpus 8 ``` -------------------------------- ### DensePose Evaluation Example Source: https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/GETTING_STARTED.md Provides an example of how to perform model evaluation for DensePose, including specifying model weights. ```bash python train_net.py --config-file configs/densepose_rcnn_R_50_FPN_s1x.yaml \ --eval-only MODEL.WEIGHTS model.pth ``` -------------------------------- ### Detectron2 Training with train_net.py Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/getting_started.md Trains a Detectron2 model using the `train_net.py` script. Requires dataset setup and specifying a config file. Supports multi-GPU training and evaluation. ```bash cd tools/ ./train_net.py --num-gpus 8 \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml ``` -------------------------------- ### DensePose Inference Example Source: https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/GETTING_STARTED.md Demonstrates how to run DensePose inference using a pre-trained model to visualize contour and bounding box. ```bash python apply_net.py show configs/densepose_rcnn_R_50_FPN_s1x.yaml densepose_rcnn_R_50_FPN_s1x.pkl image.jpg dp_contour,bbox --output image_densepose_contour.png ``` -------------------------------- ### Detectron2 Single-GPU Training Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/getting_started.md Configures training for a single GPU, adjusting parameters like batch size and learning rate. This is an example of modifying default training configurations. ```bash ./train_net.py \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml \ --num-gpus 1 SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025 ``` -------------------------------- ### DensePose Training Example (1 GPU) Source: https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/GETTING_STARTED.md Illustrates how to train DensePose on a single GPU by applying the linear learning rate scaling rule. ```bash python train_net.py --config-file configs/densepose_rcnn_R_50_FPN_s1x.yaml \ SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025 ``` -------------------------------- ### Detectron2 Training with train_net.py Source: https://github.com/facebookresearch/detectron2/blob/main/GETTING_STARTED.md Trains a Detectron2 model using the `train_net.py` script. Requires dataset setup and specifying a config file. Supports multi-GPU training and evaluation. ```bash cd tools/ ./train_net.py --num-gpus 8 \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml ``` -------------------------------- ### Detectron2 Installation: Colab Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Guides users on installing Detectron2 within a Google Colab environment. It directs users to a Colab Tutorial with step-by-step instructions. -------------------------------- ### Detectron2 Single-GPU Training Source: https://github.com/facebookresearch/detectron2/blob/main/GETTING_STARTED.md Configures training for a single GPU, adjusting parameters like batch size and learning rate. This is an example of modifying default training configurations. ```bash ./train_net.py \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml \ --num-gpus 1 SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025 ``` -------------------------------- ### Detectron2 Getting Started Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst A basic introduction to using Detectron2 for object detection. This tutorial covers loading a pre-trained model and performing inference on an image. ```python from detectron2.engine import DefaultPredictor from detectron2.config import get_cfg cfg = get_cfg() # add project-specific config (e.g., mask R-CNN) cfg.merge_from_file("configs/mask_rcnn_R_50_FPN_3x.yaml") cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # set threshold for this model cfg.MODEL.WEIGHTS = "detectron2://MaskRCNN-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl" predictor = DefaultPredictor(cfg) # Load an image im = cv2.imread("input.jpg") outputs = predictor(im) # Look at the outputs. See https://detectron2.readthedocs.io/tutorials/visualization.html for details. ``` -------------------------------- ### Detectron2 Installation: Docker Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Explains how to install Detectron2 using the official Dockerfile. The Dockerfile contains simple commands for setting up the environment. -------------------------------- ### Detectron2 Model Evaluation Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/getting_started.md Evaluates the performance of a trained Detectron2 model. Requires specifying the config file and the path to the model checkpoint. ```bash ./train_net.py \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml \ --eval-only MODEL.WEIGHTS /path/to/checkpoint_file ``` -------------------------------- ### Detectron2 Installation: Docker Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Explains how to install Detectron2 using the official Dockerfile. The Dockerfile contains simple commands for setting up the environment. -------------------------------- ### Detectron2 Installation: Colab Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Guides users on installing Detectron2 within a Google Colab environment. It directs users to a Colab Tutorial with step-by-step instructions. -------------------------------- ### Detectron2 Model Evaluation Source: https://github.com/facebookresearch/detectron2/blob/main/GETTING_STARTED.md Evaluates the performance of a trained Detectron2 model. Requires specifying the config file and the path to the model checkpoint. ```bash ./train_net.py \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml \ --eval-only MODEL.WEIGHTS /path/to/checkpoint_file ``` -------------------------------- ### Install Detectron2 from GitHub Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Installs the Detectron2 library directly from its GitHub repository using pip. This is a straightforward method for users who want the latest version without local modifications. ```shell python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' ``` -------------------------------- ### Detectron2 Inference Demo Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/getting_started.md Demonstrates how to run inference on images using a pre-trained Detectron2 model. Requires specifying a config file and model weights. Supports webcam and video input, CPU execution, and output saving. ```bash cd demo/ python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \ --input input1.jpg input2.jpg \ [--other-options] \ --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl ``` -------------------------------- ### Detectron2 Plain Training Script Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/getting_started.md Utilizes `plain_train_net.py` for training Detectron2 models. This script offers fewer default features and abstractions, making it easier to customize. ```bash cd tools/ ./plain_train_net.py --num-gpus 8 \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml ``` -------------------------------- ### Install Detectron2 from GitHub Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Installs the Detectron2 library directly from its GitHub repository using pip. This is a straightforward method for users who want the latest version without local modifications. ```shell python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' ``` -------------------------------- ### Install Detectron2 from Local Clone Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Installs Detectron2 from a local copy of the repository. This method is useful for developers who plan to modify the library's code. It requires cloning the repository first and then installing it in editable mode. ```shell git clone https://github.com/facebookresearch/detectron2.git python -m pip install -e detectron2 ``` -------------------------------- ### Install Detectron2 from Local Clone Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Installs Detectron2 from a local copy of the repository. This method is useful for developers who plan to modify the library's code. It requires cloning the repository first and then installing it in editable mode. ```shell git clone https://github.com/facebookresearch/detectron2.git python -m pip install -e detectron2 ``` -------------------------------- ### Detectron2 Inference Demo Source: https://github.com/facebookresearch/detectron2/blob/main/GETTING_STARTED.md Demonstrates how to run inference on images using a pre-trained Detectron2 model. Requires specifying a config file and model weights. Supports webcam and video input, CPU execution, and output saving. ```bash cd demo/ python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \ --input input1.jpg input2.jpg \ [--other-options] \ --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl ``` -------------------------------- ### Detectron2 Plain Training Script Source: https://github.com/facebookresearch/detectron2/blob/main/GETTING_STARTED.md Utilizes `plain_train_net.py` for training Detectron2 models. This script offers fewer default features and abstractions, making it easier to customize. ```bash cd tools/ ./plain_train_net.py --num-gpus 8 \ --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml ``` -------------------------------- ### macOS Detectron2 Installation with Environment Variables Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Provides specific environment variables required for installing Detectron2 on macOS, particularly when using clang compilers and targeting x86_64 architecture. This ensures compatibility and proper building on Apple systems. ```shell CC=clang CXX=clang++ ARCHFLAGS="-arch x86_64" python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' ``` -------------------------------- ### macOS Detectron2 Installation with Environment Variables Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Provides specific environment variables required for installing Detectron2 on macOS, particularly when using clang compilers and targeting x86_64 architecture. This ensures compatibility and proper building on Apple systems. ```shell CC=clang CXX=clang++ ARCHFLAGS="-arch x86_64" python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' ``` -------------------------------- ### Detectron2 Environment Collection Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Collects and displays environment information for Detectron2, including CUDA compiler, CUDA_HOME, and PyTorch CUDA build status. This helps diagnose version inconsistencies. ```python python -m detectron2.utils.collect_env ``` -------------------------------- ### Detectron2 Environment Collection Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Collects and displays environment information for Detectron2, including CUDA compiler, CUDA_HOME, and PyTorch CUDA build status. This helps diagnose version inconsistencies. ```python python -m detectron2.utils.collect_env ``` -------------------------------- ### Detectron2 Windows Compatibility Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Discusses Windows compatibility for Detectron2. While continuously built on Windows via CircleCI, official support is not provided. Contributions that improve Windows compatibility are welcomed. -------------------------------- ### Detectron2 Export APIs Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/deployment.md Main export APIs for tracing and scripting Detectron2 models. Usage is demonstrated in test files and deployment examples. Requires user effort and knowledge of model limitations for scripting and tracing. ```APIDOC TracingAdapter - Used for tracing Detectron2 models. scripting_with_instances - Used for scripting Detectron2 models with instances. ``` -------------------------------- ### Detectron2 Windows Compatibility Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Discusses Windows compatibility for Detectron2. While continuously built on Windows via CircleCI, official support is not provided. Contributions that improve Windows compatibility are welcomed. -------------------------------- ### Detectron2 Training Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst Instructions for training Detectron2 models, including setting up the training configuration, launching the training process, and monitoring progress. ```python from detectron2.engine import launch from detectron2.engine.defaults import DefaultTrainer # Assuming cfg is loaded and configured # trainer = DefaultTrainer(cfg) # trainer.resume_or_load(resume=False) # trainer.train() # To launch training: # python tools/train_net.py --config-file path/to/your/config.yaml ``` -------------------------------- ### Custom Training Hook Example Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/training.md An example of a custom hook that prints a message during training iterations. This demonstrates how to extend the trainer's functionality using the hook system. ```python class HelloHook(HookBase): def after_step(self): if self.trainer.iter % 100 == 0: print(f"Hello at iteration {self.trainer.iter}!") ``` -------------------------------- ### Detectron2 Import Error: '_C' Module Not Found Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Resolves the 'ImportError: cannot import name _C' by ensuring Detectron2 is correctly built and installed. If running from the project's root directory, it advises changing the current directory to avoid importing local files instead of the installed package. -------------------------------- ### Detectron2 Import Error: '_C' Module Not Found Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Resolves the 'ImportError: cannot import name _C' by ensuring Detectron2 is correctly built and installed. If running from the project's root directory, it advises changing the current directory to avoid importing local files instead of the installed package. -------------------------------- ### Clean Detectron2 Build Cache Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Command to clean the build artifacts of Detectron2 when installed from a local clone. Removing the 'build/' directory and all '.so' files is necessary before rebuilding, especially after reinstalling dependencies like PyTorch. ```shell rm -rf build/ **/*.so ``` -------------------------------- ### Clean Detectron2 Build Cache Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Command to clean the build artifacts of Detectron2 when installed from a local clone. Removing the 'build/' directory and all '.so' files is necessary before rebuilding, especially after reinstalling dependencies like PyTorch. ```shell rm -rf build/ **/*.so ``` -------------------------------- ### Detectron2 Configuration Example Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/extend.md Example of configuring a Detectron2 model, specifically setting the input format. ```python input_format="BGR", ``` -------------------------------- ### Install Detectron2 and Prepare Cityscapes Data Source: https://github.com/facebookresearch/detectron2/blob/main/projects/Panoptic-DeepLab/README.md Instructions for installing the Detectron2 library and preparing the Cityscapes dataset for use with Panoptic-DeepLab. Follow the provided links for detailed steps. ```text Install Detectron2 following [the instructions](https://detectron2.readthedocs.io/tutorials/install.html). To use cityscapes, prepare data follow the [tutorial](https://detectron2.readthedocs.io/tutorials/builtin_datasets.html#expected-dataset-structure-for-cityscapes). ``` -------------------------------- ### Detectron2 Lazy Configuration Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst An introduction to Detectron2's lazy configuration system, which allows for more flexible and dynamic configuration management. ```python from detectron2.config import LazyConfig, instantiate # Load a lazy config file cfg = LazyConfig.load("path/to/lazy_config.py") # Instantiate components from the config model = instantiate(cfg.model) dataset = instantiate(cfg.dataloader.train.dataset) # Training loop would then use these instantiated objects. ``` -------------------------------- ### Python Docstring Style Guide Source: https://github.com/facebookresearch/detectron2/blob/main/docs/notes/contributing.md Detectron2 uses Google style docstrings for Python code. This includes clear parameter descriptions, return values, and examples. ```python def my_function(param1: str, param2: int) -> bool: """A brief description of the function. Args: param1: Description of the first parameter. param2: Description of the second parameter. Returns: True if successful, False otherwise. """ pass ``` -------------------------------- ### Set CPU as Model Device Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Configures Detectron2 models to run inference on the CPU instead of the GPU. This is useful when GPU support is not available or not required. ```python MODEL.DEVICE='cpu' ``` -------------------------------- ### Detectron2 Configuration Files Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst Explanation of the configuration system used in Detectron2, which is based on YACS. This covers how to define and merge configuration options. ```yaml SOLVER: IMS_PER_BATCH: 2 BASE_LR: 0.001 MAX_ITER: 50000 DATASETS: TRAIN: ("my_dataset_train",) TEST: ("my_dataset_val",) INPUT: MIN_SIZE_TRAIN: (800,) MAX_SIZE_TRAIN: 1333 ``` -------------------------------- ### Set CPU as Model Device Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Configures Detectron2 models to run inference on the CPU instead of the GPU. This is useful when GPU support is not available or not required. ```python MODEL.DEVICE='cpu' ``` -------------------------------- ### Build Documentation Source: https://github.com/facebookresearch/detectron2/blob/main/docs/README.md Builds the HTML documentation for Detectron2 using the Sphinx build system. ```bash make html ``` -------------------------------- ### Detectron2 Bootstrapping Configuration Example Source: https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/BOOTSTRAPPING_PIPELINE.md An example YAML configuration for bootstrapping datasets in Detectron2. It specifies dataset details, image loading strategies, transformations, batching, inference settings, data sampling, and filtering criteria. ```yaml BOOTSTRAP_DATASETS: - DATASET: "chimpnsee" RATIO: 1.0 IMAGE_LOADER: TYPE: "video_keyframe" SELECT: STRATEGY: "random_k" NUM_IMAGES: 4 TRANSFORM: TYPE: "resize" MIN_SIZE: 800 MAX_SIZE: 1333 BATCH_SIZE: 8 NUM_WORKERS: 1 INFERENCE: INPUT_BATCH_SIZE: 1 OUTPUT_BATCH_SIZE: 1 DATA_SAMPLER: TYPE: "densepose_uniform" COUNT_PER_CLASS: 8 FILTER: TYPE: "detection_score" MIN_VALUE: 0.8 BOOTSTRAP_MODEL: WEIGHTS: https://dl.fbaipublicfiles.com/densepose/evolution/densepose_R_50_FPN_DL_WC1M_3x_Atop10P_CA/217578784/model_final_9fe1cc.pkl ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/facebookresearch/detectron2/blob/main/docs/README.md Installs the Python packages required to build the Detectron2 documentation using pip. ```bash pip install docutils==0.16 Sphinx==3.2.0 recommonmark==0.6.0 sphinx_rtd_theme ``` -------------------------------- ### Set TORCH_CUDA_ARCH_LIST for Compilation Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Specifies the GPU compute capabilities (SM architectures) to compile for when building PyTorch or Detectron2 from source. This ensures compatibility with specific GPU models. ```bash export TORCH_CUDA_ARCH_LIST="6.0;7.0" ``` -------------------------------- ### Set TORCH_CUDA_ARCH_LIST for Compilation Source: https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md Specifies the GPU compute capabilities (SM architectures) to compile for when building PyTorch or Detectron2 from source. This ensures compatibility with specific GPU models. ```bash export TORCH_CUDA_ARCH_LIST="6.0;7.0" ``` -------------------------------- ### Detectron2 Deployment Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst Guidance on deploying trained Detectron2 models for inference in various environments. This may involve exporting models to formats like ONNX or TorchScript. ```python # Example of exporting to TorchScript (simplified) from detectron2.export import ScriptablePredictor # Load model and config # cfg = get_cfg() # ... load model weights ... # Create a scriptable predictor predictor = ScriptablePredictor(cfg, predictor.model) # Trace the model traceable_model = predictor.get_traceable_model() scripted_model = torch.jit.script(traceable_model) # Save the scripted model scripted_model.save("exported_model.pt") ``` -------------------------------- ### Training a Detectron2 Model Source: https://github.com/facebookresearch/detectron2/blob/main/projects/ViTDet/README.md This command initiates the training process for a Detectron2 model using a specified configuration file. It defaults to using 64 GPUs with a batch size of 64. ```bash ../../tools/lazyconfig_train_net.py --config-file configs/path/to/config.py ``` -------------------------------- ### Detectron2 Data Loading Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/index.rst Details on the data loading pipeline in Detectron2, including how to create custom data loaders and handle different data formats. ```python from detectron2.data import build_detection_train_loader, DatasetCatalog, MetadataCatalog # Assuming dataset is registered as 'my_dataset_train' data_loader = build_detection_train_loader(cfg, dataset_name="my_dataset_train") # Iterate through the data loader for data in data_loader: # Process each data sample pass ``` -------------------------------- ### Update libgcc in Conda Environment Source: https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/install.md Updates the libgcc package within a Conda environment. This can help resolve C++ symbol errors that arise from mismatches between the compiler and runtime libraries. ```bash conda update libgcc ``` -------------------------------- ### Detectron2 Configuration Example Source: https://github.com/facebookresearch/detectron2/blob/main/MODEL_ZOO.md Example of a Detectron2 configuration file for Keypoint R-CNN using a ResNet-50 backbone with FPN and a 1x training schedule. This YAML file specifies model architecture, dataset settings, and training hyperparameters. ```yaml MODEL: META_ARC_LIST: ["keypoint_rcnn_R_50_FPN_1x.yaml"] DEVICE: "cuda" DATASETS: TRAIN: ["coco_2017_train_keypoints"] TEST: ["coco_2017_val_keypoints"] SOLVER: IMS_PER_BATCH: 16 BASE_LR: 0.0025 MAX_ITER: 90000 STEPS: [60000, 80000] LR_SCHEDULER_NAME: "WarmupMultiStepLR" GAMMA: 0.1 WARMUP_FACTOR: 0.0033333333333333335 WARMUP_ITERS: 1000 INPUT: MIN_SIZE_TRAIN: [800] MAX_SIZE_TRAIN: 1333 MIN_SIZE_TEST: 800 MAX_SIZE_TEST: 1333 TEST: EXPECTED_RESULTS: [["bbox", "segm", "keypoints"]] KEYPOINT_OK_SCORE_THRES: 0.5 ```