Spaces:
Sleeping
Sleeping
| import os | |
| import random | |
| import shutil | |
| # ================================ | |
| # 0. ์ค์ | |
| # ================================ | |
| TARGET_COUNT = 60 | |
| MIN_RES = 128 # ํด์๋ 128 | |
| PREFIX = "kg" | |
| BASE_DIR = "./data/raw" | |
| # ================================ | |
| # 1. ๊ฒฝ๋ก | |
| # ================================ | |
| DATA_DIR = r"C:\Users\qud46\Desktop\raw_kg" | |
| # ================================ | |
| # 2. ํด๋์ค ๋ชฉ๋ก | |
| # ================================ | |
| CLASS_LIST = [ | |
| # ์์ ๋ฐ ์์ฌ๋ฃ | |
| "pizza","hamburger","sushi","pasta","salad", | |
| "steak","cup_cake","sandwich","waffle","dumpling", | |
| # ๋๋ฌผ | |
| "golden-retriever","bulldog","siamese-cat", | |
| "persian-cat","elephant","sheep","horse", | |
| "penguin","butterfly","squirrel", | |
| # ๊ฝ | |
| "rose","sunflower","daisy","tulip","dandelion", | |
| "lily","lavender","orchid","iris","marigold","aster", | |
| # ๊ณผ์ผ | |
| "apple","banana","strawberry","orange", | |
| "carrot","tomato","cucumber", | |
| # ํ๊ฒ | |
| "car","bicycle","motorcycle","airplane","bus", | |
| # ํจ์ ๋ฐ ์กํ | |
| "t-shirt","sneakers","earrings","glasses", | |
| "pants","bracelet","necklace" | |
| ] | |
| print("ํด๋์ค๋ณ ์ด๋ฏธ์ง 60์ฅ ๋ง์ถ๊ธฐ ์์\n") | |
| # ================================ | |
| # 3. ๋ฉ์ธ ๋ก์ง | |
| # ================================ | |
| for cls in CLASS_LIST: | |
| cls_path = os.path.join(DATA_DIR, cls) | |
| if not os.path.exists(cls_path): | |
| print(f"{cls}: ํด๋ ์์ (skip)") | |
| continue | |
| # ์ด๋ฏธ์ง ํ์ผ ๋ชฉ๋ก | |
| images = [ | |
| f for f in os.listdir(cls_path) | |
| if os.path.isfile(os.path.join(cls_path, f)) | |
| ] | |
| current_count = len(images) | |
| print( | |
| f"{cls}: ํ์ฌ {current_count}์ฅ " | |
| f"โ ๋ชฉํ {TARGET_COUNT}์ฅ" | |
| ) | |
| # ================================ | |
| # 1) 60์ฅ ์ด๊ณผ โ ๋๋ค ์ญ์ | |
| # ================================ | |
| if current_count > TARGET_COUNT: | |
| delete_count = current_count - TARGET_COUNT | |
| to_delete = random.sample( | |
| images, | |
| delete_count | |
| ) | |
| for file in to_delete: | |
| file_path = os.path.join(cls_path, file) | |
| try: | |
| os.remove(file_path) | |
| except: | |
| continue | |
| print(f" โ {delete_count}์ฅ ์ญ์ ์๋ฃ") | |
| # ================================ | |
| # 2) 60์ฅ ๋ฏธ๋ง โ ๋ถ์กฑ ๊ฐ์ ์ถ๋ ฅ | |
| # ================================ | |
| elif current_count < TARGET_COUNT: | |
| need_count = TARGET_COUNT - current_count | |
| print( | |
| f" โ {need_count}์ฅ ๋ถ์กฑ " | |
| f"(์ถ๊ฐ ์์ง ํ์)" | |
| ) | |
| # ================================ | |
| # 3) ์ ํํ 60์ฅ | |
| # ================================ | |
| else: | |
| print(" โ ์ด๋ฏธ 60์ฅ ์๋ฃ") | |
| print("\n์ ์ฒด ์ ๋ฆฌ ์๋ฃ!") |