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

时间:2018-06-28 13:56:24

标签: python python-3.x tensorflow pycharm tensorflow-lite

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

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

回溯(最近通话最近):文件
  “ /home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-
  包/tensorflow/python/framework/importer.py”,第489行,在
  import_graph_def          graph._c_graph,序列化,选项)#pylint:disable = protected-access
  tensorflow.python.framework.errors_impl.InvalidArgumentError:输入0   节点的
  import / final_retrain_ops / Wx_plus_b / weights_quant / AssignMinLast原为
  来自
的浮动   import / final_retrain_ops / Wx_plus_b / weights_quant / min:0不兼容
  与预期的float_ref。在处理上述异常期间,   发生了另一个异常:追溯(最近一次呼叫最近):
  文件“ /snap/pycharm-community/64/helpers/pydev/pydevd.py”,行1664,   在          main()文件“ /snap/pycharm-community/64/helpers/pydev/pydevd.py”,行1658,在
  主要          globals = debugger.run(setup ['file'],None,None,is_module)文件“ /snap/pycharm-community/64/helpers/pydev/pydevd.py”,第1068行,   运行中          pydev_imports.execfile(file,globals,locals)#执行脚本File
  “ /snap/pycharm-community/64/helpers/pydev/_pydev_imps/_pydev_execfile.py”,   第18行,在execfile中          exec(compile(contents +“ \ n”,file,'exec'),glob,loc)文件“ /home/automator/PycharmProjects/tensorflow/tfliteme.py”,行389,
  在          printTensors(“ / home / automator / Desktop / cervix / optimized_model.pb”)
  文件“ /home/automator/PycharmProjects/tensorflow/tfliteme.py”,行
  374,在印刷版中          tf.import_graph_def(graph_def)文件“ /home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-
  包/tensorflow/python/util/deprecation.py”,第432行,
  new_func          return func(* args,** kwargs)File“ /home/automator/PycharmProjects/tensorflow/venv/lib/python3.5/site-
  包/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。

1 个答案:

答案 0 :(得分:0)

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

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