Facebook
From BORSA KAPLANI, 3 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 207
  1. import os
  2. from collections import defaultdict
  3.  
  4. def count_images_in_subfolders(root_path):
  5.     result = defaultdict(int)
  6.  
  7.     for foldername, subfolders, filenames in os.walk(root_path):
  8.         image_count = sum(1 for filename in filenames if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')))
  9.         result[foldername] += image_count
  10.  
  11.     for folder, count in result.items():
  12.         print(f"{folder} = {count}")
  13.  
  14. # Kullanım örneği
  15. path = "/content/drive/MyDrive/Dataset/kompozisyon_dataset"
  16. count_images_in_subfolders(path)
  17.