### Install and Initialize Pre-commit Hook Source: https://github.com/open-mmlab/mmclassification/blob/main/CONTRIBUTING.md These commands install the pre-commit package and initialize the pre-commit hook in the repository. This ensures that code linters and formatters are enforced on every commit. ```shell pip install -U pre-commit pre-commit install ``` -------------------------------- ### Verify MMClassification Installation (CLI) Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Verifies the MMClassification installation by running an image inference demo from the command line. This requires the library to be installed from source. ```shell python demo/image_demo.py demo/demo.JPEG resnet18_8xb32_in1k --device cpu ``` -------------------------------- ### Install MMPreTrain Multimodal Dependencies Source: https://github.com/open-mmlab/mmclassification/blob/main/README.md Installs the extra dependencies required for multimodal model support in MMPreTrain using the mim command. ```shell mim install -e ".[multimodal]" ``` -------------------------------- ### Configuring Visualizer Backends Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/advanced_guides/runtime.md Sets up the UniversalVisualizer to record training and testing information. This example shows how to configure it to save logs and scalars to local files, TensorBoard, or WandB. ```python visualizer = dict( type='UniversalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), ] ) ``` ```python visualizer = dict( type='UniversalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), dict(type='TensorboardVisBackend'), ] ) ``` ```python visualizer = dict( type='UniversalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), dict(type='WandbVisBackend'), ] ) ``` -------------------------------- ### Train and Test Conformer Models Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/conformer/README.md Provides command-line interface examples for training a Conformer model on a dataset and testing a pre-trained model checkpoint. ```shell python tools/train.py configs/conformer/conformer-small-p32_8xb128_in1k.py ``` ```shell python tools/test.py configs/conformer/conformer-tiny-p16_8xb128_in1k.py https://download.openmmlab.com/mmclassification/v0/conformer/conformer-tiny-p16_3rdparty_8xb128_in1k_20211206-f6860372.pth ``` -------------------------------- ### Configuration System Example Source: https://context7.com/open-mmlab/mmclassification/llms.txt Illustrates how to create a custom training configuration file by inheriting from base configurations and overriding specific settings for models, datasets, and training schedules. This allows for modular and flexible customization. ```python # configs/custom/my_resnet50_config.py _base_ = [ '../_base_/models/resnet50.py', '../_base_/datasets/imagenet_bs32.py', '../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py' ] model = dict( train_cfg=dict( augments=dict(type='CutMix', alpha=1.0) ) ) train_cfg = dict(max_epochs=300, val_interval=10) param_scheduler = dict( type='MultiStepLR', by_epoch=True, milestones=[150, 200, 250], gamma=0.1 ) ``` -------------------------------- ### Train and Test SimSiam Models Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/simsiam/README.md Provides command-line interface examples for training a SimSiam model using a configuration file and testing a model with specific weights. ```shell python tools/train.py configs/simsiam/simsiam_resnet50_8xb32-coslr-100e_in1k.py ``` ```shell python tools/test.py configs/simsiam/benchmarks/resnet50_8xb512-linear-coslr-90e_in1k.py https://download.openmmlab.com/mmselfsup/1.x/simsiam/simsiam_resnet50_8xb32-coslr-100e_in1k/resnet50_linear-8xb512-coslr-90e_in1k/resnet50_linear-8xb512-coslr-90e_in1k_20220825-f53ba400.pth ``` -------------------------------- ### Train and Test MaskFeat Models Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/maskfeat/README.md Provides command-line interface examples for training and testing MaskFeat models using configuration files. ```shell python tools/train.py configs/maskfeat/maskfeat_vit-base-p16_8xb256-amp-coslr-300e_in1k.py ``` ```shell python tools/test.py configs/maskfeat/benchmarks/vit-base-p16_8xb256-coslr-100e_in1k.py https://download.openmmlab.com/mmselfsup/1.x/maskfeat/maskfeat_vit-base-p16_8xb256-amp-coslr-300e_in1k/vit-base-p16_ft-8xb256-coslr-100e_in1k/vit-base-p16_ft-8xb256-coslr-100e_in1k_20221028-5134431c.pth ``` -------------------------------- ### Pipeline Configuration Example in MMPretrain Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/migration.md Demonstrates a typical pipeline configuration for training in MMPretrain, including image loading, cropping, flipping, and packing inputs. This structure is now more consistent across OpenMMLab projects. ```python train_pipeline = [ dict(type='LoadImageFromFile'), dict( type='RandomResizedCrop', scale=224, crop_ratio_range=(0.2, 1.0), backend='pillow', interpolation='bicubic'), dict(type='RandomFlip', prob=0.5), dict(type='PackInputs') ] ``` -------------------------------- ### Install MMPreTrain with Conda Source: https://github.com/open-mmlab/mmclassification/blob/main/README.md Installs the MMPreTrain environment using Conda, setting up Python, PyTorch, and necessary CUDA toolkits. It then clones the repository and installs the package using mim. ```shell conda create -n open-mmlab python=3.8 pytorch==1.10.1 torchvision==0.11.2 cudatoolkit=11.3 -c pytorch -y conda activate open-mmlab pip install openmim git clone https://github.com/open-mmlab/mmpretrain.git cd mmpretrain mim install -e . ``` -------------------------------- ### Inherit Base Configurations Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/user_guides/config.md Example of how to define a configuration file that inherits settings from multiple primitive base files, including models, datasets, schedules, and runtime parameters. ```python _base_ = [ '../_base_/models/resnet50.py', '../_base_/datasets/imagenet_bs32.py', '../_base_/schedules/imagenet_bs256.py', '../_base_/default_runtime.py' ] ``` -------------------------------- ### Install MMClassification from Source Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Installs MMClassification from its source code repository. This method is recommended for development purposes, allowing direct modification of the framework's code. ```shell git clone https://github.com/open-mmlab/mmpretrain.git cd mmpretrain pip install -U openmim && mim install -e . ``` -------------------------------- ### Train and test MobileOne models Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/mobileone/README.md Provides command-line interface examples for training a MobileOne model on a custom dataset and evaluating a pre-trained model checkpoint. ```shell python tools/train.py configs/mobileone/mobileone-s0_8xb32_in1k.py python tools/test.py configs/mobileone/mobileone-s0_8xb32_in1k.py https://download.openmmlab.com/mmclassification/v0/mobileone/mobileone-s0_8xb32_in1k_20221110-0bc94952.pth ``` -------------------------------- ### Visualize Transformed Images Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/dataset_visualization.md Example command to visualize images after they have passed through the data transformation pipeline. ```bash python ./tools/visualization/browse_dataset.py ./configs/resnet/resnet50_8xb32_in1k.py -n 100 ``` -------------------------------- ### Train and Test RegNet Models Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/regnet/README.md Provides command-line interface examples for training a RegNet model on a dataset and evaluating a checkpoint on a test set. ```shell python tools/train.py configs/regnet/regnetx-400mf_8xb128_in1k.py python tools/test.py configs/regnet/regnetx-400mf_8xb128_in1k.py https://download.openmmlab.com/mmclassification/v0/regnet/regnetx-400mf_8xb128_in1k_20211213-89bfc226.pth ``` -------------------------------- ### Download ImageNet using MIM (Bash) Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/user_guides/dataset_prepare.md Command-line instructions to download and preprocess the ImageNet dataset using the MIM tool. Requires OpenXlab CLI installation and login. ```bash # install OpenXlab CLI tools pip install -U openxlab # log in to OpenXLab openxlab login # download and preprocess by MIM, better to execute in $MMPreTrain directory. mim download mmpretrain --dataset imagenet1k ``` -------------------------------- ### Visualize Original Dataset Images Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/dataset_visualization.md Example command to visualize original images from a dataset. This mode is useful for verifying raw data loading before any transformations are applied. ```bash python ./tools/visualization/browse_dataset.py ./configs/resnet/resnet101_8xb16_cifar10.py --phase val --output-dir tmp --mode original --show-number 100 --rescale-factor 10 --channel-order RGB ``` -------------------------------- ### PyTorch Distributed Training Script (Node 2) Source: https://github.com/open-mmlab/mmclassification/blob/main/projects/fgia_accv2022_1st/README.md This command starts a distributed training process on the second node of a multi-node setup using PyTorch's distributed training utilities. It's similar to the Node 1 script but with an incremented NODE_RANK. Environment variables for master port and address, along with the configuration file and GPU count, are essential. ```shell # node 2 NNODES=2 NODE_RANK=1 PORT=${MASTER_PORT} MASTER_ADDR=${MASTER_ADDR} bash tools/dist_train.sh projects/fgia_accv2022_1st/config/mae_vit-large-p16_8xb512-amp-coslr-1600e_in1k.py 8 ``` -------------------------------- ### PyTorch Distributed Training Script (Node 1) Source: https://github.com/open-mmlab/mmclassification/blob/main/projects/fgia_accv2022_1st/README.md This command starts a distributed training process on the first node of a multi-node setup using PyTorch's distributed training utilities. It requires setting environment variables for the number of nodes, the current node's rank, the master port, and the master address. The configuration file and number of GPUs are also specified. ```shell # node 1 NNODES=2 NODE_RANK=0 PORT=${MASTER_PORT} MASTER_ADDR=${MASTER_ADDR} bash tools/dist_train.sh projects/fgia_accv2022_1st/config/mae_vit-large-p16_8xb512-amp-coslr-1600e_in1k.py 8 ``` -------------------------------- ### Switch to Deployment Mode Programmatically Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/replknet/README.md Demonstrates how to instantiate a RepLKNet backbone and manually trigger the switch to deployment mode within a Python script. ```python from mmpretrain.models import RepLKNet backbone = RepLKNet(arch='31B') backbone.switch_to_deploy() ``` -------------------------------- ### Install PyTorch for GPU Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Installs PyTorch and torchvision for GPU platforms using Conda. This command automatically installs the latest compatible versions of PyTorch and cudatoolkit. ```shell conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Verify MMClassification Installation (Python API) Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Verifies the MMClassification installation by running an image inference demo using the Python API. This method is applicable when MMClassification is installed as a package. ```python from mmpretrain import get_model, inference_model model = get_model('resnet18_8xb32_in1k', device='cpu') # or device='cuda:0' inference_model(model, 'demo/demo.JPEG') ``` -------------------------------- ### Load Checkpoint and Resume Training Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/advanced_guides/runtime.md Demonstrates how to specify a checkpoint file to load for inference or resuming training, and how to enable the resume functionality. It also covers command-line options for resuming training. ```python # load from which checkpoint load_from = "Your checkpoint path" # whether to resume training from the loaded checkpoint resume = False ``` ```bash # Automatically resume from the latest checkpoint. python tools/train.py configs/resnet/resnet50_8xb32_in1k.py --resume # Resume from the specified checkpoint. python tools/train.py configs/resnet/resnet50_8xb32_in1k.py --resume checkpoints/resnet.pth ``` -------------------------------- ### Install MMSegmentation via MIM Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/user_guides/downstream.md Installs the OpenMMLab MIM tool and the MMSegmentation framework for semantic segmentation tasks. ```shell pip install openmim mim install 'mmsegmentation>=1.0.0rc0' ``` -------------------------------- ### Initialize and Use Conformer Model Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/conformer/README.md Shows how to load a pre-trained Conformer model, perform a forward pass with dummy input, and extract feature maps from the network. ```python import torch from mmpretrain import get_model model = get_model('conformer-tiny-p16_3rdparty_in1k', pretrained=True) inputs = torch.rand(1, 3, 224, 224) out = model(inputs) print(type(out)) # To extract features. feats = model.extract_feat(inputs) print(type(feats)) ``` -------------------------------- ### Install MMDetection via MIM Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/user_guides/downstream.md Installs the OpenMMLab MIM tool and the MMDetection framework required for object detection tasks. ```shell pip install openmim mim install 'mmdet>=3.0.0rc0' ``` -------------------------------- ### Train HiViT Model using Command Line Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/hivit/README.md This shell command demonstrates how to initiate the training process for a HiViT model. It requires a prepared dataset and a configuration file specific to the HiViT model variant. ```shell python tools/train.py configs/hivit/hivit-tiny-p16_16xb64_in1k.py ``` -------------------------------- ### Install PyTorch for CPU Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Installs PyTorch and torchvision for CPU-only platforms using Conda. This is suitable for environments without a GPU. ```shell conda install pytorch torchvision cpuonly -c pytorch ``` -------------------------------- ### Training Models via Command Line Source: https://context7.com/open-mmlab/mmclassification/llms.txt Provides various command-line examples for training classification models using the `train.py` script. Covers single GPU, multi-GPU, distributed training, resuming training, mixed precision, and overriding configuration options. ```bash python tools/train.py configs/resnet/resnet50_8xb32_in1k.py ``` ```bash python tools/train.py configs/resnet/resnet50_8xb32_in1k.py \ --work-dir ./experiments/resnet50_custom ``` ```bash python tools/train.py configs/resnet/resnet50_8xb32_in1k.py \ --resume ./work_dirs/resnet50_8xb32_in1k/latest.pth ``` ```bash python tools/train.py configs/resnet/resnet50_8xb32_in1k.py --amp ``` ```bash python tools/train.py configs/resnet/resnet50_8xb32_in1k.py --auto-scale-lr ``` ```bash CUDA_VISIBLE_DEVICES=-1 python tools/train.py configs/resnet/resnet50_8xb32_in1k.py ``` ```bash python tools/train.py configs/resnet/resnet50_8xb32_in1k.py \ --cfg-options model.backbone.depth=101 \ train_cfg.max_epochs=200 \ optim_wrapper.optimizer.lr=0.01 ``` ```bash bash ./tools/dist_train.sh configs/resnet/resnet50_8xb32_in1k.py 4 ``` ```bash PORT=29666 bash ./tools/dist_train.sh configs/resnet/resnet50_8xb32_in1k.py 4 ``` ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 PORT=29500 bash ./tools/dist_train.sh config1.py 4 CUDA_VISIBLE_DEVICES=4,5,6,7 PORT=29501 bash ./tools/dist_train.sh config2.py 4 ``` ```bash ./tools/slurm_train.sh partition_name job_name configs/resnet/resnet50_8xb32_in1k.py ./work_dirs ``` ```bash NNODES=2 NODE_RANK=0 PORT=29500 MASTER_ADDR=192.168.1.1 \ bash tools/dist_train.sh configs/resnet/resnet50_8xb32_in1k.py 8 ``` ```bash NNODES=2 NODE_RANK=1 PORT=29500 MASTER_ADDR=192.168.1.1 \ bash tools/dist_train.sh configs/resnet/resnet50_8xb32_in1k.py 8 ``` -------------------------------- ### Install MMClassification with Multi-modality Support Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Installs MMClassification with additional dependencies required for multi-modality models. This can be done either from source or as a Python package. ```shell # Install from source mim install -e ".[multimodal]" # Install as a Python package mim install "mmpretrain[multimodal]>=1.0.0rc8" ``` -------------------------------- ### Install MMClassification as a Python Package Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/get_started.md Installs MMClassification as a standard Python package using mim. This is suitable for users who want to integrate MMClassification into their existing projects. ```shell pip install -U openmim && mim install "mmpretrain>=1.0.0rc8" ``` -------------------------------- ### Execute Training and Testing Commands Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/eva/README.md Provides the command-line interface commands to initiate training on a configuration file and evaluate a model using a specific checkpoint. ```shell python tools/train.py configs/eva/eva-mae-style_vit-base-p16_16xb256-coslr-400e_in1k.py ``` ```shell python tools/test.py configs/eva/benchmarks/vit-base-p16_8xb128-coslr-100e_in1k.py https://download.openmmlab.com/mmselfsup/1.x/eva/eva-mae-style_vit-base-p16_16xb256-coslr-400e_in1k/vit-base-p16_ft-8xb128-coslr-100e_in1k/vit-base-p16_ft-8xb128-coslr-100e_in1k_20221226-f61cf992.pth ``` -------------------------------- ### Train and Test MixMIM Models using Command Line Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/mixmim/README.md These commands illustrate how to initiate training and testing for MixMIM models using the `train.py` and `test.py` scripts provided by the `mmpretrain` library. Ensure your dataset is prepared according to the documentation before running these commands. ```shell python tools/train.py configs/mixmim/mixmim_mixmim-base_16xb128-coslr-300e_in1k.py ``` ```shell python tools/test.py configs/mixmim/benchmarks/mixmim-base_8xb128-coslr-100e_in1k.py https://download.openmmlab.com/mmselfsup/1.x/mixmim/mixmim-base-p16_16xb128-coslr-300e_in1k/mixmim-base-p16_ft-8xb128-coslr-100e_in1k/mixmim-base-p16_ft-8xb128-coslr-100e_in1k_20221208-41ecada9.pth ``` -------------------------------- ### JSON Annotation File Example Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/user_guides/dataset_prepare.md An example of a JSON file adhering to the OpenMMLab 2.0 Dataset Format Specification. It includes 'metainfo' for dataset metadata and 'data_list' containing individual data samples with image paths and ground truth labels. ```json { "metainfo": { "classes": ["cat", "dog"], "...": "..." }, "data_list": [ { "img_path": "xxx/xxx_0.jpg", "gt_label": 0, "...": "..." }, { "img_path": "xxx/xxx_1.jpg", "gt_label": 1, "...": "..." } ] } ``` -------------------------------- ### Visualize Concatenated Images Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/dataset_visualization.md Example of visualizing original and transformed images side-by-side. ```APIDOC ## Visualize Concatenated Images ### Description This example demonstrates visualizing both the original and transformed versions of images together for comparison. ### Method `python tools/visualization/browse_dataset.py` ### Endpoint N/A ### Parameters - **`CONFIG_FILE`**: `configs/swin_transformer/swin-small_16xb64_in1k.py` - **`-n, --show-number`**: `10` (visualize 10 images) - **`-m, --mode`**: `concat` (display original and transformed images side-by-side) ### Request Example ```shell python ./tools/visualization/browse_dataset.py configs/swin_transformer/swin-small_16xb64_in1k.py -n 10 -m concat ``` ### Response Visualized images showing original and transformed versions concatenated. ``` -------------------------------- ### Run t-SNE Visualization Tool Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/t-sne_visualization.md This command demonstrates how to run the t-SNE visualization tool. It requires a configuration file and optionally accepts a checkpoint, work directory, and visualization stage. Various parameters can be tuned to control the t-SNE algorithm and the output. ```bash python tools/visualization/vis_tsne.py \ CONFIG \ [--checkpoint CHECKPOINT] \ [--work-dir WORK_DIR] \ [--test-cfg TEST_CFG] \ [--vis-stage {backbone,neck,pre_logits}] [--class-idx ${CLASS_IDX} [CLASS_IDX ...]] \ [--max-num-class MAX_NUM_CLASS] \ [--max-num-samples MAX_NUM_SAMPLES] \ [--cfg-options CFG_OPTIONS [CFG_OPTIONS ...]] \ [--device DEVICE] \ [--legend] \ [--show] \ [--n-components N_COMPONENTS] \ [--perplexity PERPLEXITY] \ [--early-exaggeration EARLY_EXAGGERATION] \ [--learning-rate LEARNING_RATE] \ [--n-iter N_ITER] \ [--n-iter-without-progress N_ITER_WITHOUT_PROGRESS] \ [--init INIT] ``` -------------------------------- ### Instantiate and Use TinyViT Model Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/tinyvit/README.md Shows how to load a pre-trained TinyViT model using get_model, perform a forward pass with dummy input, and extract features from the model. ```python import torch from mmpretrain import get_model model = get_model('tinyvit-5m_3rdparty_in1k', pretrained=True) inputs = torch.rand(1, 3, 224, 224) out = model(inputs) print(type(out)) # To extract features. feats = model.extract_feat(inputs) print(type(feats)) ``` -------------------------------- ### Visualize Transformed Images Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/dataset_visualization.md Example of how to visualize images after data transformations have been applied. ```APIDOC ## Visualize Transformed Images ### Description This example shows how to visualize images after they have undergone data augmentation and transformation pipelines. ### Method `python tools/visualization/browse_dataset.py` ### Endpoint N/A ### Parameters - **`CONFIG_FILE`**: `./configs/resnet/resnet50_8xb32_in1k.py` - **`-n, --show-number`**: `100` (visualize 100 images) - **`-m, --mode`**: `transformed` (default mode, can be omitted) ### Request Example ```shell python ./tools/visualization/browse_dataset.py ./configs/resnet/resnet50_8xb32_in1k.py -n 100 ``` ### Response Visualized images showing the results of data transformations. ``` -------------------------------- ### GET /models/feature-extraction Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/davit/README.md Initialize a DaViT model instance to extract image features. ```APIDOC ## GET /models/feature-extraction ### Description Loads a pre-trained DaViT model to perform feature extraction on input tensors. ### Method GET ### Endpoint /models/feature-extraction ### Parameters #### Query Parameters - **model_name** (string) - Required - The identifier for the DaViT model - **pretrained** (boolean) - Optional - Whether to load pre-trained weights (default: true) ### Request Example GET /models/feature-extraction?model_name=davit-tiny_3rdparty_in1k&pretrained=true ### Response #### Success Response (200) - **model_type** (string) - The architecture type of the loaded model - **status** (string) - Initialization status ``` -------------------------------- ### Using Reparameterized Weights in Testing Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/zh_CN/papers/replknet.md Demonstrates how to use the reparameterized weights for testing. This involves specifying the deploy configuration file and the deploy checkpoint. ```bash python tools/test.py ${deploy_cfg} ${deploy_checkpoint} --metrics accuracy ``` -------------------------------- ### GET /models/load Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/convmixer/README.md Retrieves a model instance and extracts features from input tensors. ```APIDOC ## GET /models/load ### Description Loads a pre-trained ConvMixer model and provides functionality to extract features from input tensors. ### Method GET ### Endpoint /models/load ### Parameters #### Query Parameters - **model_name** (string) - Required - The name of the model to load - **pretrained** (boolean) - Optional - Whether to load pre-trained weights ### Request Example { "model_name": "convmixer-768-32_3rdparty_in1k", "pretrained": true } ### Response #### Success Response (200) - **model_type** (string) - The type of the loaded model object - **features** (array) - Extracted feature representation #### Response Example { "model_type": "ConvMixer", "features": [0.12, 0.45, ...] } ``` -------------------------------- ### Load and Use VGG Model Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/vgg/README.md Shows how to instantiate a VGG model with pre-trained weights and perform a forward pass with dummy input. It also demonstrates how to extract features from the model. ```python import torch from mmpretrain import get_model model = get_model('vgg11_8xb32_in1k', pretrained=True) inputs = torch.rand(1, 3, 224, 224) out = model(inputs) print(type(out)) # To extract features. feats = model.extract_feat(inputs) print(type(feats)) ``` -------------------------------- ### Install DCNv3 Dependencies Source: https://github.com/open-mmlab/mmclassification/blob/main/projects/internimage_classification/README.md Compiles the necessary DCNv3 operators required for InternImage functionality. ```shell cd ops_dcnv3 sh ./make.sh ``` -------------------------------- ### Train and Test RepVGG Models Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/repvgg/README.md Command-line instructions for training, testing, and evaluating RepVGG models using configuration files. ```shell # Train python tools/train.py configs/repvgg/repvgg-A0_8xb32_in1k.py # Test python tools/test.py configs/repvgg/repvgg-A0_8xb32_in1k.py https://download.openmmlab.com/mmclassification/v0/repvgg/repvgg-A0_8xb32_in1k_20221213-60ae8e23.pth # Test with reparameterized model python tools/test.py configs/repvgg/repvgg-A0_8xb32_in1k.py repvgg_A0_deploy.pth --cfg-options model.backbone.deploy=True ``` -------------------------------- ### GET /models/features Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/mlp_mixer/README.md Extract feature representations from an input tensor using the MLP-Mixer model. ```APIDOC ## GET /models/features ### Description Loads the MLP-Mixer model and extracts feature maps from a provided input tensor. ### Method GET ### Endpoint /models/features ### Parameters #### Query Parameters - **model_name** (string) - Required - The model identifier - **input_shape** (array) - Required - Dimensions of the input tensor (e.g., [1, 3, 224, 224]) ### Request Example { "model_name": "mlp-mixer-base-p16_3rdparty_64xb64_in1k", "input_shape": [1, 3, 224, 224] } ### Response #### Success Response (200) - **features** (tensor) - The extracted feature map from the model backbone #### Response Example { "features": "" } ``` -------------------------------- ### Training iTPN Models with Command Line Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/itpn/README.md Provides the command-line interface command to initiate the training process for iTPN models. This requires a prepared dataset and a configuration file. The command executes the training script with specified parameters. ```shell python tools/train.py configs/itpn/itpn-pixel_hivit-base-p16_8xb512-amp-coslr-800e_in1k.py ``` -------------------------------- ### GET /models/feature-extraction Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/hornet/README.md Initializes a HorNet model and extracts feature maps from input tensors. ```APIDOC ## GET /models/feature-extraction ### Description Loads a pre-trained HorNet model and performs a forward pass to extract features from a given input tensor. ### Method GET ### Endpoint /models/feature-extraction ### Parameters #### Query Parameters - **model_name** (string) - Required - The identifier for the HorNet model - **pretrained** (boolean) - Optional - Whether to load pre-trained weights ### Request Example { "model_name": "hornet-tiny_3rdparty_in1k", "pretrained": true } ### Response #### Success Response (200) - **features** (tensor) - The extracted feature map tensor #### Response Example { "features": "torch.Tensor" } ``` -------------------------------- ### Test Model via Command Line Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/user_guides/test.md Standard command to initiate model testing using a configuration file and a checkpoint file. This script supports various optional arguments for output directory, visualization, and evaluation metrics. ```shell python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [ARGS] ``` -------------------------------- ### Perform Image Classification with MMPretrain Source: https://context7.com/open-mmlab/mmclassification/llms.txt Demonstrates how to initialize an image classification model, perform single and batch inference, and customize model configurations. It also shows how to visualize results and list available pre-trained models. ```python from mmpretrain import ImageClassificationInferencer inferencer = ImageClassificationInferencer('resnet50_8xb32_in1k') result = inferencer('demo/demo.JPEG')[0] # Batch inference results = inferencer(['demo/demo.JPEG', 'demo/bird.JPEG'], batch_size=8) # Custom config and visualization inferencer = ImageClassificationInferencer(model='configs/resnet/resnet50_8xb32_in1k.py', device='cuda') results = inferencer(['demo/dog.jpg'], show_dir='./visualize/', draw_score=True) ``` -------------------------------- ### GET /models/load Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/levit/README.md Retrieve a model instance for feature extraction or custom inference workflows. ```APIDOC ## GET /models/load ### Description Loads a pre-trained LeViT model into memory for further processing or feature extraction. ### Method GET ### Endpoint /models/load ### Parameters #### Query Parameters - **model_name** (string) - Required - The name of the model to load - **pretrained** (boolean) - Optional - Whether to load pre-trained weights (default: true) ### Request Example GET /models/load?model_name=levit-128s_3rdparty_in1k&pretrained=true ### Response #### Success Response (200) - **model_object** (object) - The initialized PyTorch model instance #### Response Example { "status": "success", "model_loaded": "levit-128s_3rdparty_in1k" } ``` -------------------------------- ### GET /models/load Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/densenet/README.md Retrieve a pre-trained DenseNet model instance for feature extraction or further processing. ```APIDOC ## GET /models/load ### Description Loads a pre-trained model into memory for local inference or feature extraction. ### Method GET ### Endpoint /models/load ### Parameters #### Query Parameters - **model_name** (string) - Required - The model identifier - **pretrained** (boolean) - Optional - Whether to load pre-trained weights (default: true) ### Request Example GET /models/load?model_name=densenet121_3rdparty_in1k&pretrained=true ### Response #### Success Response (200) - **model_type** (string) - The architecture type - **status** (string) - Load status #### Response Example { "model_type": "densenet121", "status": "loaded" } ``` -------------------------------- ### Programmatic Reparameterization Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/repmlp/README.md Demonstrates how to initialize a RepMLPNet backbone and switch it to deploy mode programmatically within a Python script. ```python from mmpretrain.models import RepMLPNet backbone = RepMLPNet(arch='B', img_size=224, reparam_conv_kernels=(1, 3)) backbone.switch_to_deploy() ``` -------------------------------- ### Train SimMIM Model Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/simmim/README.md This shell command illustrates how to initiate the training process for a SimMIM model. It requires a configuration file specifying the model architecture and training parameters. ```shell python tools/train.py configs/simmim/simmim_swin-base-w6_8xb256-amp-coslr-100e_in1k-192px.py ``` -------------------------------- ### Visualize Original Images Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/dataset_visualization.md Example of how to visualize original dataset images using the `browse_dataset.py` script. ```APIDOC ## Visualize Original Images ### Description This example demonstrates how to visualize the original images loaded from disk for a specific dataset phase. ### Method `python tools/visualization/browse_dataset.py` ### Endpoint N/A ### Parameters - **`CONFIG_FILE`**: `./configs/resnet/resnet101_8xb16_cifar10.py` - **`-p, --phase`**: `val` (visualize validation set) - **`-o, --output-dir`**: `tmp` (save visualizations to 'tmp' directory) - **`-m, --mode`**: `original` (display original images) - **`-n, --show-number`**: `100` (visualize 100 images) - **`-r, --rescale-factor`**: `10` (enlarge images by 10 times) - **`-c, --channel-order`**: `RGB` (set channel order to RGB) ### Request Example ```shell python ./tools/visualization/browse_dataset.py ./configs/resnet/resnet101_8xb16_cifar10.py --phase val --output-dir tmp --mode original --show-number 100 --rescale-factor 10 --channel-order RGB ``` ### Response Visualized images saved in the specified output directory. ``` -------------------------------- ### Initialize and use MobileOne model Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/mobileone/README.md Shows how to load the MobileOne model architecture, perform a forward pass with random input, and extract features from the backbone. ```python import torch from mmpretrain import get_model model = get_model('mobileone-s0_8xb32_in1k', pretrained=True) inputs = torch.rand(1, 3, 224, 224) out = model(inputs) print(type(out)) # To extract features. feats = model.extract_feat(inputs) print(type(feats)) ``` -------------------------------- ### Visualize Pipeline Images Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/en/useful_tools/dataset_visualization.md Example of visualizing all intermediate images generated throughout the data transformation pipeline. ```APIDOC ## Visualize Pipeline Images ### Description This example shows how to visualize every intermediate image produced during the data transformation pipeline, useful for debugging. ### Method `python tools/visualization/browse_dataset.py` ### Endpoint N/A ### Parameters - **`CONFIG_FILE`**: `configs/swin_transformer/swin-small_16xb64_in1k.py` or `configs/beit/beit_beit-base-p16_8xb256-amp-coslr-300e_in1k.py` - **`-m, --mode`**: `pipeline` (display all intermediate pipeline images) ### Request Example ```shell python ./tools/visualization/browse_dataset.py configs/swin_transformer/swin-small_16xb64_in1k.py -m pipeline ``` ### Response Visualized images showing each step of the data transformation pipeline. ``` -------------------------------- ### GET get_model Source: https://context7.com/open-mmlab/mmclassification/llms.txt Retrieves a model instance by name, with options to load pre-trained weights and customize architecture components. ```APIDOC ## GET get_model ### Description Initializes a model from the MMPreTrain registry. Allows loading pre-trained weights and modifying the head, neck, or backbone. ### Method GET ### Endpoint mmpretrain.get_model(model_name, pretrained=False, **kwargs) ### Parameters #### Path Parameters - **model_name** (string) - Required - The name of the model to retrieve. #### Request Body - **pretrained** (bool/string) - Optional - Boolean to load default weights or string path to a local checkpoint. - **head** (dict) - Optional - Custom configuration for the model head. - **backbone** (dict) - Optional - Custom configuration for the model backbone. ### Response #### Success Response (200) - **model** (object) - A PyTorch model instance ready for inference or feature extraction. ``` -------------------------------- ### GET list_models Source: https://context7.com/open-mmlab/mmclassification/llms.txt Retrieves a list of available pre-trained models in MMPreTrain, supporting pattern matching and task-based filtering. ```APIDOC ## GET list_models ### Description Returns a list of available pre-trained models. Supports filtering by name patterns and specific task types. ### Method GET ### Endpoint mmpretrain.list_models(pattern=None, task=None, exclude_patterns=None) ### Parameters #### Query Parameters - **pattern** (string) - Optional - Pattern to match model names (supports wildcards). - **task** (string) - Optional - Filter models by task (e.g., 'Image Classification'). - **exclude_patterns** (list) - Optional - List of patterns to exclude from results. ### Response #### Success Response (200) - **models** (list) - A list of strings representing the names of available models. ``` -------------------------------- ### Predict Image with SimMIM Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/simmim/README.md This snippet demonstrates how to use the `inference_model` function to get predictions from a pre-trained SimMIM model. ```APIDOC ## Predict Image ### Description Use the `inference_model` function to get predictions from a pre-trained SimMIM model. ### Method `inference_model(model_name, image_path)` ### Parameters - **model_name** (str) - Required - The name of the pre-trained model to use. - **image_path** (str) - Required - The path to the input image. ### Request Example ```python from mmpretrain import inference_model predict = inference_model('swin-base-w6_simmim-100e-pre_8xb256-coslr-100e_in1k-192px', 'demo/bird.JPEG') print(predict['pred_class']) print(predict['pred_score']) ``` ### Response #### Success Response (200) - **pred_class** (str) - The predicted class label. - **pred_score** (float) - The confidence score for the prediction. #### Response Example ```json { "pred_class": "bird", "pred_score": 0.95 } ``` ``` -------------------------------- ### Execute MAE Training and Testing Source: https://github.com/open-mmlab/mmclassification/blob/main/docs/zh_CN/papers/mae.md Provides the command-line interface commands to initiate training and testing processes for MAE models using configuration files. ```shell python tools/train.py configs/mae/mae_vit-base-p16_8xb512-amp-coslr-300e_in1k.py ``` ```shell python tools/test.py configs/mae/benchmarks/vit-base-p16_8xb128-coslr-100e_in1k.py None ``` -------------------------------- ### Use HRNet Model Programmatically Source: https://github.com/open-mmlab/mmclassification/blob/main/configs/hrnet/README.md Shows how to load an HRNet model and extract features or get raw outputs. ```APIDOC ## Use HRNet Model Programmatically ### Description This section explains how to load an HRNet model using `get_model`, perform forward passes, and extract features. ### Method `get_model`, `model()`, `model.extract_feat()` ### Endpoint N/A (This is a programmatic API call) ### Parameters - **model_name** (string) - Required - The name of the HRNet model to load (e.g., 'hrnet-w18_3rdparty_8xb32_in1k'). - **pretrained** (boolean) - Optional - Whether to load pre-trained weights. Defaults to `False`. ### Request Example ```python import torch from mmpretrain import get_model model = get_model('hrnet-w18_3rdparty_8xb32_in1k', pretrained=True) inputs = torch.rand(1, 3, 224, 224) # Example input tensor # Get model output out = model(inputs) print(type(out)) # Extract features feats = model.extract_feat(inputs) print(type(feats)) ``` ### Response #### Success Response (200) - **out** (object) - The raw output of the model. - **feats** (object) - The extracted features from the model. #### Response Example ```python ``` ```