-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit_data.py
39 lines (28 loc) · 901 Bytes
/
split_data.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
import os
import shutil
folder = 'Dataset/training'
images = []
labels = []
fileList = os.listdir(folder)
os.mkdir(f'{folder}/train')
os.mkdir(f'{folder}/validate')
for file in fileList:
fileName = os.path.splitext(file)[0]
imgExt = os.path.splitext(file)[1]
if imgExt == '.jpg':
images.append(file)
labels.append(f'{fileName}.txt')
data_train_img = images[0:int(len(images)*0.7)]
data_train_labels = labels[0:int(len(labels)*0.7)]
data_validate_img = images[int(len(images)*0.7):int(len(images))]
data_validate_labels = labels[int(len(labels)*0.7):int(len(labels))]
def moveFiles(curLoc,sourceLoc):
for i in curLoc:
source = f'{folder}/{i}'
dest = f'{folder}/{sourceLoc}/{i}'
shutil.copy(source,dest)
os.remove(source)
moveFiles(data_train_img,'train')
moveFiles(data_train_labels,'train')
moveFiles(data_validate_img,'validate')
moveFiles(data_validate_labels,'validate')