forked from Profrog/yolo_scan_algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeset2.py
More file actions
80 lines (53 loc) · 1.75 KB
/
makeset2.py
File metadata and controls
80 lines (53 loc) · 1.75 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import datetime
import os
import shutil
from pathlib import Path
import imghdr
#global name_file
#name_file = "coco.names"
#data1 = open(name_file, 'a')
now = datetime.datetime.now()
global path
path = "t_image/"
global search1
search1 = "detourl" + "_" + str(now.strftime("%m")) + str(now.strftime("%d"))
if os.path.exists(search1):
print("already has file")
else:
os.makedirs(search1)
file_list = os.listdir(path)
file_list_py = [file for file in file_list if file.endswith(".txt")]
search_num = 0
print ("file_list: {}".format(file_list_py))
for test1 in file_list_py:
try:
with open(path + test1) as file:
label_dir = path + test1
if label_dir.find(".xml") >= 0:
label_dir2 = label_dir.replace(".xml","")
data_file = Path(label_dir)
data_file.rename(label_dir2)
label_dir = label_dir2
shutil.copy(label_dir, search1)
try:
shutil.copy(label_dir[0:len(label_dir) -4] + ".jpg", search1)
except:
try:
shutil.copy(label_dir[0:len(label_dir) -4] + ".jpeg", search1)
except:
try:
shutil.copy(label_dir[0:len(label_dir) -4] + ".png", search1)
except:
print("loading error")
search_num += 1
print("find dataset " + str(search_num) + "\n")
#print(label_dir[0:len(label_dir) -4] + "\n")
except:
print("error in " + test1 + "\n")
continue
write_data = search1 + ".txt"
filea = open(write_data, 'w+')
file_list2 = os.listdir(search1 + "/")
file_list_py2 = [file for file in file_list2 if file.endswith(".txt")]
print("all data_num is " + str(len(file_list_py2)) + "\n")
filea.write("all data_num is " + str(len(file_list_py2)) + "\n")