tensorflow: TF2.3 converter.convert ValueError: Input 0 of node StatefulPartitionedCall/functional_1/resnet50/conv1_bn/AssignNewValue was passed float from Func/StatefulPartitionedCall/input/_5:0 incompatible with expected resource.

System information

  • OS Platform and Distribution (Ubuntu 18.04, cuda 10.1):
  • TensorFlow installed from (binary):
  • TensorFlow version (TF 2.3):

Here is the part of my code.

       export_path './test_model'
        tf.saved_model.save(model, export_path)
        converter = tf.lite.TFLiteConverter.from_saved_model(export_path)
        converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
        tflite_model = converter.convert()
        open("./converted_model.tflite", "wb").write(tflite_model)

Here is my model summary, which is a typical image classification model using pre_trained ResNet50 model for transfer-learning.

Model: "functional_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_2 (InputLayer)         [(None, 160, 160, 3)]     0         
_________________________________________________________________
sequential (Sequential)      (None, 160, 160, 3)       0         
_________________________________________________________________
tf_op_layer_RealDiv (TensorF [(None, 160, 160, 3)]     0         
_________________________________________________________________
tf_op_layer_Sub (TensorFlowO [(None, 160, 160, 3)]     0         
_________________________________________________________________
resnet50 (Functional)        (None, 5, 5, 2048)        23587712  
_________________________________________________________________
global_average_pooling2d (Gl (None, 2048)              0         
_________________________________________________________________
dropout (Dropout)            (None, 2048)              0         
_________________________________________________________________
dense (Dense)                (None, 3)                 6147      
=================================================================
Total params: 23,593,859
Trainable params: 23,540,739
Non-trainable params: 53,120
_________________________________________________________________

Here is the failure errors.

Traceback (most recent call last):
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/framework/importer.py", line 497, in _import_graph_def_internal
    graph._c_graph, serialized, options)  # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input 0 of node StatefulPartitionedCall/functional_1/resnet50/conv1_bn/AssignNewValue was passed float from Func/StatefulPartitionedCall/input/_5:0 incompatible with expected resource.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "main.py", line 321, in <module>
    main(train='lite')
  File "main.py", line 210, in main
    tflite_model = converter.convert()
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/lite/python/lite.py", line 1076, in convert
    return super(TFLiteConverterV2, self).convert()
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/lite/python/lite.py", line 878, in convert
    self._funcs[0], lower_control_flow=False))
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 1109, in convert_variables_to_constants_v2_as_graph
    converted_input_indices)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/framework/convert_to_constants.py", line 1001, in _construct_concrete_function
    new_output_names)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/eager/wrap_function.py", line 650, in function_from_graph_def
    wrapped_import = wrap_function(_imports_graph_def, [])
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/eager/wrap_function.py", line 628, in wrap_function
    collections={}),
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/eager/wrap_function.py", line 87, in __call__
    return self.call_with_variable_creator_scope(self._fn)(*args, **kwargs)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/eager/wrap_function.py", line 93, in wrapped
    return fn(*args, **kwargs)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/eager/wrap_function.py", line 648, in _imports_graph_def
    importer.import_graph_def(graph_def, name="")
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/framework/importer.py", line 405, in import_graph_def
    producer_op_list=producer_op_list)
  File "/home/ktatc/anaconda3/envs/HHproject/lib/python3.7/site-packages/tensorflow/python/framework/importer.py", line 501, in _import_graph_def_internal
    raise ValueError(str(e))
**ValueError: Input 0 of node StatefulPartitionedCall/functional_1/resnet50/conv1_bn/AssignNewValue was passed float from Func/StatefulPartitionedCall/input/_5:0 incompatible with expected resource.**

How can i solve it? I don’t know the reason why these kind of error happen. please let me know in detail. Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 32 (11 by maintainers)

Most upvoted comments

can someone please convert the model to tflite and send me it would be a great help this is the model file -https://drive.google.com/drive/folders/1-1jAHa_N2YoA28sLCa2a0xJFkEfJu4Td?usp=sharing

Hi All,

I have the same issues when I convert saved model to onnx model by below command:

python3 -m tf2onnx.convert --saved-model . --output tf2-preview_inception_v3_classification_4.onnx --concrete_function 0

Error log:

ValueError: Input 0 of node StatefulPartitionedCall/StatefulPartitionedCall/train/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/AssignMovingAvg_1/AssignSubVariableOp was passed float from Func/StatefulPartitionedCall/StatefulPartitionedCall/input/_410:0 incompatible with expected resource.

My detail issue #1152 if there are anyone know this issue, please help me.

d7 = BatchNormalization()(in_image, training=True)

Why are you specifying that argument, though? Based on where and how your model is being used this layer can adapt its behavior. This Keras guide sheds some more details on it.