Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo.py #6

Open
hlee-git opened this issue Aug 28, 2018 · 4 comments
Open

demo.py #6

hlee-git opened this issue Aug 28, 2018 · 4 comments

Comments

@hlee-git
Copy link

Traceback (most recent call last):
File "/home/weakalign-master/demo.py", line 77, in
model.FeatureExtraction.state_dict()[name].copy_(checkpoint['state_dict']['FeatureExtraction.' + name])
KeyError: 'FeatureExtraction.model.1.num_batches_tracked'

I tried your code, but there was KeyError like above
OrderedDict "checkpoint['state_dict']['FeatureExtraction.model.1.num_batches_tracked']" does not exist
I'd appreciate it if you could check for the error.

@bluedream1121
Copy link

I also have that issue after I update pytorch 0.3 to pytorch 0.4.

Who anybody solve this problem?

@siavashk
Copy link

siavashk commented Nov 1, 2018

I ran into the same issue. The underlying reason is that pytorch has changed its batchnorm some time between versions 0.2 and 0.4: pytorch/pytorch#8481
This pull request is supposed to fix it, but it did not fix it for me. I managed to get the demo running by downgrading to 0.2: conda install pytorch=0.2 torchvision -c pytorch

@AziziShekoofeh
Copy link

I also have the same issue and yes, the underlying reason is pytorch/pytorch#8481, however, downgrading is not a practical solution in long run. Anybody plan to address this?

@chenyuZha
Copy link

I found the solution: instead to downgrade pytorch to 0.2, you can filter the keys by ignoring num_batches_tracked

 feature_extraction_dict = {k: v for k, v in self.model_aff.FeatureExtraction.state_dict().items() if 'num_batches_tracked' not in k}
            for name, param in feature_extraction_dict.items():
                self.model_aff.FeatureExtraction.state_dict()[name].copy_(checkpoint['state_dict']['FeatureExtraction.' + name])

            feature_reg_dict = {k: v for k, v in self.model_aff.FeatureRegression.state_dict().items() if 'num_batches_tracked' not in k}
            for name, param in feature_reg_dict.items():
                self.model_aff.FeatureRegression.state_dict()[name].copy_(checkpoint['state_dict']['FeatureRegression.' + name])

            feature_reg2_dict = {k: v for k, v in self.model_aff.FeatureRegression2.state_dict().items() if
                                'num_batches_tracked' not in k}
            for name, param in feature_reg2_dict.items():
                self.model_aff.FeatureRegression2.state_dict()[name].copy_(
                    checkpoint['state_dict']['FeatureRegression2.' + name])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants