简体   繁体   中英

Can't convert Frozen Inference Graph to .tflite

I am new to the object detection API and TensorFlow in general. I followed this tutorial and in the end I produced a frozen_inference_graph.pb . I want to run this object detection model on my phone, which in my understanding requires me to convert it to.tflite (please lmk if this doesn't make any sense).

When I tried to convert it using this standard code here:

import tensorflow as tf
graph = 'pathtomygraph'
input_arrays = ['image_tensor']
output_arrays = ['all_class_predictions_with_background']


converter = tf.lite.TFLiteConverter.from_frozen_graph(graph, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

It throws an error, saying:

ValueError: None is only supported in the 1st dimension. Tensor 'image_tensor' has invalid shape '[None, None, None, 3]'

This is a common error I found on the internet, and after searching through many threads, I tried to give an extra parameter to the code:

converter = tf.lite.TFLiteConverter.from_frozen_graph(
        graph, input_arrays, output_arrays,input_shapes={"image_tensor":[1,600,600,3]})

Now it looks like this:

import tensorflow as tf
graph = 'pathtomygraph'
input_arrays = ['image_tensor']
output_arrays = ['all_class_predictions_with_background']


converter = tf.lite.TFLiteConverter.from_frozen_graph(
        graph, input_arrays, output_arrays,input_shapes={"image_tensor":[1,600,600,3]})
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

This works at first, but throws another error at the end, saying:

Check failed: array.data_type == array.final_data_type Array "image_tensor" has mis-matching actual and final data types (data_type=uint8, final_data_type=float). Fatal Error: Aborted

I understand that my input tensor has the data type of uint8 and this causes a mismatch, I guess. My question would be, is this the correct way to approach things? (I want to run my model on my phone). If it is, how do I then fix the error? :/

Thank you very much.

Change your model input (the image_tensor placeholder) to have data type tf.float32 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM