ChristopherSTAN commited on
Commit
389ed1f
·
unverified ·
1 Parent(s): 2bcf3da

Delete VOC_split.py

Browse files
Files changed (1) hide show
  1. data/VOC_split.py +0 -60
data/VOC_split.py DELETED
@@ -1,60 +0,0 @@
1
-
2
- # Run this file with folder VOCdevkit.
3
- import xml.etree.ElementTree as ET
4
- import pickle
5
- import os
6
- from os import listdir, getcwd
7
- from os.path import join
8
-
9
- sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
10
-
11
- classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
12
-
13
-
14
- def convert(size, box):
15
- dw = 1./(size[0])
16
- dh = 1./(size[1])
17
- x = (box[0] + box[1])/2.0 - 1
18
- y = (box[2] + box[3])/2.0 - 1
19
- w = box[1] - box[0]
20
- h = box[3] - box[2]
21
- x = x*dw
22
- w = w*dw
23
- y = y*dh
24
- h = h*dh
25
- return (x,y,w,h)
26
-
27
- def convert_annotation(year, image_id):
28
- in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id))
29
- out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w')
30
- tree=ET.parse(in_file)
31
- root = tree.getroot()
32
- size = root.find('size')
33
- w = int(size.find('width').text)
34
- h = int(size.find('height').text)
35
-
36
- for obj in root.iter('object'):
37
- difficult = obj.find('difficult').text
38
- cls = obj.find('name').text
39
- if cls not in classes or int(difficult)==1:
40
- continue
41
- cls_id = classes.index(cls)
42
- xmlbox = obj.find('bndbox')
43
- b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
44
- bb = convert((w,h), b)
45
- out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
46
-
47
- wd = getcwd()
48
-
49
- for year, image_set in sets:
50
- if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)):
51
- os.makedirs('VOCdevkit/VOC%s/labels/'%(year))
52
- image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()
53
- list_file = open('%s_%s.txt'%(year, image_set), 'w')
54
- for image_id in image_ids:
55
- list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id))
56
- convert_annotation(year, image_id)
57
- list_file.close()
58
-
59
- os.system("cat 2007_train.txt 2007_val.txt 2012_train.txt 2012_val.txt > train.txt")
60
- os.system("cat 2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt > train.all.txt")