質問編集履歴
3
UbuntuCleanerでは解決せず
test
CHANGED
File without changes
|
test
CHANGED
@@ -140,4 +140,4 @@
|
|
140
140
|
|
141
141
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
142
142
|
|
143
|
-
|
143
|
+
UbuntuCleanerでシステムワイドにcacheを消しましたが古い内容を読み込むままでした。
|
2
作成コードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,83 +112,7 @@
|
|
112
112
|
|
113
113
|
if name == 'nerve':
|
114
114
|
|
115
|
-
one_hot_vector[0] = 1
|
115
|
+
one_hot_vector[0] = 1
|
116
|
-
|
117
|
-
#elif name == 'bicycle':
|
118
|
-
|
119
|
-
# one_hot_vector[1] = 1
|
120
|
-
|
121
|
-
#elif name == 'bird':
|
122
|
-
|
123
|
-
# one_hot_vector[2] = 1
|
124
|
-
|
125
|
-
#elif name == 'boat':
|
126
|
-
|
127
|
-
# one_hot_vector[3] = 1
|
128
|
-
|
129
|
-
#elif name == 'bottle':
|
130
|
-
|
131
|
-
# one_hot_vector[4] = 1
|
132
|
-
|
133
|
-
#elif name == 'bus':
|
134
|
-
|
135
|
-
# one_hot_vector[5] = 1
|
136
|
-
|
137
|
-
#elif name == 'car':
|
138
|
-
|
139
|
-
# one_hot_vector[6] = 1
|
140
|
-
|
141
|
-
#elif name == 'cat':
|
142
|
-
|
143
|
-
# one_hot_vector[7] = 1
|
144
|
-
|
145
|
-
#elif name == 'chair':
|
146
|
-
|
147
|
-
# one_hot_vector[8] = 1
|
148
|
-
|
149
|
-
#elif name == 'cow':
|
150
|
-
|
151
|
-
# one_hot_vector[9] = 1
|
152
|
-
|
153
|
-
#elif name == 'diningtable':
|
154
|
-
|
155
|
-
# one_hot_vector[10] = 1
|
156
|
-
|
157
|
-
#elif name == 'dog':
|
158
|
-
|
159
|
-
# one_hot_vector[11] = 1
|
160
|
-
|
161
|
-
#elif name == 'horse':
|
162
|
-
|
163
|
-
# one_hot_vector[12] = 1
|
164
|
-
|
165
|
-
#elif name == 'motorbike':
|
166
|
-
|
167
|
-
# one_hot_vector[13] = 1
|
168
|
-
|
169
|
-
#elif name == 'person':
|
170
|
-
|
171
|
-
# one_hot_vector[14] = 1
|
172
|
-
|
173
|
-
#elif name == 'pottedplant':
|
174
|
-
|
175
|
-
# one_hot_vector[15] = 1
|
176
|
-
|
177
|
-
#elif name == 'sheep':
|
178
|
-
|
179
|
-
# one_hot_vector[16] = 1
|
180
|
-
|
181
|
-
#elif name == 'sofa':
|
182
|
-
|
183
|
-
# one_hot_vector[17] = 1
|
184
|
-
|
185
|
-
#elif name == 'train':
|
186
|
-
|
187
|
-
# one_hot_vector[18] = 1
|
188
|
-
|
189
|
-
#elif name == 'tvmonitor':
|
190
|
-
|
191
|
-
# one_hot_vector[19] = 1
|
192
116
|
|
193
117
|
else:
|
194
118
|
|
@@ -199,8 +123,6 @@
|
|
199
123
|
return one_hot_vector
|
200
124
|
|
201
125
|
|
202
|
-
|
203
|
-
## example on how to use it
|
204
126
|
|
205
127
|
import pickle
|
206
128
|
|
1
修正コード全体を貼り付けます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,191 @@
|
|
22
22
|
|
23
23
|
###該当のソースコード
|
24
24
|
|
25
|
-
Python3.5, Ubuntu14.04, Anaconda3による仮想環境
|
25
|
+
Python3.5, Ubuntu14.04, Anaconda3による仮想環境。
|
26
|
+
|
27
|
+
1クラス判別のため、それ以外のクラスをコメントアウトし、一番下の3行から#を外しました。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
import numpy as np
|
32
|
+
|
33
|
+
import os
|
34
|
+
|
35
|
+
from xml.etree import ElementTree
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
class XML_preprocessor(object):
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
def __init__(self, data_path):
|
44
|
+
|
45
|
+
self.path_prefix = data_path
|
46
|
+
|
47
|
+
self.num_classes = 1
|
48
|
+
|
49
|
+
self.data = dict()
|
50
|
+
|
51
|
+
self._preprocess_XML()
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def _preprocess_XML(self):
|
56
|
+
|
57
|
+
filenames = os.listdir(self.path_prefix)
|
58
|
+
|
59
|
+
for filename in filenames:
|
60
|
+
|
61
|
+
tree = ElementTree.parse(self.path_prefix + filename)
|
62
|
+
|
63
|
+
root = tree.getroot()
|
64
|
+
|
65
|
+
bounding_boxes = []
|
66
|
+
|
67
|
+
one_hot_classes = []
|
68
|
+
|
69
|
+
size_tree = root.find('size')
|
70
|
+
|
71
|
+
width = float(size_tree.find('width').text)
|
72
|
+
|
73
|
+
height = float(size_tree.find('height').text)
|
74
|
+
|
75
|
+
for object_tree in root.findall('object'):
|
76
|
+
|
77
|
+
for bounding_box in object_tree.iter('bndbox'):
|
78
|
+
|
79
|
+
xmin = float(bounding_box.find('xmin').text)/width
|
80
|
+
|
81
|
+
ymin = float(bounding_box.find('ymin').text)/height
|
82
|
+
|
83
|
+
xmax = float(bounding_box.find('xmax').text)/width
|
84
|
+
|
85
|
+
ymax = float(bounding_box.find('ymax').text)/height
|
86
|
+
|
87
|
+
bounding_box = [xmin,ymin,xmax,ymax]
|
88
|
+
|
89
|
+
bounding_boxes.append(bounding_box)
|
90
|
+
|
91
|
+
class_name = object_tree.find('name').text
|
92
|
+
|
93
|
+
one_hot_class = self._to_one_hot(class_name)
|
94
|
+
|
95
|
+
one_hot_classes.append(one_hot_class)
|
96
|
+
|
97
|
+
image_name = root.find('filename').text
|
98
|
+
|
99
|
+
bounding_boxes = np.asarray(bounding_boxes)
|
100
|
+
|
101
|
+
one_hot_classes = np.asarray(one_hot_classes)
|
102
|
+
|
103
|
+
image_data = np.hstack((bounding_boxes, one_hot_classes))
|
104
|
+
|
105
|
+
self.data[image_name] = image_data
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def _to_one_hot(self,name):
|
110
|
+
|
111
|
+
one_hot_vector = [0] * self.num_classes
|
112
|
+
|
113
|
+
if name == 'nerve':
|
114
|
+
|
115
|
+
one_hot_vector[0] = 1
|
116
|
+
|
117
|
+
#elif name == 'bicycle':
|
118
|
+
|
119
|
+
# one_hot_vector[1] = 1
|
120
|
+
|
121
|
+
#elif name == 'bird':
|
122
|
+
|
123
|
+
# one_hot_vector[2] = 1
|
124
|
+
|
125
|
+
#elif name == 'boat':
|
126
|
+
|
127
|
+
# one_hot_vector[3] = 1
|
128
|
+
|
129
|
+
#elif name == 'bottle':
|
130
|
+
|
131
|
+
# one_hot_vector[4] = 1
|
132
|
+
|
133
|
+
#elif name == 'bus':
|
134
|
+
|
135
|
+
# one_hot_vector[5] = 1
|
136
|
+
|
137
|
+
#elif name == 'car':
|
138
|
+
|
139
|
+
# one_hot_vector[6] = 1
|
140
|
+
|
141
|
+
#elif name == 'cat':
|
142
|
+
|
143
|
+
# one_hot_vector[7] = 1
|
144
|
+
|
145
|
+
#elif name == 'chair':
|
146
|
+
|
147
|
+
# one_hot_vector[8] = 1
|
148
|
+
|
149
|
+
#elif name == 'cow':
|
150
|
+
|
151
|
+
# one_hot_vector[9] = 1
|
152
|
+
|
153
|
+
#elif name == 'diningtable':
|
154
|
+
|
155
|
+
# one_hot_vector[10] = 1
|
156
|
+
|
157
|
+
#elif name == 'dog':
|
158
|
+
|
159
|
+
# one_hot_vector[11] = 1
|
160
|
+
|
161
|
+
#elif name == 'horse':
|
162
|
+
|
163
|
+
# one_hot_vector[12] = 1
|
164
|
+
|
165
|
+
#elif name == 'motorbike':
|
166
|
+
|
167
|
+
# one_hot_vector[13] = 1
|
168
|
+
|
169
|
+
#elif name == 'person':
|
170
|
+
|
171
|
+
# one_hot_vector[14] = 1
|
172
|
+
|
173
|
+
#elif name == 'pottedplant':
|
174
|
+
|
175
|
+
# one_hot_vector[15] = 1
|
176
|
+
|
177
|
+
#elif name == 'sheep':
|
178
|
+
|
179
|
+
# one_hot_vector[16] = 1
|
180
|
+
|
181
|
+
#elif name == 'sofa':
|
182
|
+
|
183
|
+
# one_hot_vector[17] = 1
|
184
|
+
|
185
|
+
#elif name == 'train':
|
186
|
+
|
187
|
+
# one_hot_vector[18] = 1
|
188
|
+
|
189
|
+
#elif name == 'tvmonitor':
|
190
|
+
|
191
|
+
# one_hot_vector[19] = 1
|
192
|
+
|
193
|
+
else:
|
194
|
+
|
195
|
+
print('unknown label: %s' %name)
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
return one_hot_vector
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
## example on how to use it
|
204
|
+
|
205
|
+
import pickle
|
206
|
+
|
207
|
+
data = XML_preprocessor('/home/owner/data/VOCdevkit/VOC2019/Annotations/').data
|
208
|
+
|
209
|
+
pickle.dump(data,open('/home/owner/data/VOCdevkit/VOC2019/VOC2019.pkl','wb'))
|
26
210
|
|
27
211
|
|
28
212
|
|