Comments (7)
from tflite2tensorflow.
I see. I will add an option to enable CoreML optimization. Thank you for doing some meaningful research! 😸
from tflite2tensorflow.
Commit: ab7d962
Release: https://github.com/PINTO0309/tflite2tensorflow/releases/tag/v1.19.0
from tflite2tensorflow.
Sad to say, I don't own an IOS environment, so I can't test it. I'm not entirely sure if it will work, but could you please check if the CoreML model you downloaded from the following URL works?
model_coreml_float32.mlmodel.zip
docker run -it --rm \
-v `pwd`:/home/user/workdir \
ghcr.io/pinto0309/tflite2tensorflow:latest
wget https://github.com/google/mediapipe/raw/master/mediapipe/modules/palm_detection/palm_detection_full.tflite
tflite2tensorflow \
--model_path palm_detection_full.tflite \
--flatc_path ../flatc \
--schema_path ../schema.fbs \
--output_pb
tflite2tensorflow \
--model_path palm_detection_full.tflite \
--flatc_path ../flatc \
--schema_path ../schema.fbs \
--output_coreml
from tflite2tensorflow.
Thanks for the reply. Just test the model on the IOS, still get the same error.
2022-02-16 12:04:35.315685+0000 MLModelCamera[12740:4737111] [espresso] [Espresso::handle_ex_plan] exception=Espresso exception: "Generic error": [Exception from layer 240: model_1/model/add_24/add]Espresso exception: "Invalid blob shape": elementwise_kernel_cpu: Cannot broadcast [12, 2, 1, 256, 1] and [12, 1, 1, 256, 1] status=-1
2022-02-16 12:04:35.315728+0000 MLModelCamera[12740:4737111] [coreml] Error computing NN outputs -1
2022-02-16 12:04:35.315755+0000 MLModelCamera[12740:4737111] [coreml] Failure in -executePlan:error:.
failed to perform
I checked the layer 240 of the graph, pretty sure the ResizeBilinear caused this problem, as it has also been mentioned in many onnx->coreml conversion, e.g. :
(onnx/onnx-coreml#474)
(apple/coremltools#1105)
I also noticed that the new height and new width in resizebilinear layer are all 0. Is that something related?
Thanks
from tflite2tensorflow.
I don't think the number 240 in the error message is directly related to the error. The error occurs in the operation named model_1/model/add_24/add
.
[Exception from layer 240: model_1/model/add_24/add]Espresso exception: "Invalid blob shape": elementwise_kernel_cpu: Cannot broadcast [12, 2, 1, 256, 1] and [12, 1, 1, 256, 1] status=-1
The shape of the tensor shown in the error message is obviously wrong.
Cannot broadcast [12, 2, 1, 256, 1] and [12, 1, 1, 256, 1]
This is because there are no operations in this model that process in 5 dimensions.
I also noticed that the new height and new width in resizebilinear layer are all 0. Is that something related?
No, not at all. It is correct that new_height
and new_width
are set to zero, as per the specification. Since the second input is set to [24, 24]
, ResizeBilinear (upsample)
will produce an output of size 24 in height and width.
The way I see it, it's a bug in CoreML.
from tflite2tensorflow.
Hi, Katsuya
I am glad to tell you I find a way to work around. I was inspired by this article https://machinethink.net/blog/coreml-upsampling/ (go to the Cheatsheet section)
Instead of using tf.image.resize, I use tf.compat.v1.image.resize_bilinear. The hacked code I used for coreml specifically is as follows:
elif op_type == 'RESIZE_BILINEAR':
input_tensor = tensors[op['inputs'][0]]
size_detail = interpreter._get_tensor_details(op['inputs'][1])
size = interpreter.get_tensor(size_detail['index'])
size_height = size[0]
size_width = size[1]
options = op['builtin_options']
align_corners = options['align_corners']
half_pixel_centers = options['half_pixel_centers']
def upsampling2d_bilinear(x, size_height, size_width, align_corners, half_pixel_centers):
if optimizing_for_edgetpu_flg:
return tf.image.resize_bilinear(x, (size_height, size_width))
else:
if optimizing_for_openvino_and_myriad:
if half_pixel_centers:
return tf.image.resize_bilinear(
x,
(size_height, size_width),
align_corners=False,
half_pixel_centers=half_pixel_centers
)
else:
return tf.image.resize_bilinear(
x,
(size_height, size_width),
align_corners=True,
half_pixel_centers=half_pixel_centers
)
else:
y = tf.compat.v1.image.resize_bilinear(x, [size_height, size_width], align_corners=True) # slightly better way, which works on IOS
# y = tfv2.keras.layers.UpSampling2D()(x) # no matching solution in COREML
# y = tfv2.image.resize( # no matching solution in COREML
# x,
# [size_height, size_width],
# method='bilinear'
# )
return y
from tflite2tensorflow.
Related Issues (20)
- Error converting face_landmark_with_attention.tflite HOT 2
- Error converting pose_detection.tflite [ No such file or directory: './pose_detection.json' ] HOT 2
- Error converting pose_detection.tflite [ No such file or directory: './pose_detection.json' ] HOT 3
- The shape of the output layer is different from the result of the tensorflow2onnx transformation. HOT 8
- Order of input channels switched on ONNX HOT 2
- Add option to optimize tf.math.reduce_prod to Myriad (OAK) HOT 7
- Got error while converting magenta_arbitrary-image-stylization-v1-256_fp16_transfer_1.tflite to .h5 format HOT 1
- ValueError: The name 'serving_default_input_1:0:0' looks a like a Tensor name, but is not a valid one. Tensor names must be of the form "<op_name>:<output_index>". HOT 1
- CoreML conversions of face_landmark_with_attention.tflite fails HOT 3
- No json file HOT 1
- OSError: SavedModel file does not exist at: saved_model/{saved_model.pbtxt|saved_model.pb} HOT 1
- fail to convert [KNIFT] HOT 2
- Use docker but no *.json error HOT 6
- model quantified slower than not quantifed on windows x64 HOT 1
- tflite2tensorflow Docker has flatc error HOT 4
- Problem converting pose_landmark (full) HOT 1
- How to add custom operators to tflite runtime? HOT 1
- TypeError: Interpreter._get_tensor_details() missing 1 required positional argument: 'subgraph_index' HOT 3
- TypeError: Interpreter._get_tensor_details() missing 1 required positional argument: 'subgraph_index' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tflite2tensorflow.