I have an error: “Unexpected key(s) in state_dict: ‘epoch’, ‘netG_state_dict’, ‘optimizer_state_dict’.” when resume training. (below lines are full error, and I added my trainer_vlc.py code at the bottom.)
Would you let me know how to load model correctly?
File "/project/6057220/xianzhen/storygan/vlcgan/trainer_vlc.py", line 110, in load_network_stageI
netG.load_state_dict(state_dict)
File "/home/xianzhen/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1482, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for StoryMarttGAN:
Missing key(s) in state_dict: "recurrent.weight_ih", "recurrent.weight_hh", "recurrent.bias_ih", "recurrent.bias_hh", "moconn.layer.0.attention.self.query.weight", "moconn.layer.0.attention.self.query.bias", "moconn.layer.0.attention.self.key.weight", "moconn.layer.0.attention.self.key.bias", "moconn.layer.0.attention.self.value.weight", "moconn.layer.0.attention.self.value.bias", "moconn.layer.0.attention.output.dense.weight", "moconn.layer.0.attention.output.dense.bias", "moconn.layer.0.attention.output.LayerNorm.weight", "moconn.layer.0.attention.output.LayerNorm.bias", "moconn.layer.0.memory_initilizer.init_memory_bias", "moconn.layer.0.memory_initilizer.init_memory_fc.0.weight", "moconn.layer.0.memory_initilizer.init_memory_fc.0.bias", "moconn.layer.0.memory_initilizer.init_memory_fc.1.weight", "moconn.layer.0.memory_initilizer.init_memory_fc.1.bias", "moconn.layer.0.memory_updater.memory_update_attention.query.weight", "moconn.layer.0.memory_updater.memory_update_attention.query.bias", "moconn.layer.0.memory_updater.memory_update_attention.key.weight", "moconn.layer.0.memory_updater.memory_update_attention.key.bias", "moconn.layer.0.memory_updater.memory_update_attention.value.weight", "moconn.layer.0.memory_updater.memory_update_attention.value.bias", "moconn.layer.0.memory_updater.mc.weight", "moconn.layer.0.memory_updater.sc.weight", "moconn.layer.0.memory_updater.sc.bias", "moconn.layer.0.memory_updater.mz.weight", "moconn.layer.0.memory_updater.sz.weight", "moconn.layer.0.memory_updater.sz.bias", "moconn.layer.0.memory_augmented_attention.query.weight", "moconn.layer.0.memory_augmented_attention.query.bias", "moconn.layer.0.memory_augmented_attention.key.weight", "moconn.layer.0.memory_augmented_attention.key.bias", "moconn.layer.0.memory_augmented_attention.value.weight", "moconn.layer.0.memory_augmented_attention.value.bias", "moconn.layer.0.hidden_intermediate.dense.weight", "moconn.layer.0.hidden_intermediate.dense.bias", "moconn.layer.0.memory_projection.weight", "moconn.layer.0.memory_projection.bias", "moconn.layer.0.output.dense.weight", "moconn.layer.0.output.dense.bias", "moconn.layer.0.output.LayerNorm.weight", "moconn.layer.0.output.LayerNorm.bias", "moconn.layer.1.attention.self.query.weight", "moconn.layer.1.attention.self.query.bias", "moconn.layer.1.attention.self.key.weight", "moconn.layer.1.attention.self.key.bias", "moconn.layer.1.attention.self.value.weight", "moconn.layer.1.attention.self.value.bias", "moconn.layer.1.attention.output.dense.weight", "moconn.layer.1.attention.output.dense.bias", "moconn.layer.1.attention.output.LayerNorm.weight", "moconn.layer.1.attention.output.LayerNorm.bias", "moconn.layer.1.memory_initilizer.init_memory_bias", "moconn.layer.1.memory_initilizer.init_memory_fc.0.weight", "moconn.layer.1.memory_initilizer.init_memory_fc.0.bias", "moconn.layer.1.memory_initilizer.init_memory_fc.1.weight", "moconn.layer.1.memory_initilizer.init_memory_fc.1.bias", "moconn.layer.1.memory_updater.memory_update_attention.query.weight", "moconn.layer.1.memory_updater.memory_update_attention.query.bias", "moconn.layer.1.memory_updater.memory_update_attention.key.weight", "moconn.layer.1.memory_updater.memory_update_attention.key.bias", "moconn.layer.1.memory_updater.memory_update_attention.value.weight", "moconn.layer.1.memory_updater.memory_update_attention.value.bias", "moconn.layer.1.memory_updater.mc.weight", "moconn.layer.1.memory_updater.sc.weight", "moconn.layer.1.memory_updater.sc.bias", "moconn.layer.1.memory_updater.mz.weight", "moconn.layer.1.memory_updater.sz.weight", "moconn.layer.1.memory_updater.sz.bias", "moconn.layer.1.memory_augmented_attention.query.weight", "moconn.layer.1.memory_augmented_attention.query.bias", "moconn.layer.1.memory_augmented_attention.key.weight", "moconn.layer.1.memory_augmented_attention.key.bias", "moconn.layer.1.memory_augmented_attention.value.weight", "moconn.layer.1.memory_augmented_attention.value.bias", "moconn.layer.1.hidden_intermediate.dense.weight", "moconn.layer.1.hidden_intermediate.dense.bias", "moconn.layer.1.memory_projection.weight", "moconn.layer.1.memory_projection.bias", "moconn.layer.1.output.dense.weight", "moconn.layer.1.output.dense.bias", "moconn.layer.1.output.LayerNorm.weight", "moconn.layer.1.output.LayerNorm.bias", "moconn.layer.2.attention.self.query.weight", "moconn.layer.2.attention.self.query.bias", "moconn.layer.2.attention.self.key.weight", "moconn.layer.2.attention.self.key.bias", "moconn.layer.2.attention.self.value.weight", "moconn.layer.2.attention.self.value.bias", "moconn.layer.2.attention.output.dense.weight", "moconn.layer.2.attention.output.dense.bias", "moconn.layer.2.attention.output.LayerNorm.weight", "moconn.layer.2.attention.output.LayerNorm.bias", "moconn.layer.2.memory_initilizer.init_memory_bias", "moconn.layer.2.memory_initilizer.init_memory_fc.0.weight", "moconn.layer.2.memory_initilizer.init_memory_fc.0.bias", "moconn.layer.2.memory_initilizer.init_memory_fc.1.weight", "moconn.layer.2.memory_initilizer.init_memory_fc.1.bias", "moconn.layer.2.memory_updater.memory_update_attention.query.weight", "moconn.layer.2.memory_updater.memory_update_attention.query.bias", "moconn.layer.2.memory_updater.memory_update_attention.key.weight", "moconn.layer.2.memory_updater.memory_update_attention.key.bias", "moconn.layer.2.memory_updater.memory_update_attention.value.weight", "moconn.layer.2.memory_updater.memory_update_attention.value.bias", "moconn.layer.2.memory_updater.mc.weight", "moconn.layer.2.memory_updater.sc.weight", "moconn.layer.2.memory_updater.sc.bias", "moconn.layer.2.memory_updater.mz.weight", "moconn.layer.2.memory_updater.sz.weight", "moconn.layer.2.memory_updater.sz.bias", "moconn.layer.2.memory_augmented_attention.query.weight", "moconn.layer.2.memory_augmented_attention.query.bias", "moconn.layer.2.memory_augmented_attention.key.weight", "moconn.layer.2.memory_augmented_attention.key.bias", "moconn.layer.2.memory_augmented_attention.value.weight", "moconn.layer.2.memory_augmented_attention.value.bias", "moconn.layer.2.hidden_intermediate.dense.weight", "moconn.layer.2.hidden_intermediate.dense.bias", "moconn.layer.2.memory_projection.weight", "moconn.layer.2.memory_projection.bias", "moconn.layer.2.output.dense.weight", "moconn.layer.2.output.dense.bias", "moconn.layer.2.output.LayerNorm.weight", "moconn.layer.2.output.LayerNorm.bias", "moconn.layer.3.attention.self.query.weight", "moconn.layer.3.attention.self.query.bias", "moconn.layer.3.attention.self.key.weight", "moconn.layer.3.attention.self.key.bias", "moconn.layer.3.attention.self.value.weight", "moconn.layer.3.attention.self.value.bias", "moconn.layer.3.attention.output.dense.weight", "moconn.layer.3.attention.output.dense.bias", "moconn.layer.3.attention.output.LayerNorm.weight", "moconn.layer.3.attention.output.LayerNorm.bias", "moconn.layer.3.memory_initilizer.init_memory_bias", "moconn.layer.3.memory_initilizer.init_memory_fc.0.weight", "moconn.layer.3.memory_initilizer.init_memory_fc.0.bias", "moconn.layer.3.memory_initilizer.init_memory_fc.1.weight", "moconn.layer.3.memory_initilizer.init_memory_fc.1.bias", "moconn.layer.3.memory_updater.memory_update_attention.query.weight", "moconn.layer.3.memory_updater.memory_update_attention.query.bias", "moconn.layer.3.memory_updater.memory_update_attention.key.weight", "moconn.layer.3.memory_updater.memory_update_attention.key.bias", "moconn.layer.3.memory_updater.memory_update_attention.value.weight", "moconn.layer.3.memory_updater.memory_update_attention.value.bias", "moconn.layer.3.memory_updater.mc.weight", "moconn.layer.3.memory_updater.sc.weight", "moconn.layer.3.memory_updater.sc.bias", "moconn.layer.3.memory_updater.mz.weight", "moconn.layer.3.memory_updater.sz.weight", "moconn.layer.3.memory_updater.sz.bias", "moconn.layer.3.memory_augmented_attention.query.weight", "moconn.layer.3.memory_augmented_attention.query.bias", "moconn.layer.3.memory_augmented_attention.key.weight", "moconn.layer.3.memory_augmented_attention.key.bias", "moconn.layer.3.memory_augmented_attention.value.weight", "moconn.layer.3.memory_augmented_attention.value.bias", "moconn.layer.3.hidden_intermediate.dense.weight", "moconn.layer.3.hidden_intermediate.dense.bias", "moconn.layer.3.memory_projection.weight", "moconn.layer.3.memory_projection.bias", "moconn.layer.3.output.dense.weight", "moconn.layer.3.output.dense.bias", "moconn.layer.3.output.LayerNorm.weight", "moconn.layer.3.output.LayerNorm.bias", "pooler.context_vector", "pooler.fc.0.weight", "pooler.fc.0.bias", "pooler.fc.1.weight", "pooler.fc.1.bias", "pooler.fc.1.running_mean", "pooler.fc.1.running_var", "embeddings.word_embeddings.weight", "embeddings.word_fc.0.weight", "embeddings.word_fc.0.bias", "embeddings.word_fc.2.weight", "embeddings.word_fc.2.bias", "embeddings.word_fc.4.weight", "embeddings.word_fc.4.bias", "embeddings.position_embeddings.pe", "embeddings.LayerNorm.weight", "embeddings.LayerNorm.bias", "tag_embeddings.weight", "map_embed.weight", "map_embed.bias", "ca_net.fc.weight", "ca_net.fc.bias", "fc.0.weight", "fc.1.weight", "fc.1.bias", "fc.1.running_mean", "fc.1.running_var", "filter_net.0.weight", "filter_net.0.bias", "filter_net.1.weight", "filter_net.1.bias", "filter_net.1.running_mean", "filter_net.1.running_var", "image_net.0.weight", "image_net.0.bias", "image_net.1.weight", "image_net.1.bias", "image_net.1.running_mean", "image_net.1.running_var", "mart_fc.0.weight", "mart_fc.0.bias", "mart_fc.1.weight", "mart_fc.1.bias", "mart_fc.1.running_mean", "mart_fc.1.running_var", "upsample1.1.weight", "upsample1.2.weight", "upsample1.2.bias", "upsample1.2.running_mean", "upsample1.2.running_var", "upsample2.1.weight", "upsample2.2.weight", "upsample2.2.bias", "upsample2.2.running_mean", "upsample2.2.running_var", "upsample3.1.weight", "upsample3.2.weight", "upsample3.2.bias", "upsample3.2.running_mean", "upsample3.2.running_var", "next_g.att.conv_context.weight", "next_g.att.conv_sentence_vis.weight", "next_g.att.linear.weight", "next_g.att.linear.bias", "next_g.residual.0.block.0.weight", "next_g.residual.0.block.1.weight", "next_g.residual.0.block.1.bias", "next_g.residual.0.block.1.running_mean", "next_g.residual.0.block.1.running_var", "next_g.residual.0.block.3.weight", "next_g.residual.0.block.4.weight", "next_g.residual.0.block.4.bias", "next_g.residual.0.block.4.running_mean", "next_g.residual.0.block.4.running_var", "next_g.residual.1.block.0.weight", "next_g.residual.1.block.1.weight", "next_g.residual.1.block.1.bias", "next_g.residual.1.block.1.running_mean", "next_g.residual.1.block.1.running_var", "next_g.residual.1.block.3.weight", "next_g.residual.1.block.4.weight", "next_g.residual.1.block.4.bias", "next_g.residual.1.block.4.running_mean", "next_g.residual.1.block.4.running_var", "next_g.residual.2.block.0.weight", "next_g.residual.2.block.1.weight", "next_g.residual.2.block.1.bias", "next_g.residual.2.block.1.running_mean", "next_g.residual.2.block.1.running_var", "next_g.residual.2.block.3.weight", "next_g.residual.2.block.4.weight", "next_g.residual.2.block.4.bias", "next_g.residual.2.block.4.running_mean", "next_g.residual.2.block.4.running_var", "next_g.residual.3.block.0.weight", "next_g.residual.3.block.1.weight", "next_g.residual.3.block.1.bias", "next_g.residual.3.block.1.running_mean", "next_g.residual.3.block.1.running_var", "next_g.residual.3.block.3.weight", "next_g.residual.3.block.4.weight", "next_g.residual.3.block.4.bias", "next_g.residual.3.block.4.running_mean", "next_g.residual.3.block.4.running_var", "next_g.upsample.1.weight", "next_g.upsample.2.weight", "next_g.upsample.2.bias", "next_g.upsample.2.running_mean", "next_g.upsample.2.running_var", "next_g.conv.weight", "next_img.0.weight", "next_img_.0.weight", "m_net.0.weight", "m_net.0.bias", "m_net.1.weight", "m_net.1.bias", "m_net.1.running_mean", "m_net.1.running_var", "c_net.0.weight", "c_net.0.bias", "c_net.1.weight", "c_net.1.bias", "c_net.1.running_mean", "c_net.1.running_var".
Unexpected key(s) in state_dict: "epoch", "netG_state_dict", "optimizer_state_dict".
def load_network_stageI(self):
from .model import StoryGAN, STAGE1_D_IMG, STAGE1_D_STY_V2, StoryMarttGAN
if self.use_martt:
netG = StoryMarttGAN(self.cfg, self.video_len)
else:
netG = StoryGAN(self.cfg, self.video_len)
netG.apply(weights_init)
print(netG)
if self.cfg.NET_G != '':
state_dict = \
torch.load(self.cfg.NET_G,
map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict)
print('Load from: ', self.cfg.NET_G)
if self.use_image_disc:
if self.cfg.DATASET_NAME == 'youcook2':
use_categories = False
else:
use_categories = True
netD_im = STAGE1_D_IMG(self.cfg, use_categories=use_categories)
netD_im.apply(weights_init)
print(netD_im)
if self.cfg.NET_D_IM != '':
state_dict = \
torch.load(self.cfg.NET_D_IM,
map_location=lambda storage, loc: storage)
netD_im.load_state_dict(state_dict)
print('Load from: ', self.cfg.NET_D_IM)
else:
netD_im = None
if self.use_story_disc:
netD_st = STAGE1_D_STY_V2(self.cfg)
netD_st.apply(weights_init)
# for m in netD_st.modules():
# print(m.__class__.__name__)
print(netD_st)
if self.cfg.NET_D_ST != '':
state_dict = \
torch.load(self.cfg.NET_D_ST,
map_location=lambda storage, loc: storage)
netD_st.load_state_dict(state_dict)
print('Load from: ', self.cfg.NET_D_ST)
else:
netD_st = None