[Bug]: Training fails with dataloader #1933
Replies: 6 comments
-
Hi! I had similar issue before and solved it by adding datamodule = Folder(
name="hazelnut_toy",
root="/home/citriot/Downloads/hazelnut_toy",
normal_dir="good",
abnormal_dir="crack",
mask_dir="mask/crack",
normal_split_ratio=0.2,
image_size=(256,256)
) |
Beta Was this translation helpful? Give feedback.
-
Sure that works, but with a custom dataset with the image_size parameter added, I'm still getting similar errors. I did try using torchvision transform to resize the images but that didn't work |
Beta Was this translation helpful? Give feedback.
-
Have you solved it? I'm also having this issue and hope I can get your help |
Beta Was this translation helpful? Give feedback.
-
@stevejonathancitriot, can you elaborate what sort of similar issues are you getting? I'm trying the reproduce the issue, but it works here |
Beta Was this translation helpful? Give feedback.
-
When I try the setup you provided above, I can train and test the model ![]() |
Beta Was this translation helpful? Give feedback.
-
This is because data modules expect transforms or image-size arguments. When none of them is passed, the transforms are read from the model. If you instantiate the datamodule without these arguments and play with the datamodule to check the dataset items, you would get the error you shared. However, if you create a model and engine and train, it should work since the transforms will be obtained from model. Converting this to a Q&A since this is not an issue |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I get an error when I try to access the dataloader items with the hazelnut_toy dataset
Dataset
Folder
Model
PatchCore
Steps to reproduce the behavior
Installed anomalib with pip and "anomalib install"
Error when running this code
from anomalib.data import Folder
Create the datamodule
datamodule = Folder(
name="hazelnut_toy",
root="/home/citriot/Downloads/hazelnut_toy",
normal_dir="good",
abnormal_dir="crack",
mask_dir="mask/crack",
normal_split_ratio=0.2,
)
Setup the datamodule
datamodule.setup()
train_dataset = datamodule.train_data
val_dataset = datamodule.val_data
test_dataset = datamodule.test_data
Access the dataloaders
train_dataloader = datamodule.train_dataloader()
val_dataloader = datamodule.val_dataloader()
test_dataloader = datamodule.test_dataloader()
i, train_data = next(enumerate(datamodule.train_dataloader()))
print(train_data.keys(), train_data['image'].shape)
# dict_keys(['image_path', 'label', 'image', 'mask_path', 'mask'])
i, val_data = next(enumerate(datamodule.val_dataloader()))
print(val_data.keys(), val_data['image'].shape)
# dict_keys(['image_path', 'label', 'image', 'mask_path', 'mask'])
i, test_data = next(enumerate(datamodule.test_dataloader()))
print(test_data.keys(), test_data['image'].shape)
# dict_keys(['image_path', 'label', 'image', 'mask_path', 'mask'])
from anomalib.models import Patchcore
from anomalib.engine import Engine
Create the model and engine
model = Patchcore()
engine = Engine()
Train a Patchcore model on the given datamodule
engine.train(datamodule=datamodule, model=model)
OS information
OS information:
Expected behavior
Model would train?
Screenshots
No response
Pip/GitHub
pip
What version/branch did you use?
1.0
Configuration YAML
/
Logs
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions