-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataSplit.py
40 lines (29 loc) · 1.38 KB
/
dataSplit.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
import os
import random
import shutil
import cv2
IMAGE_PATH = "archive/image"
ANNOTATION_PATH = "annotation"
output_test = "datasets/test"
output_val = "datasets/val"
pathDir = os.listdir(IMAGE_PATH)
# print(pathDir)
filenumber = len(pathDir)
picknumber1 = int(filenumber * 0.2)
test_sample = random.sample(pathDir, picknumber1)
for file_name in test_sample:
shutil.move(IMAGE_PATH + "/" + file_name, output_test + "/images/" + file_name)
shutil.move(ANNOTATION_PATH + "/" + os.path.splitext(file_name)[0] + ".txt", output_test + "/labels/" + os.path.splitext(file_name)[0] + ".txt")
pathDir = os.listdir(IMAGE_PATH)
picknumber2 = int(filenumber * 0.2)
val_sample = random.sample(pathDir, picknumber2)
for file_name in val_sample:
shutil.move(IMAGE_PATH + "/" + file_name, output_val + "/images/" + file_name)
shutil.move(ANNOTATION_PATH + "/" + os.path.splitext(file_name)[0] + ".txt", output_val + "/labels/" + os.path.splitext(file_name)[0] + ".txt")
# pathDir = os.listdir("datasets/test/images")
# picknumber = int(filenumber * 0.05)
# val_sample = random.sample(pathDir, picknumber)
# for file_name in val_sample:
# shutil.move("datasets/test/images" + "/" + file_name, "datasets/train/images/" + file_name)
# shutil.move("datasets/test/labels/" + os.path.splitext(file_name)[0] + ".txt", "datasets/train/labels/" + os.path.splitext(file_name)[0] + ".txt")
print("done")