1. 程式人生 > >問題記錄:恢復某些層引數,遇到NotFoundError: Key conv2d_168/bias not found in checkpoint

問題記錄:恢復某些層引數,遇到NotFoundError: Key conv2d_168/bias not found in checkpoint

問題描述:對網路結構做了些修改,匯入已訓練的引數,出現NotFoundError

相關程式:

#State where your log file is at.
log_dir = './log2'

#State where your checkpoint file is 
checkpoint_file = './log/model.ckpt-300068'

#Define the scopes that you want to exclude for restoration
exclude = ['conv_0','conv_1','conv_2']
variables_to_restore = slim.get_variables_to_restore(exclude=exclude)

#Now we create a saver function that actually restores the variables from a checkpoint file in a sess
saver = tf.train.Saver(variables_to_restore)
def restore_fn(sess):
	return saver.restore(sess,checkpoint_file)
sv = tf.train.Supervisor(logdir = log_dir,summary_op = None, init_fn = restore_fn) 

報錯:

問題原因:沒有匯入引數

問題語句:

exclude = ['conv_0','conv_1','conv_2']
variables_to_restore = slim.get_variables_to_restore(exclude=exclude)

解決措施:

include = ['dense_1','dense_2','dense_3']
variables_to_restore = slim.get_variables_to_restore(include=include)