Sorry, I am using a new computer and I just installed the newest version of Pytorch.
My code runs perfectly on my old computer.
But now BatchNorm2d is giving me this error when the model is switched to evaluation mode.
‘BatchNorm2d’ object has no attribute ‘track_running_stats’
Does anyone know how to solve this?
I saw the source code change warning, but I am not sure about how to solve it.
My model is based on pre-trained ResNet101
Encountered same problem. Upgraded to V0.4 and rebuilt model. It required some minor re-working of the code. The model now works without error using torch.version 0.4.0
@C0rine, apologies for the slow response. The only issue I had was a previously working function that computed accuracy and sensitivity values had to be updated. The V0.4.0 version of PyTorch required me to explicitly cast the tensor to a float to compute the value. It may have been ‘operator error’ on my part not following a guideline but it worked in V0.3. After figuring that out, I was able to ‘retrain’ the model and use it in a separate production prediction microservice. I want to do more study on the differences in the model predictions between the two versions. I noticed some differences in prediction computations but have not had a chance to do a rigorous analysis. Good luck.
I am also facing the same problem and would want to roll back to previous version i.e 0.3.1. How can I do that using pip. Can you please share you method of downgrading the pytorch version?
Your model train by pytorch0.3.x, but run in pytorch > 0.4.0.
Change the parameter of BatchNorm2d by yourself.
For example, define the function
def recursion_change_bn(module):
if isinstance(module, torch.nn.BatchNorm2d):
module.track_running_stats = 1
else:
for i, (name, module1) in enumerate(module._modules.items()):
module1 = recursion_change_bn(module1)
return module
and
use it when you load model
check_point = torch.load(check_point_file_path)
model = check_point['net']
for i, (name, module) in enumerate(model._modules.items()):
module = recursion_change_bn(model)
model.eval()
I have ran 0.3.1 model in pytorch0.4.1. and pytorch1.0.0.