hollance / YOLO-CoreML-MPSNNGraph

Tiny YOLO for iOS implemented using CoreML but also using the new MPS graph API.
MIT License
937 stars 252 forks source link

Error trying to convert model to CoreML #69

Open raulsf6 opened 3 years ago

raulsf6 commented 3 years ago

Hi, first of all, thanks for you amazing.

I'm facing an error trying to convert tiny-yolo to CoreML suing the procedures explained in the repo. I manage to get the .h5 representation but when I try to export it to CoreML I get this error:

Traceback (most recent call last):
  File "coreml.py", line 17, in <module>
    coreml_model.input_description['image'] = 'Input image'
  File "/home/rsanchez/.local/share/virtualenvs/Convert-r3iBw4lK/lib/python2.7/site-packages/coremltools/models/model.py", line 79, in __setitem__
    raise AttributeError("No feature with name %s." % key)
AttributeError: No feature with name image.

Could it be due to package versions? I have a virtual Python 3 environment for the Darknet -> Keras transformation and another Python 2.7 environment for the Keras -> CoreML transformation. The only pinned version is Keras but I suppose tensorflow has to be 1.x version. Actually, my packages versions are:

hollance commented 3 years ago

It's probably the coremltools version (I think I used version 2.0 for this or perhaps even 1.0), but the error is that your model does not have an input named 'image'.

raulsf6 commented 3 years ago

@hollance thanks for your answer! I'll try with those coremltools versions. Could you also tell me which h5py version you used? I think the problem could be when exporting from Darknet to Keras. The h5 model looks like this in Netron:

image

So maybe the first transformation is messing up the input/output names?

hollance commented 3 years ago

Just rename the input in the code from image to input_1. It should work then. The name of the input isn't very important.

raulsf6 commented 3 years ago

@hollance, I just managed to execute CoreML.py succesfuly with this packages versions without modifying any code:

keras==1.2.2
tensorflow==1.15.0
coremltools==2.0
h5py

From Darknet to Keras everything works as long as yo use Keras 1.2.2 and Tensorflow 1.x.

Maybe it would be a good idea to update scripts to new versions, specially coreml.py because Python2.7 has no longer support.

Amazing work with this repo!