質問編集履歴
3
UbuntuCleanerでは解決せず
title
CHANGED
File without changes
|
body
CHANGED
@@ -69,4 +69,4 @@
|
|
69
69
|
キャッシュから読み込まれているのかと思い、仮想環境のすべてのpycファイルを削除しましたが、やはり上書き保存前の情報のままでした。
|
70
70
|
|
71
71
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
72
|
-
|
72
|
+
UbuntuCleanerでシステムワイドにcacheを消しましたが古い内容を読み込むままでした。
|
2
作成コードを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -55,51 +55,12 @@
|
|
55
55
|
def _to_one_hot(self,name):
|
56
56
|
one_hot_vector = [0] * self.num_classes
|
57
57
|
if name == 'nerve':
|
58
|
-
one_hot_vector[0] = 1
|
58
|
+
one_hot_vector[0] = 1
|
59
|
-
#elif name == 'bicycle':
|
60
|
-
# one_hot_vector[1] = 1
|
61
|
-
#elif name == 'bird':
|
62
|
-
# one_hot_vector[2] = 1
|
63
|
-
#elif name == 'boat':
|
64
|
-
# one_hot_vector[3] = 1
|
65
|
-
#elif name == 'bottle':
|
66
|
-
# one_hot_vector[4] = 1
|
67
|
-
#elif name == 'bus':
|
68
|
-
# one_hot_vector[5] = 1
|
69
|
-
#elif name == 'car':
|
70
|
-
# one_hot_vector[6] = 1
|
71
|
-
#elif name == 'cat':
|
72
|
-
# one_hot_vector[7] = 1
|
73
|
-
#elif name == 'chair':
|
74
|
-
# one_hot_vector[8] = 1
|
75
|
-
#elif name == 'cow':
|
76
|
-
# one_hot_vector[9] = 1
|
77
|
-
#elif name == 'diningtable':
|
78
|
-
# one_hot_vector[10] = 1
|
79
|
-
#elif name == 'dog':
|
80
|
-
# one_hot_vector[11] = 1
|
81
|
-
#elif name == 'horse':
|
82
|
-
# one_hot_vector[12] = 1
|
83
|
-
#elif name == 'motorbike':
|
84
|
-
# one_hot_vector[13] = 1
|
85
|
-
#elif name == 'person':
|
86
|
-
# one_hot_vector[14] = 1
|
87
|
-
#elif name == 'pottedplant':
|
88
|
-
# one_hot_vector[15] = 1
|
89
|
-
#elif name == 'sheep':
|
90
|
-
# one_hot_vector[16] = 1
|
91
|
-
#elif name == 'sofa':
|
92
|
-
# one_hot_vector[17] = 1
|
93
|
-
#elif name == 'train':
|
94
|
-
# one_hot_vector[18] = 1
|
95
|
-
#elif name == 'tvmonitor':
|
96
|
-
# one_hot_vector[19] = 1
|
97
59
|
else:
|
98
60
|
print('unknown label: %s' %name)
|
99
61
|
|
100
62
|
return one_hot_vector
|
101
63
|
|
102
|
-
## example on how to use it
|
103
64
|
import pickle
|
104
65
|
data = XML_preprocessor('/home/owner/data/VOCdevkit/VOC2019/Annotations/').data
|
105
66
|
pickle.dump(data,open('/home/owner/data/VOCdevkit/VOC2019/VOC2019.pkl','wb'))
|
1
修正コード全体を貼り付けます。
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,8 +10,100 @@
|
|
10
10
|
ファイル名、物体の位置とクラス名が記載されているxmlファイルに間違いがあったためgeditで訂正・上書き保存しました。pklファイルを確認すると上書き保存する前の間違った情報が反映されていました。
|
11
11
|
|
12
12
|
###該当のソースコード
|
13
|
-
Python3.5, Ubuntu14.04, Anaconda3による仮想環境
|
13
|
+
Python3.5, Ubuntu14.04, Anaconda3による仮想環境。
|
14
|
+
1クラス判別のため、それ以外のクラスをコメントアウトし、一番下の3行から#を外しました。
|
14
15
|
|
16
|
+
import numpy as np
|
17
|
+
import os
|
18
|
+
from xml.etree import ElementTree
|
19
|
+
|
20
|
+
class XML_preprocessor(object):
|
21
|
+
|
22
|
+
def __init__(self, data_path):
|
23
|
+
self.path_prefix = data_path
|
24
|
+
self.num_classes = 1
|
25
|
+
self.data = dict()
|
26
|
+
self._preprocess_XML()
|
27
|
+
|
28
|
+
def _preprocess_XML(self):
|
29
|
+
filenames = os.listdir(self.path_prefix)
|
30
|
+
for filename in filenames:
|
31
|
+
tree = ElementTree.parse(self.path_prefix + filename)
|
32
|
+
root = tree.getroot()
|
33
|
+
bounding_boxes = []
|
34
|
+
one_hot_classes = []
|
35
|
+
size_tree = root.find('size')
|
36
|
+
width = float(size_tree.find('width').text)
|
37
|
+
height = float(size_tree.find('height').text)
|
38
|
+
for object_tree in root.findall('object'):
|
39
|
+
for bounding_box in object_tree.iter('bndbox'):
|
40
|
+
xmin = float(bounding_box.find('xmin').text)/width
|
41
|
+
ymin = float(bounding_box.find('ymin').text)/height
|
42
|
+
xmax = float(bounding_box.find('xmax').text)/width
|
43
|
+
ymax = float(bounding_box.find('ymax').text)/height
|
44
|
+
bounding_box = [xmin,ymin,xmax,ymax]
|
45
|
+
bounding_boxes.append(bounding_box)
|
46
|
+
class_name = object_tree.find('name').text
|
47
|
+
one_hot_class = self._to_one_hot(class_name)
|
48
|
+
one_hot_classes.append(one_hot_class)
|
49
|
+
image_name = root.find('filename').text
|
50
|
+
bounding_boxes = np.asarray(bounding_boxes)
|
51
|
+
one_hot_classes = np.asarray(one_hot_classes)
|
52
|
+
image_data = np.hstack((bounding_boxes, one_hot_classes))
|
53
|
+
self.data[image_name] = image_data
|
54
|
+
|
55
|
+
def _to_one_hot(self,name):
|
56
|
+
one_hot_vector = [0] * self.num_classes
|
57
|
+
if name == 'nerve':
|
58
|
+
one_hot_vector[0] = 1
|
59
|
+
#elif name == 'bicycle':
|
60
|
+
# one_hot_vector[1] = 1
|
61
|
+
#elif name == 'bird':
|
62
|
+
# one_hot_vector[2] = 1
|
63
|
+
#elif name == 'boat':
|
64
|
+
# one_hot_vector[3] = 1
|
65
|
+
#elif name == 'bottle':
|
66
|
+
# one_hot_vector[4] = 1
|
67
|
+
#elif name == 'bus':
|
68
|
+
# one_hot_vector[5] = 1
|
69
|
+
#elif name == 'car':
|
70
|
+
# one_hot_vector[6] = 1
|
71
|
+
#elif name == 'cat':
|
72
|
+
# one_hot_vector[7] = 1
|
73
|
+
#elif name == 'chair':
|
74
|
+
# one_hot_vector[8] = 1
|
75
|
+
#elif name == 'cow':
|
76
|
+
# one_hot_vector[9] = 1
|
77
|
+
#elif name == 'diningtable':
|
78
|
+
# one_hot_vector[10] = 1
|
79
|
+
#elif name == 'dog':
|
80
|
+
# one_hot_vector[11] = 1
|
81
|
+
#elif name == 'horse':
|
82
|
+
# one_hot_vector[12] = 1
|
83
|
+
#elif name == 'motorbike':
|
84
|
+
# one_hot_vector[13] = 1
|
85
|
+
#elif name == 'person':
|
86
|
+
# one_hot_vector[14] = 1
|
87
|
+
#elif name == 'pottedplant':
|
88
|
+
# one_hot_vector[15] = 1
|
89
|
+
#elif name == 'sheep':
|
90
|
+
# one_hot_vector[16] = 1
|
91
|
+
#elif name == 'sofa':
|
92
|
+
# one_hot_vector[17] = 1
|
93
|
+
#elif name == 'train':
|
94
|
+
# one_hot_vector[18] = 1
|
95
|
+
#elif name == 'tvmonitor':
|
96
|
+
# one_hot_vector[19] = 1
|
97
|
+
else:
|
98
|
+
print('unknown label: %s' %name)
|
99
|
+
|
100
|
+
return one_hot_vector
|
101
|
+
|
102
|
+
## example on how to use it
|
103
|
+
import pickle
|
104
|
+
data = XML_preprocessor('/home/owner/data/VOCdevkit/VOC2019/Annotations/').data
|
105
|
+
pickle.dump(data,open('/home/owner/data/VOCdevkit/VOC2019/VOC2019.pkl','wb'))
|
106
|
+
|
15
107
|
###試したこと
|
16
108
|
キャッシュから読み込まれているのかと思い、仮想環境のすべてのpycファイルを削除しましたが、やはり上書き保存前の情報のままでした。
|
17
109
|
|