Skip to content

tf2onnx convert pb (create by tf2.8 estimator) traceback #2387

Open
@momodagithub

Description

@momodagithub

Describe the bug
i want to use tensorrt to accelarate my model ,so i need to convert pb to oNNX,
first i use tensorflow 1.13.2 and estimator api to save pb
but my model is larger than 2G, it seems that tf2onnx not support --large_model
so i change the code in tensorflow 2.8
i also save model with estimator api

but when i convert the pb to onnx by command:
python -m tf2onnx.convert --saved-model ./export_model/1741318171 --output model.onnx --large_model

i got
function_optimizer: function_optimizer did nothing. time = 0.002ms.
Optimization results for grappler item: __inference_batch_normalization_1_cond_1_true_5630_491
function_optimizer: function_optimizer did nothing. time = 0.002ms.
function_optimizer: function_optimizer did nothing. time = 0.001ms.

2025-03-07 11:38:10,820 - INFO - Using tensorflow=2.8.0, onnx=1.12.0, tf2onnx=1.10.1/a37f29
2025-03-07 11:38:10,820 - INFO - Using opset <onnx, 9>
2025-03-07 11:38:10,965 - WARNING - Removing optional input keras_learning_phase that appears to be a keras learning phase parameter. Use --ignore_default to force this into an input.
2025-03-07 11:38:11,061 - WARNING - shape missmatch between caller and function: __inference_batch_normalization_6_cond_false_7047_frozen_4698
Traceback (most recent call last):
File "/data/software/app/anaconda3/envs/py39/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 772, in resolve_functions
func = function_def_to_graph(fdef, input_shapes=input_shapes)
File "/data/software/app/anaconda3/envs/py39/lib/python3.9/site-packages/tensorflow/python/framework/function_def_to_graph.py", line 88, in function_def_to_graph
output_tensor_names = [
File "/data/software/app/anaconda3/envs/py39/lib/python3.9/site-packages/tensorflow/python/framework/function_def_to_graph.py", line 89, in
nested_to_flat_tensor_name[fdef.ret[arg.name]]
KeyError: 'ReadVariableOp:value:0'

i do not know why ,but it seems that ReadVariableOp:value:0 is tf1 op?

System information

  • centos 7
  • TensorFlow Version:2.8
  • Python version:3.9
  • ONNX version1.12.0
    -tf2onnx version 1.11.1

To Reproduce
the code i use
actor_like_emb = fc.numeric_column(
'actor_like_emb',
shape=[1024],
default_value=[0.0 for i in range(1024)],
dtype=tf.float32
)
params["img_feature_columns"]=["actor_like_emb"]
img_feature = tf.keras.layers.DenseFeatures(list(params["img_feature_columns"].values()))(features)

the loss part is
update_ops = tf.compat.v1.get_collection(tf.compat.v1.GraphKeys.UPDATE_OPS) # 获取批量归一化的更新操作
optimizer = tf.compat.v1.train.ProximalAdagradOptimizer(
learning_rate=params["learning_rate"],
l2_regularization_strength=params["l2_reg"],
)
with tf.control_dependencies(update_ops):
train_op = optimizer.minimize(loss, global_step=tf.compat.v1.train.get_global_step())

i use keras api and feature_column and compat.v1

really need help and suggestion

really thx

Screenshots

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions