从检查点文件导入数据时,TF-Slim无法排除变量 [英] TF-Slim can't exclude variables when import data from checkpoint files
问题描述
尽管我排除了检查点文件中不存在的变量,但是程序仍然尝试在检查点中找到它们。func
Though i exclude variables that don't exist in the checkpoint file,the program still try to find them in the checkpoint.The func
variables_to_restore = slim.get_variables_to_restore(exclude=exclude_set)
确实让我感到困惑。有人可以帮我吗?
is really confusing me. Anyone can help me?
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节点。我尝试制作保护程序,但似乎无关。
Run info is below,it shows the program can't find the Momentum nodes while i exclude them in my code.I try to make saver but it seems unrelated
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
推荐答案
在定义网络之后(以及在向图中添加任何其他变量之前)立即移动排除集的计算。这样,还原的变量列表将与检查点匹配,并且您不必手动排除已定义的每个新变量(例如Momentum):
Move the computation of the exclude set right after you define the network (and before you add any other variable to your graph). That way, the list of variables restored will match the checkpoint and you won't have to bother manually excluding every new variable you defined (for example your 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
参数现在是我们上面定义的函数):
and change your call to slim.learning.train
as such (note that there is no actual difference from your call to the function, but the init_fn
parameter is now the function we defined above):
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
)
这篇关于从检查点文件导入数据时,TF-Slim无法排除变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!