質問編集履歴
8
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -122,61 +122,31 @@
|
|
122
122
|
|
123
123
|
```
|
124
124
|
<?xml version="1.0"?>
|
125
|
-
|
126
125
|
-<annotation>
|
127
|
-
|
128
|
-
<folder>アノテーション</folder>
|
126
|
+
<folder>アノテーション</folder>
|
129
|
-
|
130
|
-
<filename>vegetable(1).JPG</filename>
|
127
|
+
<filename>vegetable(1).JPG</filename>
|
131
|
-
|
132
|
-
<path>C:\Users\isl\.spyder-py3\アノテーション\vegetable(1).JPG</path>
|
128
|
+
<path>C:\Users\isl\.spyder-py3\アノテーション\vegetable(1).JPG</path>
|
133
|
-
|
134
|
-
|
135
|
-
-<source>
|
129
|
+
-<source>
|
136
|
-
|
137
|
-
<database>Unknown</database>
|
130
|
+
<database>Unknown</database>
|
138
|
-
|
139
|
-
</source>
|
131
|
+
</source>
|
140
|
-
|
141
|
-
|
142
|
-
-<size>
|
132
|
+
-<size>
|
143
|
-
|
144
|
-
<width>661</width>
|
133
|
+
<width>661</width>
|
145
|
-
|
146
|
-
<height>838</height>
|
134
|
+
<height>838</height>
|
147
|
-
|
148
|
-
<depth>3</depth>
|
135
|
+
<depth>3</depth>
|
149
|
-
|
150
|
-
</size>
|
136
|
+
</size>
|
151
|
-
|
152
|
-
<segmented>0</segmented>
|
137
|
+
<segmented>0</segmented>
|
153
|
-
|
154
|
-
|
155
|
-
-<object>
|
138
|
+
-<object>
|
156
|
-
|
157
|
-
<name>beans</name>
|
139
|
+
<name>beans</name>
|
158
|
-
|
159
|
-
<pose>Unspecified</pose>
|
140
|
+
<pose>Unspecified</pose>
|
160
|
-
|
161
|
-
<truncated>0</truncated>
|
141
|
+
<truncated>0</truncated>
|
162
|
-
|
163
|
-
<difficult>0</difficult>
|
142
|
+
<difficult>0</difficult>
|
164
|
-
|
165
|
-
|
166
|
-
-<bndbox>
|
143
|
+
-<bndbox>
|
167
|
-
|
168
|
-
<xmin>43</xmin>
|
144
|
+
<xmin>43</xmin>
|
169
|
-
|
170
|
-
<ymin>199</ymin>
|
145
|
+
<ymin>199</ymin>
|
171
|
-
|
172
|
-
<xmax>511</xmax>
|
146
|
+
<xmax>511</xmax>
|
173
|
-
|
174
|
-
<ymax>755</ymax>
|
147
|
+
<ymax>755</ymax>
|
175
|
-
|
176
|
-
</bndbox>
|
148
|
+
</bndbox>
|
177
|
-
|
178
|
-
</object>
|
149
|
+
</object>
|
179
|
-
|
180
150
|
</annotation>
|
181
151
|
```
|
182
152
|
|
7
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -119,7 +119,66 @@
|
|
119
119
|
f.write("%s\n" % key)
|
120
120
|
print(key)
|
121
121
|
```
|
122
|
+
|
123
|
+
```
|
124
|
+
<?xml version="1.0"?>
|
125
|
+
|
126
|
+
-<annotation>
|
127
|
+
|
128
|
+
<folder>アノテーション</folder>
|
129
|
+
|
130
|
+
<filename>vegetable(1).JPG</filename>
|
131
|
+
|
122
|
-
|
132
|
+
<path>C:\Users\isl\.spyder-py3\アノテーション\vegetable(1).JPG</path>
|
133
|
+
|
134
|
+
|
135
|
+
-<source>
|
136
|
+
|
137
|
+
<database>Unknown</database>
|
138
|
+
|
139
|
+
</source>
|
140
|
+
|
141
|
+
|
142
|
+
-<size>
|
143
|
+
|
144
|
+
<width>661</width>
|
145
|
+
|
146
|
+
<height>838</height>
|
147
|
+
|
148
|
+
<depth>3</depth>
|
149
|
+
|
150
|
+
</size>
|
151
|
+
|
152
|
+
<segmented>0</segmented>
|
153
|
+
|
154
|
+
|
155
|
+
-<object>
|
156
|
+
|
157
|
+
<name>beans</name>
|
158
|
+
|
159
|
+
<pose>Unspecified</pose>
|
160
|
+
|
161
|
+
<truncated>0</truncated>
|
162
|
+
|
163
|
+
<difficult>0</difficult>
|
164
|
+
|
165
|
+
|
166
|
+
-<bndbox>
|
167
|
+
|
168
|
+
<xmin>43</xmin>
|
169
|
+
|
170
|
+
<ymin>199</ymin>
|
171
|
+
|
172
|
+
<xmax>511</xmax>
|
173
|
+
|
174
|
+
<ymax>755</ymax>
|
175
|
+
|
176
|
+
</bndbox>
|
177
|
+
|
178
|
+
</object>
|
179
|
+
|
180
|
+
</annotation>
|
181
|
+
```
|
123
182
|
|
124
183
|
|
125
184
|
|
6
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -71,7 +71,7 @@
|
|
71
71
|
addimgpath = parentpath + 'traffic_img/20170271403' #"Directory path with IMG files"
|
72
72
|
outputpath = parentpath + 'traffic_format4yolo' #"output folder for yolo format"
|
73
73
|
classes_txt = './traffic_classes.txt' #"File containing classes"
|
74
|
-
ext = '.
|
74
|
+
ext = '.JPG' #"Image file extension [.jpg or .png]"
|
75
75
|
|
76
76
|
|
77
77
|
if os.path.isfile(classes_txt):
|
@@ -80,9 +80,10 @@
|
|
80
80
|
classes = {k : v for (v, k) in enumerate(class_list)}
|
81
81
|
|
82
82
|
xmlPaths = glob(addxmlpath + "/*.xml")
|
83
|
+
print(xmlPaths)
|
83
84
|
#imgPaths = glob(addimgpath + "/*"+ext)
|
84
85
|
# file = glob.glob('/Users/isl/Desktop/xml2yolo-master - コピー/traffic_labe/20170271403/*.xml')
|
85
|
-
|
86
|
+
|
86
87
|
|
87
88
|
for xmlPath in xmlPaths:
|
88
89
|
tVocParseReader = PascalVocReader(xmlPath)
|
@@ -118,9 +119,8 @@
|
|
118
119
|
f.write("%s\n" % key)
|
119
120
|
print(key)
|
120
121
|
```
|
121
|
-

|
122
|
-

|
123
|
-

|
123
|
+
|
124
124
|
|
125
125
|
|
126
126
|
|
5
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[YOLOv5の物体検出](https://farml1.com/yolov5/#toc2)をしたいため、[アノテーションファイル変換](https://qiita.com/cv_carnavi/items/bd909df26d159401d166)を参考に.xmlから.txtに変換を試みています。
|
2
2
|
|
3
|
-
|
3
|
+
traffic_format4yoloにYOLO形式の.txtは出力されたのですが、中身が入っておらず空です。
|
4
4
|
サイト通りにしてエラーも出ていないので、なにがいけないのか分かりません。
|
5
5
|
アドバイスいただけると嬉しいです。
|
6
6
|
|
@@ -15,7 +15,6 @@
|
|
15
15
|
import codecs
|
16
16
|
import cv2
|
17
17
|
from glob import glob
|
18
|
-
import glob
|
19
18
|
import re
|
20
19
|
|
21
20
|
|
@@ -68,8 +67,8 @@
|
|
68
67
|
|
69
68
|
|
70
69
|
parentpath = './' #"Directory path with parent dir before xml_dir or img_dir"
|
71
|
-
addxmlpath = parentpath + 'traffic_label/201702
|
70
|
+
addxmlpath = parentpath + 'traffic_label/20170271403' #"Directory path with XML files"
|
72
|
-
addimgpath = parentpath + 'traffic_img/201702
|
71
|
+
addimgpath = parentpath + 'traffic_img/20170271403' #"Directory path with IMG files"
|
73
72
|
outputpath = parentpath + 'traffic_format4yolo' #"output folder for yolo format"
|
74
73
|
classes_txt = './traffic_classes.txt' #"File containing classes"
|
75
74
|
ext = '.jpg' #"Image file extension [.jpg or .png]"
|
@@ -80,7 +79,7 @@
|
|
80
79
|
class_list = f.read().strip().split()
|
81
80
|
classes = {k : v for (v, k) in enumerate(class_list)}
|
82
81
|
|
83
|
-
xmlPaths = glob
|
82
|
+
xmlPaths = glob(addxmlpath + "/*.xml")
|
84
83
|
#imgPaths = glob(addimgpath + "/*"+ext)
|
85
84
|
# file = glob.glob('/Users/isl/Desktop/xml2yolo-master - コピー/traffic_labe/20170271403/*.xml')
|
86
85
|
print(xmlPaths)
|
@@ -119,14 +118,13 @@
|
|
119
118
|
f.write("%s\n" % key)
|
120
119
|
print(key)
|
121
120
|
```
|
121
|
+

|
122
|
+

|
123
|
+

|
122
124
|
|
123
|
-
|
125
|
+
|
124
|
-
|
126
|
+
|
125
|
-
|
127
|
+
|
126
|
-

|
127
|
-

|
128
|
-

|
129
|
-

|
130
128
|
|
131
129
|
|
132
130
|
Windows、Anaconda
|
4
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -126,7 +126,7 @@
|
|
126
126
|

|
127
127
|

|
128
128
|

|
129
|
-
|
129
|
+

|
130
130
|
|
131
131
|
|
132
132
|
Windows、Anaconda
|
3
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,6 +15,10 @@
|
|
15
15
|
import codecs
|
16
16
|
import cv2
|
17
17
|
from glob import glob
|
18
|
+
import glob
|
19
|
+
import re
|
20
|
+
|
21
|
+
|
18
22
|
|
19
23
|
XML_EXT = '.xml'
|
20
24
|
ENCODE_METHOD = 'utf-8'
|
@@ -26,10 +30,6 @@
|
|
26
30
|
self.shapes = []
|
27
31
|
self.filepath = filepath
|
28
32
|
self.verified = False
|
29
|
-
try:
|
30
|
-
self.parseXML()
|
31
|
-
except:
|
32
|
-
pass
|
33
33
|
|
34
34
|
def getShapes(self):
|
35
35
|
return self.shapes
|
@@ -48,12 +48,7 @@
|
|
48
48
|
xmltree = ElementTree.parse(self.filepath, parser=parser).getroot()
|
49
49
|
filename = xmltree.find('filename').text
|
50
50
|
path = xmltree.find('path').text
|
51
|
-
|
51
|
+
|
52
|
-
verified = xmltree.attrib['verified']
|
53
|
-
if verified == 'yes':
|
54
|
-
self.verified = True
|
55
|
-
except KeyError:
|
56
|
-
self.verified = False
|
57
52
|
|
58
53
|
for object_iter in xmltree.findall('object'):
|
59
54
|
bndbox = object_iter.find("bndbox")
|
@@ -70,15 +65,11 @@
|
|
70
65
|
classes = dict()
|
71
66
|
num_classes = 0
|
72
67
|
|
73
|
-
try:
|
74
|
-
input = raw_input
|
75
|
-
except NameError:
|
76
|
-
pass
|
77
68
|
|
78
69
|
|
79
70
|
parentpath = './' #"Directory path with parent dir before xml_dir or img_dir"
|
80
|
-
addxmlpath = parentpath + 'traffic_label/20170271403' #"Directory path with XML files"
|
71
|
+
addxmlpath = parentpath + 'traffic_label/201702071403' #"Directory path with XML files"
|
81
|
-
addimgpath = parentpath + 'traffic_img/20170271403' #"Directory path with IMG files"
|
72
|
+
addimgpath = parentpath + 'traffic_img/201702071403' #"Directory path with IMG files"
|
82
73
|
outputpath = parentpath + 'traffic_format4yolo' #"output folder for yolo format"
|
83
74
|
classes_txt = './traffic_classes.txt' #"File containing classes"
|
84
75
|
ext = '.jpg' #"Image file extension [.jpg or .png]"
|
@@ -89,8 +80,10 @@
|
|
89
80
|
class_list = f.read().strip().split()
|
90
81
|
classes = {k : v for (v, k) in enumerate(class_list)}
|
91
82
|
|
92
|
-
xmlPaths = glob(addxmlpath +
|
83
|
+
xmlPaths = glob.glob(addxmlpath + '/Users/isl/Desktop/xml2yolo-master - コピー/traffic_labe/20170271403/*.xml')
|
93
84
|
#imgPaths = glob(addimgpath + "/*"+ext)
|
85
|
+
# file = glob.glob('/Users/isl/Desktop/xml2yolo-master - コピー/traffic_labe/20170271403/*.xml')
|
86
|
+
print(xmlPaths)
|
94
87
|
|
95
88
|
for xmlPath in xmlPaths:
|
96
89
|
tVocParseReader = PascalVocReader(xmlPath)
|
@@ -125,7 +118,6 @@
|
|
125
118
|
for key in classes.keys():
|
126
119
|
f.write("%s\n" % key)
|
127
120
|
print(key)
|
128
|
-
|
129
121
|
```
|
130
122
|
|
131
123
|

|
@@ -133,8 +125,8 @@
|
|
133
125
|

|
134
126
|

|
135
127
|

|
136
|
-

|
137
|
-
|
129
|
+
|
138
130
|
|
139
131
|
|
140
132
|
Windows、Anaconda
|
2
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -133,6 +133,7 @@
|
|
133
133
|

|
134
134
|

|
135
135
|

|
136
|
+

|
136
137
|

|
137
138
|
|
138
139
|
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -133,6 +133,7 @@
|
|
133
133
|

|
134
134
|

|
135
135
|

|
136
|
+

|
136
137
|
|
137
138
|
|
138
139
|
Windows、Anaconda
|