从检查点文件导入数据时,TF-Slim不能排除变量

时间:2017-08-25 09:04:09

标签: tensorflow deep-learning

虽然我排除了检查点文件中不存在的变量,但程序仍然试图在检查点中找到它们。函数

 variables_to_restore = slim.get_variables_to_restore(exclude=exclude_set)

让我很困惑。有人可以帮帮我吗?

     with tf.Graph().as_default():
    tf.logging.set_verbosity(tf.logging.INFO)
    images, labels, bboxs, origin_sizes = read_content_recorder.get_image_batch(voc_dataset_dir, batch_size=50,
                                                                                reshape_size=[image_size, image_size],
                                                                                category_num=20,
                                                                                num_shards=_NUM_SHARDS,
                                                                                category="train")

    image_batch = tf.stack(images, axis=0)
    label_batch = tf.stack(labels, axis=0)

    with slim.arg_scope(vgg.vgg_arg_scope()):
        logits, _ = vgg.vgg_16(image_batch, num_classes=20, is_training=True)

    exclude_set = ['matching_filenames',
                   'vgg_16 / fc6 / weights',
                   'vgg_16 / fc6 / biases',
                   'vgg_16 / fc7 / weights',
                   'vgg_16 / fc7 / biases',
                   'vgg_16 / fc8 / weights',
                   'vgg_16 / fc8 / biases',
                   'vgg_16 / conv1 / conv1_1 / weights / Momentum',
                   'vgg_16 / conv1 / conv1_1 / biases / Momentum',
                   'vgg_16 / conv1 / conv1_2 / weights / Momentum',
                   'vgg_16 / conv1 / conv1_2 / biases / Momentum',
                   'vgg_16 / conv2 / conv2_1 / weights / Momentum',
                   'vgg_16 / conv2 /conv2_1/biases/Momentum',
                   'vgg_16 / conv2 /conv2_2/weights/Momentum',
                   'vgg_16 / conv2 /conv2_2/biases/Momentum',
                   'vgg_16 / conv3 /conv3_1/weights/Momentum',
                   'vgg_16 / conv3 /conv3_1/biases/Momentum',
                   'vgg_16 / conv3 /conv3_2/weights/Momentum',
                   'vgg_16 / conv3 /conv3_2/biases/Momentum',
                   'vgg_16 / conv3 /conv3_3/ weights/Momentum',
                   'vgg_16 / conv3 /conv3_3 / biases/Momentum',
                   'vgg_16 / conv4 /conv4_1 / weights/Momentum',
                   'vgg_16 / conv4 /conv4_1 / biases/Momentum',
                   'vgg_16 / conv4 /conv4_2 / weights/Momentum',
                   'vgg_16 / conv4 /conv4_2 / biases/Momentum',
                   'vgg_16 / conv4 /conv4_3 / weights/Momentum',
                   'vgg_16 / conv4 /conv4_3 / biases/Momentum',
                   'vgg_16 / conv5 /conv5_1 / weights/Momentum',
                   'vgg_16 / conv5 /conv5_1 / biases/Momentum',
                   'vgg_16 / conv5 /conv5_2 / weights/Momentum',
                   'vgg_16 / conv5 /conv5_2 / biases/Momentum',
                   'vgg_16 / conv5 /conv5_3 / weights/Momentum',
                   'vgg_16 / conv5 /conv5_3 / biases/Momentum',
                   'vgg_16 / fc6 /weights / Momentum',
                   'vgg_16 / fc6 /biases / Momentum',
                   'vgg_16 / fc7 /weights / Momentum',
                   'vgg_16 / fc7 /biases / Momentum',
                   'vgg_16 / fc8 /weights / Momentum',
                   'vgg_16 / fc8 /biases / Momentum']

    variables_to_restore = slim.get_variables_to_restore(exclude=exclude_set)

    for e in variables_to_restore:
        print e.name
    # variables_to_restore print result:
    # vgg_16 / conv1 / conv1_1 / weights:0
    # vgg_16 / conv1 / conv1_1 / biases:0
    # vgg_16 / conv1 / conv1_2 / weights:0
    # vgg_16 / conv1 / conv1_2 / biases:0
    # vgg_16 / conv2 / conv2_1 / weights:0
    # vgg_16 / conv2 / conv2_1 / biases:0
    # vgg_16 / conv2 / conv2_2 / weights:0
    # vgg_16 / conv2 / conv2_2 / biases:0
    # vgg_16 / conv3 / conv3_1 / weights:0
    # vgg_16 / conv3 / conv3_1 / biases:0
    # vgg_16 / conv3 / conv3_2 / weights:0
    # vgg_16 / conv3 / conv3_2 / biases:0
    # vgg_16 / conv3 / conv3_3 / weights:0
    # vgg_16 / conv3 / conv3_3 / biases:0
    # vgg_16 / conv4 / conv4_1 / weights:0
    # vgg_16 / conv4 / conv4_1 / biases:0
    # vgg_16 / conv4 / conv4_2 / weights:0
    # vgg_16 / conv4 / conv4_2 / biases:0
    # vgg_16 / conv4 / conv4_3 / weights:0
    # vgg_16 / conv4 / conv4_3 / biases:0
    # vgg_16 / conv5 / conv5_1 / weights:0
    # vgg_16 / conv5 / conv5_1 / biases:0
    # vgg_16 / conv5 / conv5_2 / weights:0
    # vgg_16 / conv5 / conv5_2 / biases:0
    # vgg_16 / conv5 / conv5_3 / weights:0
    # vgg_16 / conv5 / conv5_3 / biases:0
    # vgg_16 / fc6 / weights:0
    # vgg_16 / fc6 / biases:0
    # vgg_16 / fc7 / weights:0
    # vgg_16 / fc7 / biases:0
    # vgg_16 / fc8 / weights:0
    # vgg_16 / fc8 / biases:0

    global_step = slim.model_variable('global_step', initializer=tf.constant(0), dtype=tf.int32)
    learning_rate = slim.train.exponential_decay(0.01, global_step, 10000, 0.1, staircase=True)

    predictions = tf.nn.softmax(logits)
    loss = slim.losses.softmax_cross_entropy(predictions, label_batch)

    total_loss = slim.losses.get_total_loss()
    tf.summary.scalar('losses/Total Loss', total_loss)

    optimizer = slim.train.MomentumOptimizer(learning_rate=learning_rate,momentum=0.9)
    train_op = slim.learning.create_train_op(total_loss, optimizer)

    pretrained_model_path = "./pretrained/vgg_16.ckpt"
    #pretrained model parameters:
    #inspect_checkpoint.print_tensors_in_checkpoint_file(pretrained_model_path, '', False)


    # print "my variables"
    # for e in slim.get_variables():
    #     print e.name

    # matching_filenames:0
    # vgg_16 / conv1 / conv1_1 / weights:0
    # vgg_16 / conv1 / conv1_1 / biases:0
    # vgg_16 / conv1 / conv1_2 / weights:0
    # vgg_16 / conv1 / conv1_2 / biases:0
    # vgg_16 / conv2 / conv2_1 / weights:0
    # vgg_16 / conv2 / conv2_1 / biases:0
    # vgg_16 / conv2 / conv2_2 / weights:0
    # vgg_16 / conv2 / conv2_2 / biases:0
    # vgg_16 / conv3 / conv3_1 / weights:0
    # vgg_16 / conv3 / conv3_1 / biases:0
    # vgg_16 / conv3 / conv3_2 / weights:0
    # vgg_16 / conv3 / conv3_2 / biases:0
    # vgg_16 / conv3 / conv3_3 / weights:0
    # vgg_16 / conv3 / conv3_3 / biases:0
    # vgg_16 / conv4 / conv4_1 / weights:0
    # vgg_16 / conv4 / conv4_1 / biases:0
    # vgg_16 / conv4 / conv4_2 / weights:0
    # vgg_16 / conv4 / conv4_2 / biases:0
    # vgg_16 / conv4 / conv4_3 / weights:0
    # vgg_16 / conv4 / conv4_3 / biases:0
    # vgg_16 / conv5 / conv5_1 / weights:0
    # vgg_16 / conv5 / conv5_1 / biases:0
    # vgg_16 / conv5 / conv5_2 / weights:0
    # vgg_16 / conv5 / conv5_2 / biases:0
    # vgg_16 / conv5 / conv5_3 / weights:0
    # vgg_16 / conv5 / conv5_3 / biases:0
    # vgg_16 / fc6 / weights:0
    # vgg_16 / fc6 / biases:0
    # vgg_16 / fc7 / weights:0
    # vgg_16 / fc7 / biases:0
    # vgg_16 / fc8 / weights:0
    # vgg_16 / fc8 / biases:0
    # global_step:0
    # vgg_16 / conv1 / conv1_1 / weights / Momentum:0
    # vgg_16 / conv1 / conv1_1 / biases / Momentum:0
    # vgg_16 / conv1 / conv1_2 / weights / Momentum:0
    # vgg_16 / conv1 / conv1_2 / biases / Momentum:0
    # vgg_16 / conv2 / conv2_1 / weights / Momentum:0
    # vgg_16 / conv2 / conv2_1 / biases / Momentum:0
    # vgg_16 / conv2 / conv2_2 / weights / Momentum:0
    # vgg_16 / conv2 / conv2_2 / biases / Momentum:0
    # vgg_16 / conv3 / conv3_1 / weights / Momentum:0
    # vgg_16 / conv3 / conv3_1 / biases / Momentum:0
    # vgg_16 / conv3 / conv3_2 / weights / Momentum:0
    # vgg_16 / conv3 / conv3_2 / biases / Momentum:0
    # vgg_16 / conv3 / conv3_3 / weights / Momentum:0
    # vgg_16 / conv3 / conv3_3 / biases / Momentum:0
    # vgg_16 / conv4 / conv4_1 / weights / Momentum:0
    # vgg_16 / conv4 / conv4_1 / biases / Momentum:0
    # vgg_16 / conv4 / conv4_2 / weights / Momentum:0
    # vgg_16 / conv4 / conv4_2 / biases / Momentum:0
    # vgg_16 / conv4 / conv4_3 / weights / Momentum:0
    # vgg_16 / conv4 / conv4_3 / biases / Momentum:0
    # vgg_16 / conv5 / conv5_1 / weights / Momentum:0
    # vgg_16 / conv5 / conv5_1 / biases / Momentum:0
    # vgg_16 / conv5 / conv5_2 / weights / Momentum:0
    # vgg_16 / conv5 / conv5_2 / biases / Momentum:0
    # vgg_16 / conv5 / conv5_3 / weights / Momentum:0
    # vgg_16 / conv5 / conv5_3 / biases / Momentum:0
    # vgg_16 / fc6 / weights / Momentum:0
    # vgg_16 / fc6 / biases / Momentum:0
    # vgg_16 / fc7 / weights / Momentum:0
    # vgg_16 / fc7 / biases / Momentum:0
    # vgg_16 / fc8 / weights / Momentum:0
    # vgg_16 / fc8 / biases / Momentum:0


    #init_fn = slim.assign_from_checkpoint_fn(pretrained_model_path, variables_to_restore)
    saver = tf.train.Saver(variables_to_restore)
    def init_fn(sess):
        saver.restore(sess)

    #saver = tf.train.Saver(variables_to_restore)

    final_loss = slim.learning.train(
        train_op,
        global_step=global_step,
        init_fn=init_fn,
        logdir=train_log_dir,  # model checkpoints and summaries be written here
        saver = saver,#
        number_of_steps=370000  # training steps
    )

运行信息如下,它显示程序无法找到Momentum节点,而我在我的代码中将它们排除。我试图制作保护程序,但似乎无关

TFRecord files did exist!Go to next stage....

Instructions for updating:
Use tf.losses.get_regularization_losses instead.
INFO:tensorflow:Summary name losses/Total Loss is illegal; using losses/Total_Loss instead.
['matching_filenames', 'vgg_16/fc6/weights', 'vgg_16/fc6/biases', 'vgg_16/fc7/weights', 'vgg_16/fc7/biases', 'vgg_16/fc8/weights', 'vgg_16/fc8/biases', 'vgg_16/conv1/conv1_1/weights/Momentum', 'vgg_16/conv1/conv1_1/biases/Momentum', 'vgg_16/conv1/conv1_2/weights/Momentum', 'vgg_16/conv1/conv1_2/biases/Momentum', 'vgg_16/conv2/conv2_1/weights/Momentum', 'vgg_16/conv2/conv2_1/biases/Momentum', 'vgg_16/conv2/conv2_2/weights/Momentum', 'vgg_16/conv2/conv2_2/biases/Momentum', 'vgg_16/conv3/conv3_1/weights/Momentum', 'vgg_16/conv3/conv3_1/biases/Momentum', 'vgg_16/conv3/conv3_2/weights/Momentum', 'vgg_16/conv3/conv3_2/biases/Momentum', 'vgg_16/conv3/conv3_3/weights/Momentum', 'vgg_16/conv3/conv3_3/biases/Momentum', 'vgg_16/conv4/conv4_1/weights/Momentum', 'vgg_16/conv4/conv4_1/biases/Momentum', 'vgg_16/conv4/conv4_2/weights/Momentum', 'vgg_16/conv4/conv4_2/biases/Momentum', 'vgg_16/conv4/conv4_3/weights/Momentum', 'vgg_16/conv4/conv4_3/biases/Momentum', 'vgg_16/conv5/conv5_1/weights/Momentum', 'vgg_16/conv5/conv5_1/biases/Momentum', 'vgg_16/conv5/conv5_2/weights/Momentum', 'vgg_16/conv5/conv5_2/biases/Momentum', 'vgg_16/conv5/conv5_3/weights/Momentum', 'vgg_16/conv5/conv5_3/biases/Momentum', 'vgg_16/fc6/weights/Momentum', 'vgg_16/fc6/biases/Momentum', 'vgg_16/fc7/weights/Momentum', 'vgg_16/fc7/biases/Momentum', 'vgg_16/fc8/weights/Momentum', 'vgg_16/fc8/biases/Momentum']
27
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: GeForce GTX 960M
major: 5 minor: 0 memoryClockRate (GHz) 1.176
pciBusID 0000:01:00.0
Total memory: 3.95GiB
Free memory: 3.52GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0)
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv3/conv3_3/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/fc8/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_2/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_2/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv2/conv2_1/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv4/conv4_1/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv2/conv2_1/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv2/conv2_2/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv4/conv4_1/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/fc8/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv4/conv4_2/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv2/conv2_2/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv4/conv4_3/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv5/conv5_2/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv5/conv5_1/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv5/conv5_1/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv5/conv5_3/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv5/conv5_2/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv5/conv5_3/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/fc6/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/fc6/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/fc7/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/fc7/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv3/conv3_1/biases/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv3/conv3_1/weights/Momentum not found in checkpoint
W tensorflow/core/framework/op_kernel.cc:993] Not found: Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/Restore_device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.NotFoundError'>, Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
     [[Node: save_1/RestoreV2_57/_11 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_211_save_1/RestoreV2_57", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

Caused by op u'save_1/RestoreV2_5', defined at:
  File "/home/wuzheng/PycharmProjects/localization/test2.py", line 133, in <module>
    number_of_steps=370000  # training steps
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/slim/python/slim/learning.py", line 688, in train
    saver = saver or tf_saver.Saver()
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1040, in __init__
    self.build()
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1070, in build
    restore_sequentially=self._restore_sequentially)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 675, in build
    restore_sequentially, reshape)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 402, in _AddRestoreOps
    tensors = self.restore_op(filename_tensor, saveable, preferred_shard)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 242, in restore_op
    [spec.tensor.dtype])[0])
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_io_ops.py", line 668, in restore_v2
    dtypes=dtypes, name=name)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2327, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1226, in __init__
    self._traceback = _extract_stack()

NotFoundError (see above for traceback): Key vgg_16/conv1/conv1_1/weights/Momentum not found in checkpoint
     [[Node: save_1/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save_1/Const_0, save_1/RestoreV2_5/tensor_names, save_1/RestoreV2_5/shape_and_slices)]]
     [[Node: save_1/RestoreV2_57/_11 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_211_save_1/RestoreV2_57", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

Traceback (most recent call last):
  File "/home/wuzheng/PycharmProjects/localization/test2.py", line 133, in <module>
    number_of_steps=370000  # training steps
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/slim/python/slim/learning.py", line 776, in train
    master, start_standard_services=False, config=session_config) as sess:
  File "/home/wuzheng/anaconda2/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/supervisor.py", line 960, in managed_session
    self.stop(close_summary_writer=close_summary_writer)
  File "/home/wuzheng/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/supervisor.py", line 788, in stop
    stop_grace_period_secs=self._stop_grace_secs)

Process finished with exit code 1

1 个答案:

答案 0 :(得分:0)

在定义网络之后(以及在向图表添加任何其他变量之前)立即移动排除集的计算。这样,恢复的变量列表将与检查点匹配,您不必费心手动排除您定义的每个新变量(例如您的Momentum):

with slim.arg_scope(vgg.vgg_arg_scope()):
    logits, _ = vgg.vgg_16(image_batch, num_classes=20, is_training=True)
exclude_set = ['MyVariableToExclude', 'MyOtherVarialeToExclude']
variables_to_restore = slim.get_variables_to_restore(exclude = exclude_set)

[optimizer definition and stuff]

saver = tf.train.Saver(variables_to_restore)

[in your session]

saver.restore(sess, checkpoint_file)

更新

而不是init_fn = slim.assign_from_checkpoint_fn(pretrained_model_path, variables_to_restore)试试这个:

saver = tf.train.Saver(variables_to_restore)
def init_fn(sess):
    saver.restore(sess)

并将您的调用更改为slim.learning.train(请注意,您对该函数的调用没有实际差异,但init_fn参数现在是我们上面定义的函数):

final_loss = slim.learning.train(
        train_op,
        global_step=global_step,
        init_fn=init_fn,
        logdir=train_log_dir,
        number_of_steps=370000  # training steps
    )