ValueError:节点的输入0与预期的float_ref不兼容**

2024-05-16 22:24:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试导入优化的冻结图时遇到以下异常。在

# read pb into graph_def
with tf.gfile.GFile(pb_file, "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

# import graph_def
with tf.Graph().as_default() as graph:
    tf.import_graph_def(graph_def)

获取以下行中的异常:

^{pr2}$

Traceback (most recent call last): File
"/home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-
packages/tensorflow/python/framework/importer.py", line 489, in
import_graph_def graph._c_graph, serialized, options) # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input 0 of node
import/final_retrain_ops/Wx_plus_b/weights_quant/AssignMinLast was
passed float from
import/final_retrain_ops/Wx_plus_b/weights_quant/min:0 incompatible
with expected float_ref. During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "/snap/pycharm-community/64/helpers/pydev/pydevd.py", line 1664, in main() File "/snap/pycharm-community/64/helpers/pydev/pydevd.py", line 1658, in
main globals = debugger.run(setup['file'], None, None, is_module) File "/snap/pycharm-community/64/helpers/pydev/pydevd.py", line 1068, in run pydev_imports.execfile(file, globals, locals) # execute the script File
"/snap/pycharm-community/64/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/home/automator/PycharmProjects/tensorflow/tfliteme.py", line 389,
in printTensors("/home/automator/Desktop/cervix/optimized_model.pb")
File "/home/automator/PycharmProjects/tensorflow/tfliteme.py", line
374, in printTensors tf.import_graph_def(graph_def) File "/home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-
packages/tensorflow/python/util/deprecation.py", line 432, in
new_func return func(*args, **kwargs) File "/home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-
packages/tensorflow/python/framework/importer.py", line 493, in
import_graph_def raise ValueError(str(e)) ValueError: Input 0 of node import/final_retrain_ops/Wx_plus_b/weights_quant/AssignMinLast was
passed float from
import/final_retrain_ops/Wx_plus_b/weights_quant/min:0 incompatible
with

应为float_ref


Tags: inpyimporthometftensorflowdefwith
1条回答
网友
1楼 · 发布于 2024-05-16 22:24:31

请确保您的pb_file格式正确(类似于this),并尝试在import_graph_def()的“name”参数中设置一些值,以尝试覆盖“import”默认值,如下所示:

# read pb into graph_def
with tf.gfile.GFile(pb_file, "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

# import graph_def
with tf.Graph().as_default() as graph:
    tf.import_graph_def(graph_def, name='') 

相关问题 更多 >