ValueError: Input 0 of node incompatible with expected float_ref.**

ValueError: Input 0 of node incompatible with expected float_ref.**

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

# 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)

获取此行的异常:

tf.import_graph_def(graph_def)

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。

确保您的 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='')