質問編集履歴

3

書式の改善

2021/12/01 15:18

投稿

kikulage
kikulage

スコア12

test CHANGED
File without changes
test CHANGED
@@ -100,15 +100,13 @@
100
100
 
101
101
  現在、こちらのサイトを参考に学習を行っています。
102
102
 
103
+ anaconda promt内で「python voc_annotation.py」を実行
104
+
103
105
  その際、VOTTでアノテーションした.xmlファイルを『voc_annotation.py』YOLOの学習用に変換している際に以下のようなエラーが発生しました。
104
106
 
105
107
 
106
108
 
107
- anaconda promt内で以下を実行
109
+ エラー
108
-
109
- python voc_annotation.py
110
-
111
-
112
110
 
113
111
  Traceback (most recent call last):
114
112
 
@@ -124,6 +122,8 @@
124
122
 
125
123
 
126
124
 
125
+ 補足
126
+
127
127
  『voc_annotation.py』は6行目の
128
128
 
129
129
  classes = ["item"]

2

tagの追加

2021/12/01 15:18

投稿

kikulage
kikulage

スコア12

test CHANGED
File without changes
test CHANGED
File without changes

1

プログラムコードの追加

2021/12/01 15:16

投稿

kikulage
kikulage

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,101 @@
1
+ ```python
2
+
3
+ import xml.etree.ElementTree as ET
4
+
5
+ from os import getcwd
6
+
7
+ import sys,os
8
+
9
+ sets=[('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
10
+
11
+
12
+
13
+ classes = ["hoge"]
14
+
15
+
16
+
17
+ if len(sys.argv) > 1:
18
+
19
+ classes = sys.argv[1:]
20
+
21
+
22
+
23
+ with open('model_data/voc_classes.txt','w') as f:
24
+
25
+ f.write('\n'.join(classes))
26
+
27
+
28
+
29
+
30
+
31
+ def convert_annotation(year, image_id, list_file):
32
+
33
+ in_file = open('VOCDevkit/VOC%s/Annotations/%s.xml'%(year, image_id.replace(".jpg","")))
34
+
35
+ tree=ET.parse(in_file)
36
+
37
+ root = tree.getroot()
38
+
39
+
40
+
41
+ for obj in root.iter('object'):
42
+
43
+ difficult = obj.find('difficult').text
44
+
45
+ cls = obj.find('name').text
46
+
47
+ if cls not in classes or int(difficult)==1:
48
+
49
+ continue
50
+
51
+ cls_id = classes.index(cls)
52
+
53
+ xmlbox = obj.find('bndbox')
54
+
55
+ b = (int(float(xmlbox.find('xmin').text)),
56
+
57
+ int(float(xmlbox.find('ymin').text)),
58
+
59
+ int(float(xmlbox.find('xmax').text)),
60
+
61
+ int(float(xmlbox.find('ymax').text)))
62
+
63
+ list_file.write(" " + ",".join([str(a) for a in b]) + ',' + str(cls_id))
64
+
65
+
66
+
67
+ wd = getcwd()
68
+
69
+
70
+
71
+ for year, image_set in sets:
72
+
73
+ image_ids = open('VOCDevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()
74
+
75
+ list_file = open('model_data/%s_%s.txt'%(year, image_set), 'w')
76
+
77
+ for image_id in image_ids:
78
+
79
+ if image_id == '1': continue
80
+
81
+ if image_id == '-1': continue
82
+
83
+ image_file_path = '%s/VOCDevkit/VOC%s/JPEGImages/%s'%(wd, year, image_id)
84
+
85
+ list_file.write(image_file_path)
86
+
87
+ convert_annotation(year, image_id, list_file)
88
+
89
+ list_file.write('\n')
90
+
91
+ list_file.close()
92
+
93
+
94
+
95
+
96
+
97
+ ```
98
+
1
99
  https://miyashinblog.com/yolo-fine-turning/
2
100
 
3
101
  現在、こちらのサイトを参考に学習を行っています。