tensorflow / tensorflow/models
raise ValueError("Shapes %s and %s are incompatible" % (self, other)) ValueError: Shapes (1, 1, 576, 6) and (1, 1, 576, 273) are incompatible
@pkulzc is already working on this.
Since Nov 15, 2021.
- Dominant language
- Python
- Stars
- 77.7k
- Forks
- 44.8k
- PR merge metrics
- No merged PRs in 30d
Description
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- I am using the latest TensorFlow Model Garden release and TensorFlow 2.
- I am reporting the issue to the correct repository. (Model Garden official or research directory)
- I checked to make sure that this issue has not already been filed.
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
- OS Platform and Distribution: Windows 10
- TensorFlow installed from (source or binary): pip install tensorflow
- TensorFlow version (use command below): 2.6.0
- Python version: 3.9.7
- CUDA/cuDNN version: Build cuda_11.2.r11.2/compiler.29618528_0
- GPU model and memory: NVIDIA GeForce MX250 and 16GB of memory
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.