When importing model files in pytorch, the following error is reported.
RuntimeError: Error(s) in loading state_dict for DataParallel:
Unexpected running stats buffer(s) “module.norm1.norm_func.running_mean” and “module.norm1.norm_func.running_var” for InstanceNorm2d with track_running_stats=False. If state_dict is a checkpoint saved before 0.4.0, this may be expected because InstanceNorm2d does not track running stats by default since 0.4.0. Please remove these keys from state_dict. If the running stats are actually needed, instead set track_running_stats=True in InstanceNorm2d to enable them. See the documentation of InstanceNorm2d for details.
…
Unexpected running stats buffer(s) “module.res5.norm1.norm_func.running_mean” and “module.res5.norm1.norm_func.running_var” for InstanceNorm2d with track_running_stats=False. If state_dict is a checkpoint saved before 0.4.0, this may be expected because InstanceNorm2d does not track running stats by default since 0.4.0. Please remove these keys from state_dict. If the running stats are actually needed, instead set track_running_stats=True in InstanceNorm2d to enable them. See the documentation of InstanceNorm2d for details.
…
Process finished with exit code 0
According to the hint, the imported model was generated with pytorch 0.4.0, but now we are using pytorch 1.0, so we checked the load_state_dict function in the module.
I guess the keyword has changed with the version.
The solution is.
Change the above statement to
RuntimeError: Error(s) in loading state_dict for DataParallel:
Unexpected running stats buffer(s) “module.norm1.norm_func.running_mean” and “module.norm1.norm_func.running_var” for InstanceNorm2d with track_running_stats=False. If state_dict is a checkpoint saved before 0.4.0, this may be expected because InstanceNorm2d does not track running stats by default since 0.4.0. Please remove these keys from state_dict. If the running stats are actually needed, instead set track_running_stats=True in InstanceNorm2d to enable them. See the documentation of InstanceNorm2d for details.
…
Unexpected running stats buffer(s) “module.res5.norm1.norm_func.running_mean” and “module.res5.norm1.norm_func.running_var” for InstanceNorm2d with track_running_stats=False. If state_dict is a checkpoint saved before 0.4.0, this may be expected because InstanceNorm2d does not track running stats by default since 0.4.0. Please remove these keys from state_dict. If the running stats are actually needed, instead set track_running_stats=True in InstanceNorm2d to enable them. See the documentation of InstanceNorm2d for details.
…
Process finished with exit code 0
According to the hint, the imported model was generated with pytorch 0.4.0, but now we are using pytorch 1.0, so we checked the load_state_dict function in the module.
I guess the keyword has changed with the version.
The solution is.
Change the above statement to
model_dict = torch.load(args.test_weight_path)
model_dict_clone = model_dict.copy()
for key, value in model_dict_clone.items():
if key.endswith(('running_mean', 'running_var')):
del model_dict[key]
Gnet.load_state_dict(model_dict,False)
Read More:
- Pytorch Loading model error: RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict
- [Solved] PyTorch Load Model Error: Missing key(s) RuntimeError: Error(s) in loading state_dict for
- [Solved] Pytorch Error: RuntimeError: Error(s) in loading state_dict for Network: size mismatch
- [Solved] RuntimeError: Error(s) in loading state_dict for BertForTokenClassification
- [Solved] RuntimeError: Error(s) in loading state_dict for Net:
- [Solved] RuntimeError: Error(s) in loading state dict for YOLOX:
- [Solved] Error(s) in loading state_dict for GeneratorResNet
- pytorch model.load_state_dict Error [How to Solve]
- [Solved] bushi RuntimeError: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /pytorch/caffe2/s
- [Pytorch Error Solution] Pytorch distributed RuntimeError: Address already in use
- [ONNXRuntimeError] : 10 : INVALID_Graph loading model error
- [Solved] PyTorch Caught RuntimeError in DataLoader worker process 0和invalid argument 0: Sizes of tensors mus
- How to Solve Pytorch DataLoader Loading Error: UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe5 in position 1023
- Pytorch torch.cuda.FloatTensor Error: RuntimeError: one of the variables needed for gradient computation has…
- [Solved] RuntimeError : PyTorch was compiled without NumPy support
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- [Solved] Yolov5 Deep Learning Error: RuntimeError: DataLoader worker (pid(s) 2516, 1768) exited unexpectedly
- [Solved] Pytorch error: RuntimeError: one of the variables needed for gradient computation
- [Solved] pytorch loss.backward() Error: RuntimeError: Function AddBackward0 returned an invalid gradient at index 1…
- pytorch: RuntimeError CUDA error device-side assert triggered