-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsplit_dataset.py
41 lines (36 loc) · 1.36 KB
/
split_dataset.py
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
41
import os
import shutil
# 디렉토리 경로 설정
train_images_dir = "/root/dataset/train/images"
train_labels_dir = "/root/dataset/train/labels"
val_images_dir = "/root/dataset/val/images"
val_labels_dir = "/root/dataset/val/labels"
# 이동할 파일 번호 범위 설정
start_num = 14827
end_num = 16993
# val/images 및 val/labels 폴더가 없을 경우 생성
os.makedirs(val_images_dir, exist_ok=True)
os.makedirs(val_labels_dir, exist_ok=True)
# 이미지 파일 이동
for num in range(start_num, end_num + 1):
image_filename = f"{num:010d}.jpg"
image_src = os.path.join(train_images_dir, image_filename)
image_dst = os.path.join(val_images_dir, image_filename)
# 파일이 존재하면 이동
if os.path.exists(image_src):
shutil.move(image_src, image_dst)
print(f"Moved {image_src} to {image_dst}")
else:
print(f"Image file {image_src} not found.")
# 라벨 파일 이동
for num in range(start_num, end_num + 1):
label_filename = f"{num:010d}.txt"
label_src = os.path.join(train_labels_dir, label_filename)
label_dst = os.path.join(val_labels_dir, label_filename)
# 파일이 존재하면 이동
if os.path.exists(label_src):
shutil.move(label_src, label_dst)
print(f"Moved {label_src} to {label_dst}")
else:
continue
#print(f"Label file {label_src} not found.")