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

[GTSRB] Type error when loading loss weights #72

Closed
opmusic opened this issue Nov 29, 2021 · 2 comments
Closed

[GTSRB] Type error when loading loss weights #72

opmusic opened this issue Nov 29, 2021 · 2 comments

Comments

@opmusic
Copy link

opmusic commented Nov 29, 2021

When loading loss weights from GTSRB dataset, I found the default type of loss weights is np.float64, which will generate the following error:

RuntimeError: expected scalar type Float but found Double

And it may be fixed to add the following strict type conversion before line 182, trojanzoo/trojanzoo/models.py:

 if (isinstance(loss_weights,np.ndarray)):
     loss_weights=np.asarray(loss_weights).astype(np.float32)
@ain-soph
Copy link
Owner

ain-soph commented Nov 30, 2021

Thanks for pointing it out. It seems this issue is introduced by new pytorch/numpy versions. (It still works at least last month.)

I'd prefer to keep loss_weights as double and transform to float when moving to torch.Tensor, because numpy default precision is double and pytorch precision is float.

I'll draft a new release very soon.

@ain-soph
Copy link
Owner

self.criterion = self.define_criterion(weight=to_tensor(loss_weights, dtype=torch.float))

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

2 participants