-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectImg.py
More file actions
40 lines (30 loc) · 1.2 KB
/
SelectImg.py
File metadata and controls
40 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import shutil
import random
from tqdm import tqdm
def CopyRandomImages(srcFolder, dstFolder, percent=10):
imgExts = ['.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff']
files = [f for f in os.listdir(srcFolder)
if os.path.splitext(f)[1].lower() in imgExts
and os.path.isfile(os.path.join(srcFolder, f))]
total = len(files)
if total == 0:
print("이미지 파일이 없습니다.")
return
count = max(1, round(total * percent / 100))
sampled = random.sample(files, count)
os.makedirs(dstFolder, exist_ok=True)
for f in tqdm(sampled, desc="이미지 복사 중", ncols=70):
srcPath = os.path.join(srcFolder, f)
dstPath = os.path.join(dstFolder, f)
shutil.copy2(srcPath, dstPath)
print(f"총 {total}장 중 {count}장({percent}%)을 복사 완료")
for i in range(0, 10):
srcFolder = f'D:\\Machine Learning\\mnist_png\\training\\{i}'
dstFolder = f'D:\\Machine Learning\\mnist_wish\\{i}'
print(i)
CopyRandomImages(srcFolder, dstFolder)
srcFolder = r'D:\Machine Learning\mnist_png\training\NaN'
dstFolder = r'D:\Machine Learning\mnist_wish\NaN'
print("NaN")
CopyRandomImages(srcFolder, dstFolder)