Open TobyHuang328 opened 3 years ago
Link 1 helped me a little bit, but at the end of the day, I am still stuck. Here is my situation, I have trained and exported a mobilenet model using exporter_main_v2.py, and right now I am playing around with convert_tflite and export_tflite_ssd_graph.py. I do not know if my model is frozen or quantized or something else. Sorry I am quite a beginner in object detection
Prerequisites
Please answer the following questions for yourself before submitting an issue.
1. The entire URL of the file you are using
https://github.com/tensorflow/models/tree/master/research/...
2. Describe the bug
I have a simple a script of python code to convert a .pb file into a .tflite file. But I was unable to convert the model and the error says.
Traceback (most recent call last): File "C:\Users\godlo\Documents\Tensorflow-FreightFrenzy\scripts\pythonProject\main.py", line 7, in
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\lite\python\lite.py", line 1348, in from_saved_model
saved_model = _load(saved_model_dir, tags)
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\saved_model\load.py", line 864, in load
result = load_internal(export_dir, tags, options)["root"]
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\saved_model\load.py", line 902, in load_internal
loader = loader_cls(object_graph_proto, saved_model_proto, export_dir,
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\saved_model\load.py", line 165, in init
self._restore_checkpoint()
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\saved_model\load.py", line 476, in _restore_checkpoint
load_status = saver.restore(variables_path, self._checkpoint_options)
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\tracking\util.py", line 1382, in restore
base.CheckpointPosition(
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\tracking\base.py", line 254, in restore
restore_ops = trackable._restore_from_checkpoint_position(self) # pylint: disable=protected-access
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\tracking\base.py", line 980, in _restore_from_checkpoint_position
current_position.checkpoint.restore_saveables(
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\tracking\util.py", line 351, in restore_saveables
new_restore_ops = functional_saver.MultiDeviceSaver(
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\saving\functional_saver.py", line 339, in restore
restore_ops = restore_fn()
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\saving\functional_saver.py", line 323, in restore_fn
restore_ops.update(saver.restore(file_prefix, options))
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\saving\functional_saver.py", line 115, in restore
restore_ops[saveable.name] = saveable.restore(
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\training\saving\saveable_object_util.py", line 131, in restore
return resource_variable_ops.shape_safe_assign_variable_handle(
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 309, in shape_safe_assign_variable_handle
shape.assert_is_compatible_with(value_tensor.shape)
File "C:\Users\godlo\anaconda3\envs\pythonProject\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 1161, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (1, 1, 576, 6) and (1, 1, 576, 273) are incompatible
3. Steps to reproduce
create and export a .pb file with mobilenet (I use batch size 2), I run the code below, and then the error above is what I got import tensorflow as tf print(tf.version.VERSION) from h5py._hl import dataset
saved_model_dir = "C:\Users\godlo\Documents\Tensorflow-FreightFrenzy\workspace\training_demo\exported-models\mobilenet_model\saved_model"
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
Convert
converter.target_spec.supported_ops = [ tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops. tf.lite.OpsSet.SELECT_TF_OPS, # enable TensorFlow ops. ]
tflite_model = converter.convert()
open('mobilenet_model.tflite', 'wb').write(tflite_model)
4. Expected behavior
I should get a .tflite file in my python folder with the name mobilnet_model.tflite
5. Additional context
It somehow works with some other models I have exported, such as resnet models. Just not the mobilenet model for some reason.
6. System information