How to Train and Predict with Supersimplenet without masks #2870
Replies: 1 comment
-
Duplicate of #2868 . |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm trying to train the Supersimplenet model in Anomalib using my own dataset, which contains only image-level labels — that is, I have folders for good and defective images, but no ground-truth masks for pixel-level anomalies.
My goal is to train the model only on the good images, and then run inference on the defective samples — similar to how other models like Padim or Uninet are used in the unsupervised setting.
Here is the exception: /site-packages/anomalib/models/image/supersimplenet/torch_model.py", line 116, in downsample_mask
masks = masks.type(torch.float32)
^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'type'
Epoch 0: 0%| | 0/40 [00:00<?, ?it/s]
Here is the training code I'm using successfully with other models(Padim,UniNet etc):
from anomalib.data import Folder
from anomalib.loggers import AnomalibTensorBoardLogger
from anomalib.models.image import Supersimplenet
from anomalib.engine import Engine
from colorama import Fore, Style, init
from torchvision.transforms import v2
init(autoreset=True)
tensorboard_logger = AnomalibTensorBoardLogger("logs")
augmentations = v2.Compose([
v2.RandomHorizontalFlip(p=0.5),
v2.RandomVerticalFlip(p=0.5),
v2.ColorJitter(brightness=0.1),
v2.GaussianBlur(kernel_size=(3, 3), sigma=(0.1, 0.5)),
v2.RandomApply([v2.RandomErasing(scale=(0.0001, 0.001), ratio=(1.0, 1.0))], p=0.5)
])
dataset_name = "dataset_name"
datamodule = Folder(
name=dataset_name,
root=f"datasets/customs/{dataset_name}",
normal_dir="train/good",
train_augmentations=augmentations,
train_batch_size=4,
eval_batch_size=4
)
datamodule.setup()
print(Fore.LIGHTCYAN_EX + f"dataset_length:{len(datamodule.train_dataloader().dataset)}")
model = Supersimplenet(visualizer=True)
engine = Engine(max_epochs=1, accelerator="gpu", logger=tensorboard_logger, log_every_n_steps=1)
engine.fit(model, datamodule)
engine.export(export_type="torch", export_root=f"exports-featres/SuperSimplenet/{dataset_name}", model=model, model_file_name=dataset_name)
Beta Was this translation helpful? Give feedback.
All reactions