Package: mindcv
MindCV📝Documentation|🚀Installation|🎁Model Zoo|🎉Update News|🐛Reporting IssuesEnglish |中文IntroductionMindCV is an open-source toolbox for computer vision research and development based onMindSpore. It collects a series of classic and SoTA vision models, such as ResNet and SwinTransformer, along with their pre-trained weights and training strategies. SoTA methods such as auto augmentation are also provided for performance improvement. With the decoupled module design, it is easy to apply or adapt MindCV to your own CV tasks.The main branch works withMindSpore 1.8+, includingMindSpore 2.0🔥.Major FeaturesEasy-to-Use.MindCV decomposes the vision framework into various configurable components. It is easy to customize your data pipeline, models, and learning pipeline with MindCV:>>>importmindcv# create a dataset>>>dataset=mindcv.create_dataset('cifar10',download=True)# create a model>>>network=mindcv.create_model('resnet50',pretrained=True)Users can customize and launch their transfer learning or training task in one command line.# transfer learning in one command linepythontrain.py--model=swin_tiny--pretrained--opt=adamw--lr=0.001--data_dir=/path/to/dataState-of-The-Art.MindCV provides various CNN-based and Transformer-based vision models including SwinTransformer. Their pretrained weights and performance reports are provided to help users select and reuse the right model:Flexibility and efficiency.MindCV is built on MindSpore which is an efficient DL framework that can be run on different hardware platforms (GPU/CPU/Ascend). It supports both graph mode for high efficiency and pynative mode for flexibility.Model ZooThe performance of the models trained with MindCV is summarized inhere, where the training recipes and weights are both available.Model introduction and training details can be viewed in each sub-folder underconfigs.InstallationSeeInstallationfor details.Getting StartedHands-on TutorialTo get started with MindCV, please see theQuick Start, which will give you a quick tour on each key component and the train/validate/predict pipelines.Below are a few code snippets for your taste.>>>importmindcv# List and find a pretrained vision model>>>mindcv.list_models("swin*",pretrained=True)['swin_tiny']# Create the model object>>>network=mindcv.create_model('swin_tiny',pretrained=True)# Validate its accuracypythonvalidate.py--model=swin_tiny--pretrained--dataset=imagenet--val_split=validation# {'Top_1_Accuracy': 0.80824, 'Top_5_Accuracy': 0.94802, 'loss': 1.7331367141008378}Image classification demoRight click on the image below and save asdog.jpg.Classify the downloaded image with a pretrained SoTA model:pythoninfer.py--model=swin_tiny--image_path='./dog.jpg'# {'Labrador retriever': 0.5700152, 'golden retriever': 0.034551315, 'kelpie': 0.010108651, 'Chesapeake Bay retriever': 0.008229004, 'Walker hound, Walker foxhound': 0.007791956}The top-1 prediction result is labrador retriever, which is the breed of this cut dog.TrainingIt is easy to train your model on a standard or customized dataset usingtrain.py, where the training strategy (e.g., augmentation, LR scheduling) can be configured with external arguments or a yaml config file.Standalone Training# standalone trainingpythontrain.py--model=resnet50--dataset=cifar10--dataset_downloadAbove is an example for training ResNet50 on CIFAR10 dataset on a CPU/GPU/Ascend deviceDistributed TrainingFor large datasets like ImageNet, it is necessary to do training in distributed mode on multiple devices. This can be achieved withmpirunand parallel features supported by MindSpore.# distributed training# assume you have 4 GPUs/NPUsmpirun-n4pythontrain.py--distribute\--model=densenet121--dataset=imagenet--data_dir=/path/to/imagenetNotes: If the script is executed by the root user, the--allow-run-as-rootparameter must be added tompirun.Detailed parameter definitions can be seen inconfig.pyand checked by running `python train.py --help'.To resume training, please set the--ckpt_pathand--ckpt_save_dirarguments. The optimizer state including the learning rate of the last stopped epoch will also be recovered.Config and Training StrategyYou can configure your model and other components either by specifying external parameters or by writing a yaml config file. Here is an example of training using a preset yaml file.mpirun--allow-run-as-root-n4pythontrain.py-cconfigs/squeezenet/squeezenet_1.0_gpu.yamlPre-defined Training Strategies:We provide more than 20 training recipes that achieve SoTA results on ImageNet currently.
Please look into theconfigsfolder for details.
Please feel free to adapt these training strategies to your own model for performance improvement, which can be easily done by modifying the yaml file.Train on ModelArts/OpenI PlatformTo run training on theModelArtsorOpenIcloud platform:1. Create a new training task on the cloud platform.
2. Add run parameter `config` and specify the path to the yaml config file on the website UI interface.
3. Add run parameter `enable_modelarts` and set True on the website UI interface.
4. Fill in other blanks on the website and launch the training task.Graph Mode and PyNative Mode:By default, the training pipelinetrain.pyis run ingraph modeon MindSpore, which is optimized for efficiency and parallel computing with a compiled static graph.
In contrast,pynative modeis optimized for flexibility and easy debugging. You may alter the parameter--modeto switch to pure pynative mode for debugging purpose.Mixed Mode:PyNative mode with mindspore.jitis a mixed mode for comprising flexibility and efficiency in MindSpore. To apply pynative mode with mindspore.jit for training, please runtrain_with_func.py, e.g.,pythontrain_with_func.py--model=resnet50--dataset=cifar10--dataset_download--epoch_size=10Note: this is anexperimentalfunction under improvement. It is not stable on MindSpore 1.8.1 or earlier versions.ValidationTo evaluate the model performance, please runvalidate.py# validate a trained checkpointpythonvalidate.py--model=resnet50--dataset=imagenet--data_dir=/path/to/data--ckpt_path=/path/to/model.ckptValidation while TrainingYou can also track the validation accuracy during training by enabling the--val_while_trainoption.pythontrain.py--model=resnet50--dataset=cifar10\--val_while_train--val_split=test--val_interval=1The training loss and validation accuracy for each epoch will be saved in{ckpt_save_dir}/results.log.More examples about training and validation can be seen inexamples.TutorialsWe provide the following jupyter notebook tutorials to help users learn to use MindCV.Learn about configsInference with a pretrained modelFinetune a pretrained model on custom datasetsCustomize your model//coming soonOptimizing performance for vision transformer//coming soonDeployment demoModel ListCurrently, MindCV supports the model families listed below. More models with pre-trained weights are under development and will be released soon.Supported modelsBig Transfer ResNetV2 (BiT) -https://arxiv.org/abs/1912.11370ConvNeXt -https://arxiv.org/abs/2201.03545ConViT (Soft Convolutional Inductive Biases Vision Transformers)-https://arxiv.org/abs/2103.10697DenseNet -https://arxiv.org/abs/1608.06993DPN (Dual-Path Network) -https://arxiv.org/abs/1707.01629EfficientNet (MBConvNet Family)https://arxiv.org/abs/1905.11946EfficientNet V2 -https://arxiv.org/abs/2104.00298GhostNet -https://arxiv.org/abs/1911.11907GoogLeNet -https://arxiv.org/abs/1409.4842Inception-V3 -https://arxiv.org/abs/1512.00567Inception-ResNet-V2 and Inception-V4 -https://arxiv.org/abs/1602.07261MNASNet -https://arxiv.org/abs/1807.11626MobileNet-V1 -https://arxiv.org/abs/1704.04861MobileNet-V2 -https://arxiv.org/abs/1801.04381MobileNet-V3 (MBConvNet w/ Efficient Head) -https://arxiv.org/abs/1905.02244NASNet -https://arxiv.org/abs/1707.07012PNasNet -https://arxiv.org/abs/1712.00559PVT (Pyramid Vision Transformer) -https://arxiv.org/abs/2102.12122PoolFormer models -https://github.com/sail-sg/poolformerRegNet -https://arxiv.org/abs/2003.13678RepMLPhttps://arxiv.org/abs/2105.01883RepVGG -https://arxiv.org/abs/2101.03697ResNet (v1b/v1.5) -https://arxiv.org/abs/1512.03385ResNeXt -https://arxiv.org/abs/1611.05431Res2Net -https://arxiv.org/abs/1904.01169ReXNet -https://arxiv.org/abs/2007.00992ShuffleNet v1 -https://arxiv.org/abs/1707.01083ShuffleNet v2 -https://arxiv.org/abs/1807.11164SKNet -https://arxiv.org/abs/1903.06586SqueezeNet -https://arxiv.org/abs/1602.07360Swin Transformer -https://arxiv.org/abs/2103.14030VGG -https://arxiv.org/abs/1409.1556Visformer -https://arxiv.org/abs/2104.12533Vision Transformer (ViT) -https://arxiv.org/abs/2010.11929Xception -https://arxiv.org/abs/1610.02357Please seeconfigsfor the details about model performance and pretrained weights.Supported AlgorithmsSupported algorithmsAugmentationAutoAugmentRandAugmentRepeated AugmentationRandErasing (Cutout)CutMixMixUpRandomResizeCropColor Jitter, Flip, etcOptimizerAdamAdamWLionAdan (experimental)AdaGradLAMBMomentumRMSPropSGDNAdamLR SchedulerWarmup Cosine DecayStep LRPolynomial DecayExponential DecayRegularizationWeight DecayLabel SmoothingStochastic Depth (depends on networks)Dropout (depends on networks)LossCross Entropy (w/ class weight and auxiliary logit support)Binary Cross Entropy  (w/ class weight and auxiliary logit support)Soft Cross Entropy Loss (automatically enabled if mixup or label smoothing is used)Soft Binary Cross Entropy Loss (automatically enabled if mixup or label smoothing is used)EnsembleWarmup EMA (Exponential Moving Average)What is New2024/1/17Release0.3.0is published. We will drop MindSpore 1.x in the future release.New models:Y-16GF ofRegNetSwinTransformerV2VOLOCMTHaloNetSSDDeepLabV3CLIP&OpenCLIPFeatures:AsymmetricLoss & JSDCrossEntropyAugmentations SplitCustomized AMPBug fixes:Since the classifier weights are not fully deleted, you may encounter an error passing in thenum_classeswhen creating a pre-trained model.Refactoring:The names of many models have been refactored for better understanding.ScriptofVisionTransformer.Scriptof Mixed(PyNative+jit) mode training.Documentation:A guide of how to extract multiscale features from backbone.A guide of how to finetune the pre-trained model on a custom dataset.BREAKING CHANGES:We are going to drop support of MindSpore 1.x for it's EOL.Configurationfilter_bias_and_bnwill be removed and renamed asweight_decay_filter,
due to a prolonged misunderstanding of the MindSpore optimizer.
We will migrate the existing training recipes, but the signature change of functioncreate_optimizerwill be incompatible
and the old version training recipes will also be incompatible. SeePR/752for details.SeeRELEASEfor detailed history.How to ContributeWe appreciate all kinds of contributions including issues and PRs to make MindCV better.Please refer toCONTRIBUTING.mdfor the contributing guideline.
Please follow theModel Template and Guidelinefor contributing a model that fits the overall interface :)LicenseThis project follows theApache License 2.0open-source license.AcknowledgementMindCV is an open-source project jointly developed by the MindSpore team, Xidian University, and Xi'an Jiaotong University.
Sincere thanks to all participating researchers and developers for their hard work on this project.
We also acknowledge the computing resources provided byOpenI.CitationIf you find this project useful in your research, please consider citing:@misc{MindSpore Computer Vision 2022,
    title={{MindSpore Computer Vision}:MindSpore Computer Vision Toolbox and Benchmark},
    author={MindSpore Vision Contributors},
    howpublished ={\url{https://github.com/mindspore-lab/mindcv/}},
    year={2022}}