首页 > 解决方案 > FailedPreconditionError: Error while reading resource variable module..在评估张量流预训练模型时

问题描述

我已经通过 inception3 训练了一个二值图像分类器。我能够在创建模型后立即对其进行评估。但是,如果我保存模型并重新加载它,然后尝试评估或预测,那么我会收到以下错误:

FailedPreconditionError: Error while reading resource variable module_16/InceptionV3/Mixed_6d/Branch_2/Conv2d_0c_1x7/BatchNorm/beta from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/module_16/InceptionV3/Mixed_6d/Branch_2/Conv2d_0c_1x7/BatchNorm/beta/N10tensorflow3VarE does not exist.
 [[{{node lambda_2_8/module_16_apply_default/InceptionV3/InceptionV3/Mixed_6d/Branch_2/Conv2d_0c_1x7/BatchNorm/ReadVariableOp}}]]

这是代码片段:

with tf.compat.v1.Session() as sess:
  sess.run(tf.global_variables_initializer())
  #sess.run(tf.local_variables_initializer())
  new_model = tf.keras.models.load_model('mymodel.h5')
  new_model.summary()
  eval_model=new_model.evaluate(image_test, label_test)
  eval_model

配置:tensorflow 1.14.0-rc1,Keras
2.2.4-tf

标签: pythontensorflowkeras

解决方案


推荐阅读