apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.38k stars 631 forks source link

[SSAConverter] Unable to determine target size for ResizeBilinear #715

Open rajasekhar6057 opened 4 years ago

rajasekhar6057 commented 4 years ago

🐞Describe the bug

Trace

[SSAConverter] [197/239] Converting op type: 'LeakyRelu', name: 'conv_dw_15_3_leaky_relu/LeakyRelu', output_shape: (-1, 256, -1, -1). [SSAConverter] [198/239] Converting op type: 'Shape', name: 'up_sampling2d_1/Shape', output_shape: (4,). [SSAConverter] [199/239] Converting op type: 'Conv2D', name: 'conv_pw_15_3/Conv2D', output_shape: (-1, 512, -1, -1). [SSAConverter] [200/239] Converting op type: 'StridedSlice', name: 'up_sampling2d_1/strided_slice', output_shape: (2,). [SSAConverter] [201/239] Converting op type: 'BatchNorm', name: 'conv_pw_15_3_bn/FusedBatchNormV3/Add_batch_norm', output_shape: (-1, 512, -1, -1). [SSAConverter] [202/239] Converting op type: 'Mul', name: 'up_sampling2d_1/mul', output_shape: (2,). [SSAConverter] [203/239] Converting op type: 'LeakyRelu', name: 'conv_pw_15_3_leaky_relu/LeakyRelu', output_shape: (-1, 512, -1, -1). [SSAConverter] [204/239] Converting op type: 'ResizeBilinear', name: 'up_sampling2d_1/resize/ResizeBilinear', output_shape: (-1, 128, -1, -1). Traceback (most recent call last): File "/Users/opt/anaconda3/envs/py_374/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 58, in class_labels='/Users/Desktop/saved_model/loto_classes.txt', File "/Users/opt/anaconda3/envs/py_374/lib/python3.7/site-packages/tfcoreml/_tf_coreml_converter.py", line 691, in convert custom_shape_functions=custom_shape_functions) File "/Users/opt/anaconda3/envs/py_374/lib/python3.7/site-packages/coremltools/converters/tensorflow/_tf_converter.py", line 193, in convert optional_inputs=optional_inputs) File "/Users/opt/anaconda3/envs/py_374/lib/python3.7/site-packages/coremltools/converters/nnssa/coreml/ssa_converter.py", line 154, in ssa_convert converter.convert() File "/Users/opt/anaconda3/envs/py_374/lib/python3.7/site-packages/coremltools/converters/nnssa/coreml/ssa_converter.py", line 578, in convert convert_func(node) File "/Users/opt/anaconda3/envs/py_374/lib/python3.7/site-packages/coremltools/converters/nnssa/coreml/ssa_converter.py", line 2193, in _convert_resize_bilinear raise ValueError('[SSAConverter] Unable to determine target size' ValueError: [SSAConverter] Unable to determine target size for ResizeBilinear## To Reproduce

import tfcoreml tfcoreml.convert( tf_model_path='/Users/Desktop/saved_model/saved_model1.pb', mlmodel_path='/Users/Desktop/saved_model/test.mlmodel', input_name_shape_dict={"image_input": [1, 416, 416, 3]}, output_feature_names= ["conv2d_3/BiasAdd","conv2d_8/BiasAdd","conv2d_13/BiasAdd"], image_input_names="image_input", red_bias=-1, green_bias=-1, blue_bias=-1, image_scale=2.0 / 255.0, minimum_ios_deployment_target='13', class_labels='/Users/Desktop/saved_model/classes.txt', )

System environment (please complete the following information):

Additional context

We tried using coremltools 3.1 and 3.3 and also with tensorflow 1.15 and 2.2 and have the same issue .

we also tried TF OP "ResizeNearestNeighbor" which is involved by keras UpSampling2D layer with default "interpolation='nearest'" option then tried to change the interpolation method to 'bilinear' to see if it's ok for the CoreML convert tool but it didn't work as well.

xiankgx commented 4 years ago

Hi,

I am having exactly this problem as well.

I was able to avoid it by replacing my UpSampling2D layer to something else (tf.image.resize) but what this means is the model loses the ability to take arbitrary sized inputs because in tf.image.resize I have to specify the target size (height and width) instead of specifying a width and height scale as in UpSampling2D. As a result from this, the converted model is basically useless.

These are the versions of libraries that I used: tensorflow : 2.0.0 coremltools: 3.3 (<- the latest version is 3.4 but with that, conversion doesn't even begin with another error) tfcoreml: 1.1