Do not modify your dataset just to match the code. First run the inspection script below. It tells you whether the expected class-folder structure already exists and prints the counts your review panel will ask for.
Expected local folder layout
Each immediate subfolder inside dataset/ becomes one classification label. Folder names are the class names.
Run inspect_dataset.py first. If images are nested under patient folders rather than class folders, reorganize only after confirming which parent folder is the medical label. The training script expects at least two class folders and four images in every class.
Supported formats: JPG, JPEG, PNG, BMP, TIF, and TIFF. The script prints total image count, class names, and a per-class count.
Create this file in your Python project
inspect_dataset.py
Read-only inspection; it does not rename, move, or alter images.
from pathlib import Path
IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"}
DATASET_DIR = Path("dataset")
def image_files(folder: Path):
return [path for path in folder.rglob("*") if path.suffix.lower() in IMAGE_EXTENSIONS]
def main():
if not DATASET_DIR.exists():
raise FileNotFoundError(f"Dataset folder not found: {DATASET_DIR.resolve()}")
class_dirs = sorted(path for path in DATASET_DIR.iterdir() if path.is_dir())
if not class_dirs:
raise ValueError("No class folders found. Put one folder per class inside dataset/.")
total_images = 0
print("\nDataset inspection")
print("-" * 40)
print("Class names:", [folder.name for folder in class_dirs])
for class_dir in class_dirs:
count = len(image_files(class_dir))
total_images += count
print(f"{class_dir.name}: {count} images")
print(f"Total images: {total_images}")
if __name__ == "__main__":
main()