Skip to content

Commit

Permalink
Refactor/extensions custom dataset (#1562)
Browse files Browse the repository at this point in the history
* Explanation how to use extension names in the config file

* Added information about extensions to the error message and control of the user input

* Easier to read code

* Replacing assert with raise
  • Loading branch information
abc-125 authored Jan 8, 2024
1 parent df50c0b commit 470bb86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 470bb86

Please sign in to comment.