-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild_test_dataset.py
48 lines (34 loc) · 1.15 KB
/
build_test_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
42
43
44
45
46
import os
import numpy as np
import random
import shutil
data_folder = 'D:/DLCode/wgisd/data/'
train_masked_path = 'D:/DLCode/wgisd/train_masked.txt'
ROOT_DIR = os.path.abspath(".")
print(ROOT_DIR)
#create dataset folder
dataset_folder= os.path.sep.join([ROOT_DIR,"dataset"])
if not os.path.exists(dataset_folder):
os.makedirs(dataset_folder)
#build train dataset
dataset_folder_test= os.path.sep.join([dataset_folder,"test"])
if not os.path.exists(dataset_folder_test):
os.makedirs(dataset_folder_test)
# load the names of the images
with open(train_masked_path, 'r') as fp:
data_list = fp.readlines()
data_list = set([i[:-1] for i in data_list])
print(data_list)
i=0
files = os.listdir(data_folder)
for file in files:
# extract image names
filename, filename_ext = os.path.splitext(file)
if filename_ext == ".jpg":
if filename not in data_list:
i=i+1
image_src_path = data_folder + filename + '.jpg'
image_dst_path = dataset_folder_test + os.sep + filename + '.jpg'
print("copy: ",image_src_path)
shutil.copy2(image_src_path,image_dst_path)
print("\n\ntest images:",i)