Publishing Models Using MindSpore Hub

View Source On Gitee

Overview

MindSpore Hub is a platform for storing pre-trained models provided by MindSpore or third-party developers. It provides application developers with simple model loading and fine-tuning APIs, which enables the users to perform inference or fine-tuning based on the pre-trained models and thus deploy to their own applications. Users can also submit their pre-trained models into MindSpore Hub following the specific steps. Thus other users can download and use the published models.

This tutorial uses GoogleNet as an example to describe how to submit models for model developers who are interested in publishing models into MindSpore Hub.

How to Publish Models

You can publish models to MindSpore Hub via PR in hub repo. Here we use GoogleNet as an example to list the steps of model submission to MindSpore Hub.

  1. Host your pre-trained model in a storage location where we are able to access.

  2. Add a model generation python file called mindspore_hub_conf.py in your own repo using this template. The location of the mindspore_hub_conf.py file is shown below:

    googlenet
    ├── src
    │   ├── googlenet.py
    ├── script
    │   ├── run_train.sh
    ├── train.py
    ├── test.py
    ├── mindspore_hub_conf.py
    
  3. Create a {model_name}_{dataset}.md file in hub/mshub_res/assets/mindspore/1.6 using this template. Here 1.6 indicates the MindSpore version. The structure of the hub/mshub_res folder is as follows:

    hub
    ├── mshub_res
    │   ├── assets
    │       ├── mindspore
    │           ├── 1.6
    │               ├── googlenet_cifar10.md
    │   ├── tools
    │       ├── get_sha256.py
    │       ├── load_markdown.py
    │       └── md_validator.py
    

    Note that it is required to fill in the {model_name}_{dataset}.md template by providing file-format, asset-link and asset-sha256 below, which refers to the model file format, model storage location from step 1 and model hash value, respectively.

    file-format: ckpt
    asset-link: https://download.mindspore.cn/models/r1.6/googlenet_ascend_v160_cifar10_official_cv_acc92.53.ckpt
    asset-sha256: b2f7fe14782a3ab88ad3534ed5f419b4bbc3b477706258bd6ed8f90f529775e7
    

    The MindSpore Hub supports multiple model file formats including:

    For each pre-trained model, please run the following command to obtain a hash value required at asset-sha256 of this .md file. Here the pre-trained model googlenet.ckpt is accessed from the storage location in step 1 and then saved in tools folder. The output hash value is: b2f7fe14782a3ab88ad3534ed5f419b4bbc3b477706258bd6ed8f90f529775e7.

    cd /hub/mshub_res/tools
    python get_sha256.py --file ../googlenet.ckpt
    
  4. Check the format of the markdown file locally using hub/mshub_res/tools/md_validator.py by running the following command. The output is All Passed,which indicates that the format and content of the .md file meets the requirements.

    python md_validator.py --check_path ../assets/mindspore/1.6/googlenet_cifar10.md
    
  5. Create a PR in mindspore/hub repo. See our Contributor Wiki for more information about creating a PR.

Once your PR is merged into master branch here, your model will show up in MindSpore Hub Website within 24 hours. Please refer to README for more information about model submission.