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

Assertion error in transfer.py #1

Closed
Rukhmini opened this issue May 7, 2020 · 9 comments
Closed

Assertion error in transfer.py #1

Rukhmini opened this issue May 7, 2020 · 9 comments

Comments

@Rukhmini
Copy link

Rukhmini commented May 7, 2020

I am getting assertion error in transfer.py code in line no:46
assert len(c_keys.difference(t_keys)) == 0
The error is:

AssertionError Traceback (most recent call last)
~\CovidAID-master\tools\transfer.py in
44 #print (len(c_keys.difference(t_keys)))
45 #print (len(t_keys.difference(c_keys)))
---> 46 assert len(c_keys.difference(t_keys)) == 0
47 assert len(t_keys.difference(c_keys)) == 0
48

AssertionError:

@arpanmangal
Copy link
Owner

Please report your pytorch and torchvision versions. If not already doing, use the correct version of these packages as mentioned here: https://github.com/arpanmangal/CovidAID/blob/master/INSTALL.md

@bartmch
Copy link

bartmch commented May 13, 2020

I'm currently trying to update your repo to support torch1.5. The versions you're using support cuda80, I'm on cuda10.2 so that will not work.
I have 2 questions:

  1. The assertion mentioned by @Rukhmini compartes a torch.models.densenet121 model architecture with the pre-trained chexnet model from another repo. The imported densenet121 is on torch1.5. This makes me assume that the chexnet model is causing issues and will need to be updated to be supported by torch1.5, is that correct?
  2. What other changes do you anticipate for running it on torch1.5?

@arpanmangal
Copy link
Owner

@bartmch

  1. Yes, the main reason for using the older torch version is compatibility with the pre-trained CheXNet model. It is possible to change the CheXNet model in the latest format. pytorch0.3 and pytorch>=1.0 models differ mainly in the names of keys in the state_dict of the model, and maintaining some running variables for batch norm. One will have to load the old trained model and transfer it's trained weights in the newer format.
  2. Other changes one will have to do is to change the forward pass code in tools/trainer.py as well as tools/inference.py, removing the autograd.Variable instances which have been depreciated since pytorch0.4

@bartmch
Copy link

bartmch commented May 13, 2020

Thanks for the quick reply! @arpanmangal on point (1):
I successfully changed the state_dict keys, what do I do for the num_batches_tracked layers? Do I ignore the following assertion in "transfer.py"? (as it's a torch(0) layer)

image

If it's not clear, I'm talking about the "num_batches_tracked" layers available on torch>1.0 but not in torch<1.0

image

@bartmch
Copy link

bartmch commented May 13, 2020

I was thinking about this solution because num_batches_tracked are 0 tensors (removed the commented line):
image
Would that solve the problem you think?

@arpanmangal
Copy link
Owner

arpanmangal commented May 13, 2020

@bartmch Continuing the discussion in #2

@Rukhmini
Copy link
Author

@bartmch Have you successfully run the code using pytorch>1.0. If so, can you please guide what are the changes required to run the code successfully?

@bartmch
Copy link

bartmch commented May 18, 2020

@bartmch Have you successfully run the code using pytorch>1.0. If so, can you please guide what are the changes required to run the code successfully?

See previous messages. In short implement the following snippet to make the layers compatible:
for key in list(state_dict.keys()): res = pattern.match(key) if res: new_key = res.group(1) + res.group(2) state_dict[new_key] = state_dict[key] del state_dict[key]

@shroq1
Copy link

shroq1 commented Apr 12, 2022

@bartmch what did you mean of res = pattern.match(key)"?

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

4 participants