Python 找不到输入到ReadVariableOp的变量

Python 找不到输入到ReadVariableOp的变量,python,tensorflow,keras,protocol-buffers,Python,Tensorflow,Keras,Protocol Buffers,正在尝试将包含权重的Keras.h5文件保存到Tensorflow.pb文件 # I keep getting the error: ValueError: Cannot find the variable that is an input to the ReadVariableOp. frozen_graph = freeze_session(K.get_session(), output_names=[out.op.name fo

正在尝试将包含权重的Keras.h5文件保存到Tensorflow.pb文件

# I keep getting the error:  ValueError: Cannot find the variable that is an input to the ReadVariableOp.
frozen_graph = freeze_session(K.get_session(),
                              output_names=[out.op.name for out in model.keras_model.output])
0

冻结的_图=冻结的_会话(K.get_session(),output_names=[out.op.name for out in model.keras_model.output])

我有一个错误:

ValueError回溯(最近一次调用上次)在1个冻结图中= 冻结会话(K.get_session(),--->2个输出名称=[out.op.name for 输出到model.keras_model.output])

在冻结会话(会话、保留变量名称、输出名称、, 清除设备)26 node.device=”“27冻结的设备图= tf.graph_util.convert_variables_to_constants(--->28会话, 输入\图形\定义、输出\名称、冻结\变量\名称)29返回 冻结图

~/anaconda3/envs/env_name/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py 在新函数(*args,**kwargs)322中,如果日期为无,则在未来版本中 else(“%s”%date)之后,323条指令)-->324返回func(*args, **kwargs)325返回tf_decorator.make_decorator(326 func,new_func,'弃用'

~/anaconda3/envs/env\u name/lib/python3.6/site-packages/tensorflow/python/framework/graph\u util\u impl.py 在将变量转换为常量(sess、输入图表定义、, 输出\节点\名称、变量\名称\白名单、变量\名称\黑名单) 300 source\u op\u name=get\u input\u name(映射\u name\u到\u节点[source\u op\u name]) 301如果将\u name\u映射到\u节点[source\u op\u name]。op!=“VarHandleOp”:-->302 raise VALUERROR(“找不到作为输入“303”的变量 ReadVariableOp。”)304

ValueError:找不到作为输入的变量 ReadVariableOp


我刚刚遇到了同样的问题,补充道

将keras.backend导入为K
k、 设置学习阶段(0)

解决方案是将学习阶段设置为测试模式。

我假设
freeze\u session
函数是否已发布?我不确定该错误来自何处…您是否使用TensorFlow 2.x?表明
将变量转换为常量可能无法在2.x中按预期工作。。。