Skip to content

Fixed DSR training when no GPU #2004

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

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/anomalib/models/image/dsr/lightning_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def configure_optimizers(
def on_train_start(self) -> None:
"""Load pretrained weights of the discrete model when starting training."""
ckpt: Path = self.prepare_pretrained_model()
self.model.load_pretrained_discrete_model_weights(ckpt)
self.model.load_pretrained_discrete_model_weights(ckpt, self.device)

def on_train_epoch_start(self) -> None:
"""Display a message when starting to train the upsampling module."""
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/models/image/dsr/torch_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def __init__(
for parameters in self.discrete_latent_model.parameters():
parameters.requires_grad = False

def load_pretrained_discrete_model_weights(self, ckpt: Path) -> None:
def load_pretrained_discrete_model_weights(self, ckpt: Path, device: torch.device | str | None = None) -> None:
"""Load pre-trained model weights."""
self.discrete_latent_model.load_state_dict(torch.load(ckpt))
self.discrete_latent_model.load_state_dict(torch.load(ckpt, map_location=device))

def forward(
self,
Expand Down
Loading