teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

書式の改善

2021/12/01 15:18

投稿

kikulage
kikulage

スコア12

title CHANGED
File without changes
body CHANGED
@@ -49,11 +49,10 @@
49
49
  ```
50
50
  https://miyashinblog.com/yolo-fine-turning/
51
51
  現在、こちらのサイトを参考に学習を行っています。
52
+ anaconda promt内で「python voc_annotation.py」を実行
52
53
  その際、VOTTでアノテーションした.xmlファイルを『voc_annotation.py』YOLOの学習用に変換している際に以下のようなエラーが発生しました。
53
54
 
54
- anaconda promt内で以下を実行
55
+ エラー
55
- python voc_annotation.py
56
-
57
56
  Traceback (most recent call last):
58
57
  File "voc_annotation.py", line 43, in <module>
59
58
  convert_annotation(year, image_id, list_file)
@@ -61,6 +60,7 @@
61
60
  in_file = open('VOCDevkit/VOC%s/Annotations/%s.xml'%(year, image_id.replace(".jpg","")))
62
61
  FileNotFoundError: [Errno 2] No such file or directory: 'VOCDevkit/VOC2007/Annotations/hoge.JPG.xml'
63
62
 
63
+ 補足
64
64
  『voc_annotation.py』は6行目の
65
65
  classes = ["item"]
66
66
  内のアイテムをアノテーションタグ名称に変更して実行しています。

2

tagの追加

2021/12/01 15:18

投稿

kikulage
kikulage

スコア12

title CHANGED
File without changes
body CHANGED
File without changes

1

プログラムコードの追加

2021/12/01 15:16

投稿

kikulage
kikulage

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,52 @@
1
+ ```python
2
+ import xml.etree.ElementTree as ET
3
+ from os import getcwd
4
+ import sys,os
5
+ sets=[('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
6
+
7
+ classes = ["hoge"]
8
+
9
+ if len(sys.argv) > 1:
10
+ classes = sys.argv[1:]
11
+
12
+ with open('model_data/voc_classes.txt','w') as f:
13
+ f.write('\n'.join(classes))
14
+
15
+
16
+ def convert_annotation(year, image_id, list_file):
17
+ in_file = open('VOCDevkit/VOC%s/Annotations/%s.xml'%(year, image_id.replace(".jpg","")))
18
+ tree=ET.parse(in_file)
19
+ root = tree.getroot()
20
+
21
+ for obj in root.iter('object'):
22
+ difficult = obj.find('difficult').text
23
+ cls = obj.find('name').text
24
+ if cls not in classes or int(difficult)==1:
25
+ continue
26
+ cls_id = classes.index(cls)
27
+ xmlbox = obj.find('bndbox')
28
+ b = (int(float(xmlbox.find('xmin').text)),
29
+ int(float(xmlbox.find('ymin').text)),
30
+ int(float(xmlbox.find('xmax').text)),
31
+ int(float(xmlbox.find('ymax').text)))
32
+ list_file.write(" " + ",".join([str(a) for a in b]) + ',' + str(cls_id))
33
+
34
+ wd = getcwd()
35
+
36
+ for year, image_set in sets:
37
+ image_ids = open('VOCDevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()
38
+ list_file = open('model_data/%s_%s.txt'%(year, image_set), 'w')
39
+ for image_id in image_ids:
40
+ if image_id == '1': continue
41
+ if image_id == '-1': continue
42
+ image_file_path = '%s/VOCDevkit/VOC%s/JPEGImages/%s'%(wd, year, image_id)
43
+ list_file.write(image_file_path)
44
+ convert_annotation(year, image_id, list_file)
45
+ list_file.write('\n')
46
+ list_file.close()
47
+
48
+
49
+ ```
1
50
  https://miyashinblog.com/yolo-fine-turning/
2
51
  現在、こちらのサイトを参考に学習を行っています。
3
52
  その際、VOTTでアノテーションした.xmlファイルを『voc_annotation.py』YOLOの学習用に変換している際に以下のようなエラーが発生しました。