我想加载MCnet模型的预训练权重并恢复训练。这里提供的预训练模型是使用参数K=4,T=7
进行训练的。但我需要一个参数为K=4,T=1
的模型。我想从这个预训练模型加载权重而不是从头开始训练。但由于图形已更改,我无法加载预训练模型。
InvalidArgumentError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Assign requires shapes of both tensors to match. lhs shape= [5,5,15,64] rhs shape= [5,5,33,64]
[[node save/Assign_13 (defined at /media/nagabhushan/Data02/SNB/IISc/Research/04_Gaming_Video_Prediction/Workspace/VideoPrediction/Literature/01_MCnet/src/snb/mcnet.py:108) ]]
能否使用新图加载预训练模型?
我尝试过的:
以前,我想将预训练模型从旧版tensorflow移植到新版。我在StackOverflow上得到这个答案,帮助我完成了模型移植。其思路是创建新图并从保存的图中加载存在于新图中的变量。
with tf.Session() as sess:
_ = MCNET(image_size=[240, 320], batch_size=8, K=4, T=1, c_dim=3, checkpoint_dir=None, is_train=True)
tf.global_variables_initializer().run(session=sess)
ckpt_vars = tf.train.list_variables(model_path.as_posix())
ass_ops = []
for dst_var in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES):
for (ckpt_var, ckpt_shape) in ckpt_vars:
if dst_var.name.split(":")[0] == ckpt_var and dst_var.shape == ckpt_shape:
value = tf.train.load_variable(model_path.as_posix(), ckpt_var)
ass_ops.append(tf.assign(dst_var, value))
# Assign the variables
sess.run(ass_ops)
saver = tf.train.Saver()
saver.save(sess, save_path.as_posix())
我在这里尝试了相同的操作,并且成功了,也就是说我得到了一个针对K=4,T=1
的新训练模型。但我不确定它是否有效!我的意思是,权重是否合理?这是正确的方法吗?
模型信息:
MCnet是一种用于视频预测的模型,即给定K
个过去帧,它可以预测接下来的T
帧。
非常感谢任何帮助。