hollance / YOLO-CoreML-MPSNNGraph

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

How do you deal with tf.space_to_depth during coreMLTool conversion? #48

Open kechan opened 5 years ago

kechan commented 5 years ago

This is about yolo v2 (not the tiny).

The coreMLTool python part ran without any error generating the .mlmodel file. But when I dropped this into my Xcode project, I got an error:

There was a problem decoding this CoreML document validator error: Custom layer lambda_1 has an empty 'className' field. This field is required in order for Core ML to link to the implementation for this custom class.

The lambda_1 is the custom layer that calls tf.space_to_depth(x, block_size=2). Do you have any suggestion on what to do?

hollance commented 5 years ago

You need to convert this lambda layer into something CoreML understands. I think Core ML supports space-to-depth, so you’d need to insert such a layer manually at that point. See the tfcoreml examples on how to use custom layers to do this (you’d let tfcoreml insert a custom layer, which I think you already did, then replace this afterwards with the Core ML space-to-depth layer).

kechan commented 5 years ago

Thanks. May I ask where is this "tfcoreml example" you are referring to? In-between, I actually wrote my own in Accelerate, but it may be very suboptimal.

hollance commented 5 years ago

It’s in the tfcoreml repo: https://github.com/tf-coreml/tf-coreml/blob/master/examples/custom_layer_examples.ipynb