Mini-ImageNet / src /collection /select_60_images.py
ImAMJayKIM's picture
Upload 96 files
c1596ac verified
Raw
History Blame Contribute Delete
2.77 kB
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์ „์ฒด ์ •๋ฆฌ ์™„๋ฃŒ!")