从检查点还原失败-TensorFlow

时间:2019-04-28 21:10:32

标签: python tensorflow tensorflow-datasets

我有一个名为cnn-bn-relu的函数,该函数执行一系列卷积-批处理-归一化-Relu并返回输出。 通过上述功能获得训练有素的模型,我试图不仅使用测试图像而且还使用其增强副本来测试模型

第1步。将原始图像输入到函数cnn-bn-relu

test_reconstructed_image_1_output=cnn-bn-relu(test_image_1,weights_layer_1,weights_layer_2,weights_layer_3,weights_layer_4)

第2步。接下来,将其扩展副本传递给函数cnn-bn-relu

test_reconstructed_aug_image_1_output=cnn-bn-relu(test_aug_image_1,weights_layer_1,weights_layer_2,weights_layer_3,weights_layer_4)

经过上述两个步骤,我恢复了训练后的模型权重,并尝试获取步骤1和步骤2的输出。但是,出现以下错误

  

NotFoundError(请参阅上面的回溯):从检查点还原   失败了这很可能是由于变量名或其他图形键   检查点缺少的内容。请确保您没有   根据检查点更改了期望的图形。原始错误:

我发现计算图像的增强副本与原始图像的卷积会导致上述错误,但是我不知道如何解决。

下面是我使用的代码。

Step 1:
Reading the images from tensorflow record using dataset api
test_dataset = (tf.data.TFRecordDataset(test_tfrecords_filename_label)
      .map(read_and_decode,num_parallel_calls=multiprocessing.cpu_count())
      .prefetch(1))
iterator = test_dataset.make_one_shot_iterator()
test_image_1,aug_test_image_1= iterator.get_next()

Step 2:
# Calculating convolution for original image
test_reconstructed_image_1_output=cnn-bn-relu(test_image_1,weights_layer_1,weights_layer_2,weights_layer_3,weights_layer_4)
# Calculating convolution for augmented copy of original image
test_reconstructed_aug_image_1_output=cnn-bn-relu(test_patches_image_1,weights_layer_1,weights_layer_2,weights_layer_3,weights_layer_4)

Step 3:restoring the model and running the tensorflow session
saver1 = tf.train.Saver()
sess1 = tf.Session()
saver1.restore(sess1,  "model.ckpt")
for i in range(0,3):
   output_1,output_2 = sess1.run( test_reconstructed_image_1_output,test_reconstructed_aug_image_1)

上面的代码会产生上述错误。

If i comment the line
test_reconstructed_aug_image_1_output=cnn-bn- relu(test_patches_image_1,weights_layer_1,weights_layer_2,weights_layer_3,weights_layer_4)

and replace 
for i in range(0,3):
       output_1,output_2 = sess1.run( 
test_reconstructed_image_1_output,test_reconstructed_aug_image_1)

with
for i in range(0,3):
       output_1= sess1.run( test_reconstructed_image_1_output)

我没有收到错误消息。

谁能指导我如何修改代码以同时获得output_1和output_2

0 个答案:

没有答案