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

Refactor perceptual loss so that it can be used offline (regardless of the network_type) #8317

Open
virginiafdez opened this issue Jan 28, 2025 · 1 comment
Assignees

Comments

@virginiafdez
Copy link
Contributor

I am trying to instance perceptual loss in an environment where there would not be access to the internet. With torchvision models, I typically instance the network with pretrained = False and then manually load the weights I have saved somewhere local previously.
With the PerceptualLoss class it is difficult to do so; whereas some network_types seem to have this functionality (e.g. resnet50 has a pretrained=False) types like medicalnet seem to need to access the internet all the time for (1) defining the network (resnet.py is downloaded from the hub) (2) getting and loading the weights.

Describe the solution you'd like

  • Standardisation of how the different networks are instanced / defined
  • Unique pretrained parameter or pretrained_path allowing users to load the weigths from an alternative local path.

Describe alternatives you've considered
Hardcode perceptual_loss to allow for this for the specific network_type I am using

@virginiafdez virginiafdez self-assigned this Jan 28, 2025
@virginiafdez
Copy link
Contributor Author

The desired behaviour can be achieved by:

  • Pre-downloading repo and model checkpoints (the easiest way is to query the perceptual loss once with connection to the internet) while having set the torch.hub cache directory with torch.hub.set_dir().
  • Then when in machine without connection to the internet, you can copy the repository to a desired location and then set the torch.hub cache directory to that. Perceptual loss should not try to download it if the files are already there.

There is a persisting issue still in terms of the way models are defined and loading depends entirely on the network_type parameter (e.g. medicalnet pulls a git repo, lpips pulls from their repo etc.). It would be nice to homogenise this.

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

1 participant