MMdnn icon indicating copy to clipboard operation
MMdnn copied to clipboard

Error converting from PyTorch to IR in Docker mmdnn/mmdnn:cpu.small

Open fprotopapa opened this issue 5 years ago • 1 comments

Platform (like ubuntu 16.04/win10): Ubuntu 16.04.4 LTS, Docker image: mmdnn/mmdnn:cpu.small Python version: 3.5 Source framework with version (like Tensorflow 1.4.1 with GPU): PyTorch 0.4 Destination framework with version (like CNTK 2.3 with GPU): IR Pre-trained model path (webpath or webdisk path): resnet101 Running scripts: mmtoir -f pytorch -d resnet101 --inputShape 3,224,224 -n imagenet_resnet101.pth

Running following commands:

root@291e2e238d7b:/mmdnn/example# mmdownload -f pytorch -n resnet101 -o ./ Downloading: "https://download.pytorch.org/models/resnet101-5d3b4d8f.pth" to /root/.torch/models/resnet101-5d3b4d8f.pth 100.0% PyTorch pretrained model is saved as [./imagenet_resnet101.pth].

root@291e2e238d7b:/mmdnn/example# mmtoir -f pytorch -d resnet101 --inputShape 3,224,224 -n imagenet_resnet101.pth Traceback (most recent call last): File "/usr/local/bin/mmtoir", line 11, in sys.exit(_main()) File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/_script/convertToIR.py", line 184, in _main ret = _convert(args) File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/_script/convertToIR.py", line 77, in _convert inputshape = [int(x) for x in args.inputShape] File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/_script/convertToIR.py", line 77, in inputshape = [int(x) for x in args.inputShape] ValueError: invalid literal for int() with base 10: '3,224,224'

Resulting in error through wrong arg formating.

Changing file:

root@291e2e238d7b:/mmdnn/example# nano /usr/local/lib/python3.5/dist-packages/mmdnn/conversion/_script/convertToIR.py

From line 75 till " parser = PytorchParser(args.network, inputshape)" with:

elif args.srcFramework == 'pytorch':
    assert args.inputShape != None
    inputshape = []
    for x in args.inputShape:
        shape = x.split(',')
    inputshape = [int(x) for x in shape]
    from mmdnn.conversion.pytorch.pytorch_parser import PytorchParser
    parser = PytorchParser(args.network, inputshape)

Eliminates error:

root@291e2e238d7b:/mmdnn/example# mmtoir -f pytorch -d resnet101 --inputShape 3,224,224 -n imagenet_resnet101.pth IR network structure is saved as [resnet101.json]. IR network structure is saved as [resnet101.pb]. IR weights are saved as [resnet101.npy].

fprotopapa avatar Nov 23 '20 20:11 fprotopapa

Thank you for your issues and your fix. We will fix it in our next release.

cookieli avatar Feb 03 '21 05:02 cookieli