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

Refactor/extensions custom dataset #1562

Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ dataset:
normal_test_dir: null # name of the folder containing normal test images.
task: segmentation # classification or segmentation
mask: <path/to/mask/annotations> #optional
extensions: null
extensions: null # .ext or [.ext1, .ext2, ...]
split_ratio: 0.2 # ratio of the normal images that will be used to create a test split
image_size: 256
train_batch_size: 32
Expand Down
5 changes: 4 additions & 1 deletion src/anomalib/data/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ def _prepare_files_labels(
if isinstance(extensions, str):
extensions = (extensions,)

if not all(extension.startswith(".") for extension in extensions):
raise RuntimeError(f"All extensions {extensions} must start with the dot")

filenames = [
f
for f in path.glob("**/*")
if f.suffix in extensions and not f.is_dir() and not any(part.startswith(".") for part in f.parts)
]
if not filenames:
raise RuntimeError(f"Found 0 {path_type} images in {path}")
raise RuntimeError(f"Found 0 {path_type} images in {path} with extensions {extensions}")

labels = [path_type] * len(filenames)

Expand Down
Loading