8

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

# 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(最近一次调用最后):文件
“/home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-packages/tensorflow/python/framework/importer.py
”,第 489 行,在
import_graph_def graph._c_graph , 序列化, 选项) # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input 0 of node
import/final_retrain_ops/Wx_plus_b/weights_quant/AssignMinLast 是

import/final_retrain_ops/Wx_plus_b/weights_quant/min 传递的浮点数: 0
与预期的 float_ref 不兼容。在处理上述异常的过程中,又出现了一个异常:Traceback(最近一次调用last):
文件“/snap/pycharm-community/64/helpers/pydev/pydevd.py”,第 1664 行,在 main() 文件“/snap/pycharm-community/64/helpers/pydev/pydevd.py”,第 1658 行,在
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) # 执行脚本 File
"/snap/pycharm-community/64/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, ' exec'), glob, loc) 文件“/home/automator/PycharmProjects/tensorflow/tfliteme.py”,第 389 行,
在 printTensors("/home/automator/Desktop/cervix/optimized_model.铅")
文件“/home/automator/PycharmProjects/tensorflow/tfliteme.py”,第
374 行,在 printTensors tf.import_graph_def(graph_def) 文件“
/home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-packages/ tensorflow/python/util/deprecation.py”,第 432 行,在
new_func 返回 func(*args, **kwargs) 文件“
/home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-packages/tensorflow /python/framework/importer.py",第 493 行,在
import_graph_def 中引发 ValueError(str(e)) ValueError:节点 import/final_retrain_ops/Wx_plus_b/weights_quant/AssignMinLast 的输入 0 从 import/final_retrain_ops/Wx_plus_b/weights_quant/ 传入
浮点数
min:0 不
兼容

预期的 float_ref。

4

1 回答 1

2

确保您pb_file的格式正确(类似这样),并尝试在 'name' 参数中设置一些值import_graph_def()以尝试覆盖“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='') 
于 2019-01-21T11:42:47.220 回答