功能介绍

简介

该脚本转换工具可将PyTorch脚本转换成MindSpore代码。

  • 脚本转换工具根据适配规则,对用户脚本进行转换,大幅度提高了脚本迁移速度,降低了开发者的工作量。该脚本转换工具支持对包括但不限于PyTorch模型支持列表列出的模型进行转换,转换成功后可直接运行,部分模型需要根据实际情况进行少量适配。
  • 此脚本转换工具当前仅支持PyTorch训练脚本转换。
  • 此脚本转换工具能支持PyTorch模型支持列表中的工程转换后训练成功且收敛,对最终精度和性能暂不做保证。
  • 此脚本转换工具转换后的训练工程支持在MindSpore1.5及更新版本上运行。

使用限制

PyTorch模型支持列表

表1 PyTorch模型支持列表

序号

模型

原始训练工程代码链接

备注

1

ResNet系列

ResNet18

https://github.com/pytorch/examples/tree/master/imagenet

  • 暂不支持torchvision.models相关接口的转换,需做以下操作。

    修改原始工程:

    1. 创建目录imagenet/models。
    2. 从torchvision库中拷贝torchvision/models/resnet.py至imagenet/models下,删除from .utils import load_state_dict_from_url语句。
    3. 创建imagenet/models/__init__.py文件,内容为:
      from .resnet import *
    4. main.py中,将import torchvision.models as models改为import models

2

ResNet34

3

ResNet50

4

ResNet101

5

ResNet152

6

ResNeXt-50(32x4d)

7

ResNeXt-101(32x8d)

8

Wide ResNet-50-2

9

Wide ResNet-101-2

10

ShuffleNet系列

ShuffleNetV2

https://github.com/megvii-model/ShuffleNet-Series

-

11

ShuffleNetV2+

12

BERT

https://github.com/codertimo/BERT-pytorch

  • 在转换前,master分支的代码在Loss计算上存在一定问题,需要参考https://github.com/codertimo/BERT-pytorch/issues/32#issuecomment-432877367做少量修改。
  • 转换完成后,该工程在需要安装才能使用,安装步骤如下:
    • 去除requirements.txt文件中的torch项。
    • 执行python3 setup install。
  • 具体使用方式详见仓库README。

13

UNet

https://github.com/milesial/Pytorch-Unet

MindSpore暂不支持ReduceLROnPlateau,需要替换成其他支持的scheduler。

14

ViT

https://github.com/jeonsworld/ViT-pytorch

15

Res2Net

https://github.com/Res2Net/Res2Net-ImageNet-Training

暂不支持torchvision.models相关接口的转换,需做以下操作。

修改原始工程:

  1. 创建目录res2net_pami/models。
  2. res2net_pami/main.py中,将import torchvision.models as models改为import models。

16

EfficientNet系列

EfficientNet-B0

https://github.com/lukemelas/EfficientNet-PyTorch

-

17

EfficientNet-B1

18

EfficientNet-B2

19

EfficientNet-B3

20

EfficientNet-B4

21

EfficientNet-B5

22

EfficientNet-B6

23

EfficientNet-B7

24

EfficientNet-B8

25

pytorch-cifar系列

VGG19

https://github.com/kuangliu/pytorch-cifar

26

PreActResNet18

27

DenseNet121

28

ResNeXt29_2x64d

29

MobileNet

30

MobileNetV2

31

SENet18

32

ShuffleNetG2

33

GoogleNet

34

DPN92

环境准备