Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

NIMA (MobileNetV2 architecture) - ONNX 2 CoreML fails #337

Closed
manuelcosta74 opened this issue Sep 18, 2018 · 6 comments
Closed

NIMA (MobileNetV2 architecture) - ONNX 2 CoreML fails #337

manuelcosta74 opened this issue Sep 18, 2018 · 6 comments

Comments

@manuelcosta74
Copy link

Hi

i'm in the process of converting NIMA based on MobileNetV2 architecture (pytorch) model to CoreML (model can be found here https://modelzoo.co/model/nima).
Did manage to export model from PyTorch to ONNX. Now from ONNX to CoreML is giving the error listed bellow.

Did install from source (1.1.1).

tkx

p.s.: If it helps i can also send onnx file.

Source
import onnx
from onnx_coreml import convert
onnx_model = onnx.load('NIMA_Aesthetics.proto')

mlmodel = convert(onnx_model)

mlmodel.save("NIMA_Aesthetics.mlmodel")

Traceback (most recent call last):

File "", line 1, in
runfile('/xxx/.spyder/NIMA_ONNX2CoreML.py', wdir='/xxx/.spyder')

File "/anaconda2/envs/Pytorch2CoreML/lib/python2.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
execfile(filename, namespace)

File "/anaconda2/envs/Pytorch2CoreML/lib/python2.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 100, in execfile
builtins.execfile(filename, *where)

File "NIMA_ONNX2CoreML.py", line 10, in
mlmodel = convert(onnx_model)

File "/anaconda2/envs/Pytorch2CoreML/lib/python2.7/site-packages/onnx_coreml/converter.py", line 325, in convert
graph = _prepare_onnx_graph(onnx_model.graph, transformers)

File "/anaconda2/envs/Pytorch2CoreML/lib/python2.7/site-packages/onnx_coreml/converter.py", line 245, in prepare_onnx_graph
graph
= Graph.from_onnx(graph)

File "/anaconda2/envs/Pytorch2CoreML/lib/python2.7/site-packages/onnx_coreml/_graph.py", line 185, in from_onnx
t.name: numpy_helper.to_array(t) for t in graph.initializer

AttributeError: 'NoneType' object has no attribute 'initializer'

@aseemw
Copy link
Collaborator

aseemw commented Sep 18, 2018

Hi, Yes it would be great if you can provide the saved .onnx model as well. Thanks!

@manuelcosta74
Copy link
Author

@aseemw
Copy link
Collaborator

aseemw commented Sep 18, 2018

It works for me when I try to convert from the top of the master branch (https://github.com/onnx/onnx-coreml#install-from-source):
I used onnx version 1.3.0

import onnx
from onnx_coreml import convert
omodel = onnx.load('NIMA_Aesthetics.proto')
mlmodel = convert(omodel)

@manuelcosta74
Copy link
Author

It worked!
The issue was with onnx version... did have 1.1.2

Thanks!

@manuelcosta74
Copy link
Author

@aseemw is it possible to change input and output names? For example, for this model, we will have names given by indexes or so.
If it is not, please see it as a suggestion.

cheers

@aseemw
Copy link
Collaborator

aseemw commented Sep 19, 2018

Yes, its mentioned in the README

coremltools.utils.rename_feature(spec, 'old_output_name', 'new_output_name')

See: https://apple.github.io/coremltools/#

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants