New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Shape Translator missing for OP of type Pad. #147
Comments
Yes Pad is supported: tf-coreml/tfcoreml/_ops_to_layers.py Line 38 in 58fce0f
Did you update your package to point to the latest master? |
Yes, but it’s not in the dictionary: https://github.com/tf-coreml/tf-coreml/blob/master/tfcoreml/_interpret_shapes.py |
ah yes, can you try if adding the entry "'Pad': _identity" in that dictionary fixes the issue. |
There are more ops which this graph is using which are not in de dictionary. I will try the method you provided. Will this not corrupt the generated model?I will post the result if it worked out.
|
Let me know which all ops these are. |
Okay, Now it gives me the error |
PR #148 fixes these errors and has some other fixes as well. A snapshot of the end portion of the TF graph (the unsupported ResizeBilinear op marked inside red): |
Allright, thank you very much. I will try to fix the graph a bit. Will converting it to a quantized graph work?
|
Quantization would not affect the shape of the blobs or the parameters of the resize layer. |
I understand the shapes now indeed. I tweaked it all a bit but it did not work out. It would be really helpful if you could help me to convert this model to Core ML since I really need it for my project. Converting until that layer is not a good option I guess. |
How did you tweak it? Wherever you are defining the TF model architecture, you should make sure that the spatial resize of the image feature array occurs in integer multiples, instead of a fractional number. Yes converting till that layer is not ideal at all, but since fractional upsampling (resize bilinear) is not supported in CoreML version 1, there is no other option. You should be able to convert the model, before and after that layer, and then implement the resize bilinear op functionality in your Xcode app. |
Okay, too bad... I will try something else then. Thanks for your help so far!
|
@gi097: Any progress? I'm trying to convert the same model (well the MobileNet version).
The values for the reshape are input=1 and output=3. That seems like it's also not that hard to implement? |
Sorry, no progress yet. I am now trying to compile caffe instead. |
@seantempesta Hopefully the ssd_example notebook in the examples folder should explain the process. Basically you'd cut two chunks of the TF model before and after the unsupported op and then convert them separately. You can visualize the TF graph to figure out the the correct op and input and output tensor names or use the inspect_pb.py script in the utils folder. The reshape error you are getting maybe can be removed. You can try adding another condition here. Or you can share the model and I can take a look at it. |
@seantempesta we can take a look and try to fix this together? |
@aseemw: This script will generate the checkpoint and the frozen graph for the MobileNet version of the model I'm trying to convert. https://github.com/tensorflow/models/blob/master/research/deeplab/local_test_mobilenetv2.sh I tried adding some code to handle the reshape case, but then all sorts of strange errors started happening so I likely didn't do it right. #120 does seem like the better solution. @gi097: Sure. I've got a LinkNet model converted and trained for my client, so I'm not sure when I'll have more time to dedicate to this process though. Why are you compiling |
@seantempesta Great! Could you send me that converted model if you don’t mind? See my email on Github. I am trying to port caffe, since I wanted to try SegNet, which seemed to be very fast. |
@seantempesta you won't get the reshape error if you use the latest master of tcoreml Both the models can be converted up to the input of the last resizeBilinear op ("ResizeBilinear_3") which is not supported. (Visualized here using Netron) Here is what you can do for the mobilenet model:
This will return a multiarray output of shape [21, 65, 65] (i.e. C=21, H=65, W=65).
For the other model its the same thing, but maybe different shape values (you can find that out by running the TF graph and evaluating the last few tensors). |
@aseemw do you convert the deeplab model success? I ran into the same problem and couldn't convert |
Convert successfully? I will also need this tf model |
Not for me, I just stopped trying. |
@aseemw Could you explain why ResizeBilinear_3 not be supported? For the input ImageSensor, why we don't need to do like SSD-MobileNet(drop the preprocess)? |
I find report this error: AssertionError: Resize Bilinear: height upsampling factor must be an integer (input height = 65, output height = 513) |
Yes, that is an expected error. There is support for bilinear upsampling which is equivalent to resize bilinear when the height/width changes by an integer factor (not the case here). I don't remember SSD architecture exactly, does it have a resize bilinear at the end? If it has maybe it has integer factor. Currently there are two work arounds this:
|
@aseemw No, SSD-MobileNet doesn't have resize bilinear. It has input named ImageSensor as deeplab. But we cut the preprocess step:
I asked this question just because they have the same type and name: ImageSensor. But SSD we need to to cut but for deeplab we don't. These workarounds specify that we can not modify code to accomplish it, right? we have to stop at layer of Resize_Blinear and add code to accomplish work next. I am doing the translator from CoreML model to others, can I translate this custom layer in my translator too(recognize this customer layer, then finish it using code in my model translator)? Because I don't want to leave these code to do by our customers. Morever, could you help to explain the mode:
I don't find any difference in the doc. I am doing the model translator, so I should understand it. Thanks. |
@aseemw I just find one bug of our resize_bilinear, we don't consider resize_bilinear cooperation with squeeze. And after squeeze: CoreML: The output is [1, 3,513, 513] and loadConstant is [3, 1, 1] We can not elementwise_add it. I think it should be similar as #69. Because we ignore squeeze by default. |
Checkout PR #179 that should make adding the custom layer easier. NN stands for nearest neighbor interpolation and the other one is bilinear interpolation. |
Thanks for answering. So, could we solve the bug of ResizeBilinear after Squeeze? |
"The output is [1, 3,513, 513] and loadConstant is [3, 1, 1] We can not elementwise_add it." I think this should not be an issue. CoreML is able to add tensors [3,513,513] and [3,1,1]. |
Yes, my show error is that: Converted code: import tfcoreml as tf_converter
H_in, W_in = 513, 513 # or whatever input size, must be less than / eqaul to 513
tf_converter.convert(tf_model_path = 'frozen_inference_graph.pb',
mlmodel_path = 'deeplab.mlmodel',
output_feature_names = ['sub_2:0'],
input_name_shape_dict = {'ImageTensor:0': (1, H_in, W_in, 3)} model_file = 'deeplab.mlmodel'
mlmodel = coremltools.models.MLModel(model_file)
img = Image.open('cat.png').resize((513, 513))
image = np.asarray(img)
img_tf = np.expand_dims(image, axis = 0)
image = image.transpose((2, 0, 1))
#evaluate CoreML
coreml_output_name = 'sub_2__0'
coreml_input_name = 'ImageTensor__0'
coreml_input = {coreml_input_name: image}
#Test the default CoreML evaluation
coreml_out = mlmodel.predict(coreml_input, useCPUOnly = True)[coreml_output_name]
print(coreml_out) I am not sure this is new issue after your explain. If you can help to make sure, I will open the new issue. |
Its giving error because input type is int, whereas it should be float |
Thanks @aseemw , which gives the same output with Tensorflow. I will continue to test this deeplab v3 model, if I find any issues, I will open. By the way, can we specify exactly our add support broadcast in the AddLayerParams doc? Like Tensorflow's doc: https://www.tensorflow.org/api_docs/python/tf/add, which said:
|
Doesn't it mention there that the set of broadcast able shapes are {[1], [C], [1, H, W], or [C, H, W]} ? |
You are right. I just saw it. If I could saw it before, I would save much time :-( |
If anybody is still looking for DeepLab support on CoreML, I converted the cityscapes MobileNetV2 model with DeepLabv3+. https://github.com/gi097/blindassist-scripts Based on the work of @seantempesta |
@gi097 nice job~! |
I do it manually. You can take a look at my app: https://github.com/BlindAssist/blindassist-ios/blob/3324fc09644c74ec65e4545b69c55ed18bb56b05/BlindAssist/ViewController.m#L95 |
the original image and the mask image are not perfectly matched, |
The CoreML pixel input size differs from the actual view’s size. Hence it might not be calibrated properly. You can take a look at my Storyboard which aligns the views perfectly. |
OK~I'll check that. |
Hi,
When I try to convert a deeplab model: http://download.tensorflow.org/models/deeplabv3_mnv2_cityscapes_train_2018_02_05.tar.gz
Using the following commands:
I get the following error:
TypeError: Shape Translator missing for OP of type Pad.
,But in the
README.md
there is written thatPad
is supported. What is going wrong?The text was updated successfully, but these errors were encountered: