Closed skim2257 closed 1 year ago
Was able to resolve this issue by changing the line to (removed .module
):
self.network.load_state_dict(torch.load(self.opt.reload_model_path, map_location='cuda:0'))
However, this made it incompatible with the downloaded models in training/trained_models/
Was able to resolve this issue by changing the line to (removed
.module
):self.network.load_state_dict(torch.load(self.opt.reload_model_path, map_location='cuda:0'))
However, this made it incompatible with the downloaded models in
training/trained_models/
me too! ~ hahaha 0.0
Same issue for me, mismatch with usual jpg: RuntimeError: Error(s) in loading state_dict for EncoderDecoder: Missing key(s) in state_dict: "encoder.conv1.bias", "encoder.conv2.weight", "encoder.conv2.bias", "encoder.conv3.weight", "encoder.conv3.bias", "encoder.lin1.weight", "encoder.lin1.bias", "encoder.lin2.weight", "encoder.lin2.bias", "encoder.bn2.weight", "encoder.bn2.bias", "encoder.bn2.running_mean", "encoder.bn2.running_var", "encoder.bn3.weight", "encoder.bn3.bias", "encoder.bn3.running_mean", "encoder.bn3.running_var", "encoder.bn4.weight", "encoder.bn4.bias", "encoder.bn4.running_mean", "encoder.bn4.running_var", "encoder.bn5.weight", "encoder.bn5.bias", "encoder.bn5.running_mean", "encoder.bn5.running_var". ................................................ ............................................... Unexpected key(s) in state_dict: "encoder.layer1.0.conv1.weight" ...................................................... ...................................................; size mismatch for encoder.conv1.weight: copying a param with shape torch.Size([64, 3, 7, 7]) from checkpoint, the shape in current model is torch.Size([64, 3, 1]).
Same issue for me, mismatch with usual jpg: RuntimeError: Error(s) in loading state_dict for EncoderDecoder: Missing key(s) in state_dict: "encoder.conv1.bias", "encoder.conv2.weight", "encoder.conv2.bias", "encoder.conv3.weight", "encoder.conv3.bias", "encoder.lin1.weight", "encoder.lin1.bias", "encoder.lin2.weight", "encoder.lin2.bias", "encoder.bn2.weight", "encoder.bn2.bias", "encoder.bn2.running_mean", "encoder.bn2.running_var", "encoder.bn3.weight", "encoder.bn3.bias", "encoder.bn3.running_mean", "encoder.bn3.running_var", "encoder.bn4.weight", "encoder.bn4.bias", "encoder.bn4.running_mean", "encoder.bn4.running_var", "encoder.bn5.weight", "encoder.bn5.bias", "encoder.bn5.running_mean", "encoder.bn5.running_var". ................................................ ............................................... Unexpected key(s) in state_dict: "encoder.layer1.0.conv1.weight" ...................................................... ...................................................; size mismatch for encoder.conv1.weight: copying a param with shape torch.Size([64, 3, 7, 7]) from checkpoint, the shape in current model is torch.Size([64, 3, 1]).
Image should be rgb with transparency and size 137x137 Otherwise it fails. This is the reason why there are encoder size mismatch
i solved this Problem already,i think it;s because the mismatch between save and load model
change the 'reload_network' in trainner_model.py line 33 def reload_network(self): """ Reload entire model or only decoder (atlasnet) depending on the options :return: """ if self.opt.reload_model_path != "": yellow_print(f"Network weights loaded from {self.opt.reload_model_path}!")
# print(torch.load(self.opt.reload_model_path).keys())
# pdb.set_trace()
tmp_model_keys = torch.load(self.opt.reload_model_path, map_location='cuda:0').keys()
if "module.encoder.conv1.weight" in tmp_model_keys:
self.network.load_state_dict(torch.load(self.opt.reload_model_path, map_location='cuda:0'))
else:
self.network.module.load_state_dict(torch.load(self.opt.reload_model_path, map_location='cuda:0'))
elif self.opt.reload_decoder_path != "":
opt = deepcopy(self.opt)
opt.SVR = False
network = EncoderDecoder(opt)
network = nn.DataParallel(network, device_ids=opt.multi_gpu)
tmp_model_keys = torch.load(opt.reload_decoder_path, map_location='cuda:0').keys()
if "module.encoder.conv1.weight" in tmp_model_keys:
network.load_state_dict(torch.load(opt.reload_decoder_path, map_location='cuda:0'))
else:
network.module.load_state_dict(torch.load(opt.reload_decoder_path, map_location='cuda:0'))
self.network.module.decoder = network.module.decoder
yellow_print(f"Network Decoder weights loaded from {self.opt.reload_decoder_path}!")
Closing this since the issue is stale, feel free to reopen. Thanks a lot for for playing around with AtlasNet. Cheers, Thibault
Relevant code is line 42 of model/trainer_model.py
self.network.module.load_state_dict(torch.load(self.opt.reload_model_path, map_location='cuda:0'))