Project-MONAI / GenerativeModels

MONAI Generative Models makes it easy to train, evaluate, and deploy generative models and related applications
Apache License 2.0
555 stars 78 forks source link

Workaround for using models without Internetconnection #472

Closed iffthomas closed 1 month ago

iffthomas commented 3 months ago

Hi Monai team,

Currently I'm trying out Image Synthesis inspired by a Tutorial: (https://github.com/Project-MONAI/GenerativeModels/tree/main/tutorials/generative/2d_vqgan)

As I've only got a laptop I mainly use clusters to have access to a GPU. This poses a slight problem as I don't have permission to connect to the web and can't load models that are in torch.hub. This a requirement for some tutorials/models that need pretrained weights such as PerceptualLoss(spatial_dims=2, pretrained = False, network_type=None)which inherently comes from other github repositories. I've wanted to ask if there exists a possibility to have a workaround for pretrained weights. Setting pretrained = False still tries to connect to the web and hence it fails to run this notbook.

marksgraham commented 3 months ago

Hi,

If you run locally, you can find out where the models are downloaded to using torch.hub.get_dir(), see here. You can upload that folder to the server and set this location when you init the perceptual loss using the cache_dir argument, which will call torch.hub.set_dir() for you. If it finds the models in the hub it shouldn't try to download them from the web.