VITA-Group / EnlightenGAN

[IEEE TIP] "EnlightenGAN: Deep Light Enhancement without Paired Supervision" by Yifan Jiang, Xinyu Gong, Ding Liu, Yu Cheng, Chen Fang, Xiaohui Shen, Jianchao Yang, Pan Zhou, Zhangyang Wang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected&Missing Key when Testing with Pytorch 1.7.1

ShenZheng2000 opened this issue · comments

Hello, authors! Thanks for your nice work. I met an error when testing your model with Pytorch 1.7.1

Traceback (most recent call last):
File "predict.py", line 18, in
model = create_model(opt)
File "D:\Code\SeniorThesis\EnlightenGAN-master\models\models.py", line 36, in create_model
model.initialize(opt)
File "D:\Code\SeniorThesis\EnlightenGAN-master\models\single_model.py", line 72, in initialize
self.load_network(self.netG_A, 'G_A', which_epoch)
File "D:\Code\SeniorThesis\EnlightenGAN-master\models\base_model.py", line 54, in load_network
network.load_state_dict(torch.load(save_path, map_location=device))
File "D:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 1051, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Unet_resize_conv:

I list a part of errors because it is too long:
Missing key(s) in state_dict: "conv1_1.weight", "conv1_1.bias", "bn1_1.weight", "bn1_1.bias", "bn1_1.running_mean", "bn1_1.running_var", "conv1_2.weight",

Unexpected key(s) in state_dict: "module.conv1_1.weight", "module.conv1_1.bias", "module.bn1_1.weight", "module.bn1_1.bias", "module.bn1_1.running_mean",

I would like to know if this problem is caused by the Pytorch version or torch.nn.dataparallel and I want to know how to address this. Thanks!

It is caused by dataparalle. You need to firstly use Dataparallel to warp the model then load checkpoint. Or you can directly change the name in checkpoint json objects.

@ShenZheng2000
I got the same problem with U. My Pytorch version is 1.8.x
And i am a rookie on DeepLearning domain. I want to use this algorithm to generate a normal light pic to a low light pic instread of enhancing the low light pic.
I appreciate that if U share the solution.
Thanks a lot.

The solution is already mentioned here.

It is caused by dataparalle. You need to firstly use Dataparallel to warp the model then load checkpoint. Or you can directly change the name in checkpoint json objects.