【发布时间】:2019-09-12 17:06:00
【问题描述】:
我正在尝试在 tf 会话中的计算流程图的某处使用我预先训练的 keras 模型,所以我尝试了这个简化的图表,但仍然遇到相同的错误。
model = load_model('models/vtcnn3.h5')
input = tf.placeholder(tf.float32,shape=(1,*x_test.shape[1:]))
output = model(input)
sess = tf.compat.v1.Session()
guess_0 = sess.run(output, {input:x_test[0:1]} )
当会话运行时,我会得到一个很大的回溯,最终会说
tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable dense2/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/dense2/kernel)
[[node sequential/dense2/MatMul/ReadVariableOp (defined at code/soq.py:114) ]]
Errors may have originated from an input operation.
Input Source operations connected to node sequential/dense2/MatMul/ReadVariableOp:
dense2/kernel (defined at code/soq.py:111)
Original stack trace for 'sequential/dense2/MatMul/ReadVariableOp':
File "code/soq.py", line 114, in <module>
output = model(input)
File "/Users/yaba/miniconda3/envs/cs1/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 634, in __call__
outputs = call_fn(inputs, *args, **kwargs)
.
.
.
.
dense2 是我模型中层的名称。当我对流程图进行其他更改时,回溯会将错误放入模型的不同层。
【问题讨论】:
标签: python tensorflow keras tf.keras