GithubHelp home page GithubHelp logo

mindspore-lab / mindcv Goto Github PK

View Code? Open in Web Editor NEW
230.0 12.0 139.0 11.07 MB

A toolbox of vision models and algorithms based on MindSpore

Home Page: https://mindspore-lab.github.io/mindcv/

License: Apache License 2.0

Python 99.91% Shell 0.09%
computer-vision cv deep-learning image-classification imagenet mindspore models resnet transformer

mindcv's Introduction

Introduction

MindCV is an open-source toolbox for computer vision research and development based on MindSpore. 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 following is the corresponding mindcv versions and supported mindspore versions.

mindcv mindspore
main master
v0.4.0 2.3.0
0.3.0 2.2.10
0.2 2.0
0.1 1.8

Major Features

  • Easy-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:

    >>> import mindcv
    # 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 line
    python train.py --model=swin_tiny --pretrained --opt=adamw --lr=0.001 --data_dir=/path/to/data
  • State-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 Zoo

The performance of the models trained with MindCV is summarized in here, where the training recipes and weights are both available.

Model introduction and training details can be viewed in each sub-folder under configs.

Installation

See Installation for details.

Getting Started

Hands-on Tutorial

To get started with MindCV, please see the Quick 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.

>>> import mindcv
# 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 accuracy
python validate.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 demo

Right click on the image below and save as dog.jpg.

Classify the downloaded image with a pretrained SoTA model:

python infer.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.

Training

It is easy to train your model on a standard or customized dataset using train.py, where the training strategy (e.g., augmentation, LR scheduling) can be configured with external arguments or a yaml config file.

  • Standalone Training

    # standalone training
    python train.py --model=resnet50 --dataset=cifar10 --dataset_download

    Above is an example for training ResNet50 on CIFAR10 dataset on a CPU/GPU/Ascend device

  • Distributed Training

    For large datasets like ImageNet, it is necessary to do training in distributed mode on multiple devices. This can be achieved with mpirun and parallel features supported by MindSpore.

    # distributed training
    # assume you have 4 GPUs/NPUs
    mpirun -n 4 python train.py --distribute \
        --model=densenet121 --dataset=imagenet --data_dir=/path/to/imagenet

    Notes: If the script is executed by the root user, the --allow-run-as-root parameter must be added to mpirun.

    Detailed parameter definitions can be seen in config.py and checked by running `python train.py --help'.

    To resume training, please set the --ckpt_path and --ckpt_save_dir arguments. The optimizer state including the learning rate of the last stopped epoch will also be recovered.

  • Config and Training Strategy

    You 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 -n 4 python train.py -c configs/squeezenet/squeezenet_1.0_gpu.yaml

    Pre-defined Training Strategies: We provide more than 20 training recipes that achieve SoTA results on ImageNet currently. Please look into the configs folder 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 Platform

    To run training on the ModelArts or OpenI cloud 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 pipeline train.py is run in graph mode on MindSpore, which is optimized for efficiency and parallel computing with a compiled static graph. In contrast, pynative mode is optimized for flexibility and easy debugging. You may alter the parameter --mode to switch to pure pynative mode for debugging purpose.

Mixed Mode:

PyNative mode with mindspore.jit is a mixed mode for comprising flexibility and efficiency in MindSpore. To apply pynative mode with mindspore.jit for training, please run train_with_func.py, e.g.,

python train_with_func.py --model=resnet50 --dataset=cifar10 --dataset_download  --epoch_size=10

Note: this is an experimental function under improvement. It is not stable on MindSpore 1.8.1 or earlier versions.

Validation

To evaluate the model performance, please run validate.py

# validate a trained checkpoint
python validate.py --model=resnet50 --dataset=imagenet --data_dir=/path/to/data --ckpt_path=/path/to/model.ckpt

Validation while Training

You can also track the validation accuracy during training by enabling the --val_while_train option.

python train.py --model=resnet50 --dataset=cifar10 \
    --val_while_train --val_split=test --val_interval=1

The 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 in examples.

Tutorials

We provide the following jupyter notebook tutorials to help users learn to use MindCV.

Model List

Currently, MindCV supports the model families listed below. More models with pre-trained weights are under development and will be released soon.

Supported models

Please see configs for the details about model performance and pretrained weights.

Supported Algorithms

Supported algorithms
  • Augmentation
  • Optimizer
    • Adam
    • AdamW
    • Lion
    • Adan (experimental)
    • AdaGrad
    • LAMB
    • Momentum
    • RMSProp
    • SGD
    • NAdam
  • LR Scheduler
    • Warmup Cosine Decay
    • Step LR
    • Polynomial Decay
    • Exponential Decay
  • Regularization
    • Weight Decay
    • Label Smoothing
    • Stochastic Depth (depends on networks)
    • Dropout (depends on networks)
  • Loss
    • Cross 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)
  • Ensemble
    • Warmup EMA (Exponential Moving Average)

What is New

  • 2024/1/17

Release 0.3.0 is published. We will drop MindSpore 1.x in the future release.

  1. New models:
  2. Features:
    • AsymmetricLoss & JSDCrossEntropy
    • Augmentations Split
    • Customized AMP
  3. Bug fixes:
    • Since the classifier weights are not fully deleted, you may encounter an error passing in the num_classes when creating a pre-trained model.
  4. Refactoring:
    • The names of many models have been refactored for better understanding.
    • Script of VisionTransformer.
    • Script of Mixed(PyNative+jit) mode training.
  5. 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.
  6. BREAKING CHANGES:
    • We are going to drop support of MindSpore 1.x for it's EOL.
    • Configuration filter_bias_and_bn will be removed and renamed as weight_decay_filter, due to a prolonged misunderstanding of the MindSpore optimizer. We will migrate the existing training recipes, but the signature change of function create_optimizer will be incompatible and the old version training recipes will also be incompatible. See PR/752 for details.

See RELEASE for detailed history.

How to Contribute

We appreciate all kinds of contributions including issues and PRs to make MindCV better.

Please refer to CONTRIBUTING.md for the contributing guideline. Please follow the Model Template and Guideline for contributing a model that fits the overall interface :)

License

This project follows the Apache License 2.0 open-source license.

Acknowledgement

MindCV 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 by OpenI.

Citation

If 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}
}

mindcv's People

Contributors

a1085728420 avatar alexdotham avatar ash-lee233 avatar baogerock avatar canna1102 avatar chongwei905 avatar daiyuxin0511 avatar dexterjz avatar geniuspatrick avatar jquan1999 avatar junnan-xjtu avatar junyuliu1 avatar kingcong avatar kw717 avatar lcy-star avatar pingqili avatar qujialing avatar sageyou avatar samithuang avatar songyuanwei avatar spencerr221 avatar sy-liang123 avatar the-truthh avatar vigo999 avatar wcrzlh avatar weizhenhuan avatar xingxjtu avatar xiuyu0000 avatar xixinyang avatar xuanmaixue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mindcv's Issues

[Document]添加优化ViT教程

If this is your first time, please read our contributor guidelines: https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

issue test

If this is your first time, please read our contributor guidelines:
https://github.com/mindspore-lab/mindcv/blob/main/CONTRIBUTING.md

Describe the bug/ 问题描述 (Mandatory / 必填)
A clear and concise description of what the bug is.

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境:

Please delete the backend not involved / 请删除不涉及的后端:
/device ascend/GPU/CPU/kirin/等其他芯片

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) :
    -- Python version (e.g., Python 3.7.5) :
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):
    -- GCC/Compiler version (if compiled from source):

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph):

Please delete the mode not involved / 请删除不涉及的模式:
/mode pynative
/mode graph

To Reproduce / 重现步骤 (Mandatory / 必填)
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior / 预期结果 (Mandatory / 必填)
A clear and concise description of what you expected to happen.

Screenshots/ 日志 / 截图 (Mandatory / 必填)
If applicable, add screenshots to help explain your problem.

Additional context / 备注 (Optional / 选填)
Add any other context about the problem here.

`infer.py` did not read `ckpt_path` input

If this is your first time, please read our contributor guidelines:
https://github.com/mindspore-lab/mindcv/blob/main/CONTRIBUTING.md

Describe the bug/ 问题描述 (Mandatory / 必填)
A clear and concise description of what the bug is.

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境:

Please delete the backend not involved / 请删除不涉及的后端:
/device ascend/GPU/CPU/kirin/等其他芯片

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) :
    -- Python version (e.g., Python 3.7.5) :
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):
    -- GCC/Compiler version (if compiled from source):

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph):

Please delete the mode not involved / 请删除不涉及的模式:
/mode pynative
/mode graph

To Reproduce / 重现步骤 (Mandatory / 必填)
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior / 预期结果 (Mandatory / 必填)
A clear and concise description of what you expected to happen.

Screenshots/ 日志 / 截图 (Mandatory / 必填)
If applicable, add screenshots to help explain your problem.

Additional context / 备注 (Optional / 选填)
Add any other context about the problem here.

Inference speed summary across all models under the same context (batch size)

If this is your first time, please read our contributor guidelines: https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

修改MindCV教程目录结构

If this is your first time, please read our contributor guidelines: https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

The mindcv download lacks log printing

mindcv下载缺少日志打印,日志说明没有远程的下载地址,本地下载的目录地址和权重名称
The mindcv download lacks log printing. The log indicates that there is no remote download address, local download directory address and weight name
image
image
可以参考:
image

README更新

If this is your first time, please read our contributor guidelines: https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

FLOPs estimation script is needed

If this is your first time, please read our contributor guidelines: https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

mindcv list_models issue

mindcv的list_models 建议调整为模型从小规格到大规格打印,而不是无序的
image

可以参考:
image

[RFC] MindCV 0.2 Roadmap - New Feature/Model Request

We are open to collecting valuable new models and algorithms from users!

You are welcome to leave a comment to suggest a new feature/model/algorithm for MIndCV.
You can also vote 👍 or dis-vote 👎 a suggested feature.
If you are interested in implementing one of the suggested features, please leave a comment and let us know

We are looking forward to your voice :)

Difference between train.py and train_with_func.py

Hi, may I know if train.py and train_with_func.py functions same? Under which situation we should use train_with_func.py instead of train.py? I see train_with_func.py has more than 200 lines of codes compared with the default one. Much thanks!

Incorrect model weight urls for PoolFormer

链接文件不是ckpt,且跟其他模型存放的server不一样。
37 default_cfgs = dict(
38 poolformer_s12=_cfg(
39 url='https://github.com/sail-sg/poolformer/releases/download/v1.0/poolformer_s12.pth.tar',
40 crop_pct=0.9),
41 poolformer_s24=_cfg(
42 url='https://github.com/sail-sg/poolformer/releases/download/v1.0/poolformer_s24.pth.tar',
43 crop_pct=0.9),
44 poolformer_s36=_cfg(
45 url='https://github.com/sail-sg/poolformer/releases/download/v1.0/poolformer_s36.pth.tar',
46 crop_pct=0.9),
47 poolformer_m36=_cfg(
48 url='https://github.com/sail-sg/poolformer/releases/download/v1.0/poolformer_m36.pth.tar',
49 crop_pct=0.95),
50 poolformer_m48=_cfg(
51 url='https://github.com/sail-sg/poolformer/releases/download/v1.0/poolformer_m48.pth.tar',
52 crop_pct=0.95),
53 )
54

issue test

If this is your first time, please read our contributor guidelines:
https://github.com/mindspore-lab/mindcv/blob/main/CONTRIBUTING.md

Describe the bug/ 问题描述 (Mandatory / 必填)
A clear and concise description of what the bug is.

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境:

Please delete the backend not involved / 请删除不涉及的后端:
/device ascend/GPU/CPU/kirin/等其他芯片

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) :
    -- Python version (e.g., Python 3.7.5) :
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):
    -- GCC/Compiler version (if compiled from source):

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph):

Please delete the mode not involved / 请删除不涉及的模式:
/mode pynative
/mode graph

To Reproduce / 重现步骤 (Mandatory / 必填)
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior / 预期结果 (Mandatory / 必填)
A clear and concise description of what you expected to happen.

Screenshots/ 日志 / 截图 (Mandatory / 必填)
If applicable, add screenshots to help explain your problem.

Additional context / 备注 (Optional / 选填)
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.