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

fix: efficient ad model_size str fixes #2159

Merged
merged 4 commits into from
Jul 10, 2024
Merged
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
15 changes: 9 additions & 6 deletions src/anomalib/models/image/efficient_ad/lightning_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
self,
imagenet_dir: Path | str = "./datasets/imagenette",
teacher_out_channels: int = 384,
model_size: EfficientAdModelSize = EfficientAdModelSize.S,
model_size: EfficientAdModelSize | str = EfficientAdModelSize.S,
lr: float = 0.0001,
weight_decay: float = 0.00001,
padding: bool = False,
Expand All @@ -72,24 +72,27 @@
super().__init__()

self.imagenet_dir = Path(imagenet_dir)
self.model_size = model_size
if not isinstance(model_size, EfficientAdModelSize):
model_size = EfficientAdModelSize(model_size)

Check warning on line 76 in src/anomalib/models/image/efficient_ad/lightning_model.py

View check run for this annotation

Codecov / codecov/patch

src/anomalib/models/image/efficient_ad/lightning_model.py#L76

Added line #L76 was not covered by tests
self.model_size: EfficientAdModelSize = model_size
self.model: EfficientAdModel = EfficientAdModel(
teacher_out_channels=teacher_out_channels,
model_size=model_size,
padding=padding,
pad_maps=pad_maps,
)
self.batch_size = 1 # imagenet dataloader batch_size is 1 according to the paper
self.lr = lr
self.weight_decay = weight_decay
self.batch_size: int = 1 # imagenet dataloader batch_size is 1 according to the paper
self.lr: float = lr
self.weight_decay: float = weight_decay

def prepare_pretrained_model(self) -> None:
"""Prepare the pretrained teacher model."""
pretrained_models_dir = Path("./pre_trained/")
if not (pretrained_models_dir / "efficientad_pretrained_weights").is_dir():
download_and_extract(pretrained_models_dir, WEIGHTS_DOWNLOAD_INFO)
model_size_str = self.model_size.value if isinstance(self.model_size, EfficientAdModelSize) else self.model_size
teacher_path = (
pretrained_models_dir / "efficientad_pretrained_weights" / f"pretrained_teacher_{self.model_size.value}.pth"
pretrained_models_dir / "efficientad_pretrained_weights" / f"pretrained_teacher_{model_size_str}.pth"
)
logger.info(f"Load pretrained teacher model from {teacher_path}")
self.model.teacher.load_state_dict(torch.load(teacher_path, map_location=torch.device(self.device)))
Expand Down
Loading