Skip to content
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
14 changes: 9 additions & 5 deletions src/anomalib/data/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
normal
"""

import logging
import os
import re
from enum import Enum
from pathlib import Path

from torchvision.datasets.folder import IMG_EXTENSIONS

logger = logging.getLogger(__name__)


class DirType(str, Enum):
"""Directory type names for organizing anomaly detection datasets.
Expand Down Expand Up @@ -107,11 +110,12 @@ def _prepare_files_labels(
msg = f"All extensions {extensions} must start with the dot"
raise RuntimeError(msg)

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)
]
filenames = [f for f in path.glob("**/*") if f.suffix in extensions and not f.is_dir()]
# list of files that are in hidden directories or are hidden files themselves
hidden_files = [f for f in filenames if any(part.startswith(".") for part in f.parts)]
if hidden_files:
logger.warning(f"{len(hidden_files)} hidden files found in {path}. Please make sure this is intended.")

if not filenames:
msg = f"Found 0 {path_type} images in {path} with extensions {extensions}"
raise RuntimeError(msg)
Expand Down