Reproducing Algorithm Implementation
Obtaining Sample Code
When you obtain a paper to implement migration on MindSpore, you need to find the reference code that has been implemented in other frameworks. In principle, the reference code must meet at least one of the following requirements:
The author opens the paper to the public.
The implementation is starred and forked by many developers, which means it is widely recognized.
The code is new and maintained by developers.
The PyTorch reference code is preferred.
If the results are not reproducible in the reference project or the version information is missing, check the project issue for information.
If a new paper has no reference implementation, you can refer to Network Constructing Comparison.
Analyzing Algorithm and Network Structure
First, when reading the paper and reference code, you need to analyze the network structure to organize the code writing. The following shows the general network structure of YOLOX.
Module |
Implementation |
---|---|
backbone |
CSPDarknet (s, m, l, x) |
neck |
FPN |
head |
Decoupled Head |
Second, analyze the innovative points of the migration algorithm and record the tricks used during the training, for example, data augmentation added during data processing, shuffle, optimizer, learning rate attenuation policy, and parameter initialization. You can prepare a checklist and fill in the corresponding items during analysis.
For example, the following records some tricks used by the YOLOX network during training.
Trick | Record |
---|---|
Data augmentation | Mosaic, including random scaling, crop, and layout |
MixUp | |
Learning rate attenuation policy | Multiple attenuation modes are available. By default, the COS learning rate attenuation is used. |
Optimizer parameters | SGD momentum=0.9, nesterov=True, and no weight decay |
Training parameters | epoch: 300; batchsize: 8 |
Network structure optimization points | Decoupled Head; Anchor Free; SimOTA |
Training process optimization points | EMA; Data augmentation is not performed for the last 15 epochs; mixed precision |
Note that the tricks used in the code are mainly reproduced. The tricks mentioned in some papers may not be useful.
In addition, you need to determine whether the paper can be implemented by modifying the existing MindSpore model. If yes, you can greatly reduce the development workload. For example, WGAN-PG can be developed based on WGAN. MindSpore models is a model repository. It covers mainstream models in multiple fields, such as machine vision, natural language processing, voice, and recommendation system. You can check whether there are required models from the repository.
Reproducing Paper Implementation
After obtaining the reference code, you need to reproduce the accuracy of the reference implementation and obtain the performance data of the reference implementation. This has the following advantages:
Identify some issues in advance.
Check whether the third-party repository used by the reference code depends on a version to identify version adaptation problems in advance.
Check whether the dataset can be obtained. Some datasets are private or the author adds some datasets to the public dataset. This problem can be found at the reproduction reference implementation stage.
Check whether the reference implementation can reproduce the accuracy of the paper. Some official reference implementations may not reproduce the accuracy of the paper. In this case, detect the problem in time, replace the reference implementation, or adjust the accuracy baseline.
Obtain some reference data for the MindSpore migration process.
Obtain the loss decrease trend to check whether the training convergence trend on MindSpore is normal.
Obtain the parameter file for conversion and inference verification. For details, see Inference and Training Process.
Obtain the performance baseline for performance tuning. For details, see Debugging and Tuning.