ChristopherSTAN commited on
Commit
d18adf8
·
unverified ·
1 Parent(s): 0825cb7

Add files via upload

Browse files
Files changed (5) hide show
  1. data/VOC2007.sh +42 -0
  2. data/VOC2012.sh +38 -0
  3. data/VOC_split.py +60 -0
  4. data/organize_VOC.py +47 -0
  5. data/voc.yml +10 -0
data/VOC2007.sh ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Ellis Brown
3
+
4
+ start=`date +%s`
5
+
6
+ # handle optional download dir
7
+ if [ -z "$1" ]
8
+ then
9
+ # navigate to ~/data
10
+ echo "navigating to ../data/ ..."
11
+ mkdir -p ./data
12
+ cd ./data/
13
+ else
14
+ # check if is valid directory
15
+ if [ ! -d $1 ]; then
16
+ echo $1 "is not a valid directory"
17
+ exit 0
18
+ fi
19
+ echo "navigating to" $1 "..."
20
+ cd $1
21
+ fi
22
+
23
+ echo "Downloading VOC2007 trainval ..."
24
+ # Download the data.
25
+ curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
26
+ echo "Downloading VOC2007 test data ..."
27
+ curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
28
+ echo "Done downloading."
29
+
30
+ # Extract data
31
+ echo "Extracting trainval ..."
32
+ tar -xvf VOCtrainval_06-Nov-2007.tar
33
+ echo "Extracting test ..."
34
+ tar -xvf VOCtest_06-Nov-2007.tar
35
+ echo "removing tars ..."
36
+ rm VOCtrainval_06-Nov-2007.tar
37
+ rm VOCtest_06-Nov-2007.tar
38
+
39
+ end=`date +%s`
40
+ runtime=$((end-start))
41
+
42
+ echo "Completed in" $runtime "seconds"
data/VOC2012.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Ellis Brown
3
+
4
+ start=`date +%s`
5
+
6
+ # handle optional download dir
7
+ if [ -z "$1" ]
8
+ then
9
+ # navigate to ~/data
10
+ echo "navigating to ~/data/ ..."
11
+ mkdir -p ./data
12
+ cd ./data/
13
+ else
14
+ # check if is valid directory
15
+ if [ ! -d $1 ]; then
16
+ echo $1 "is not a valid directory"
17
+ exit 0
18
+ fi
19
+ echo "navigating to" $1 "..."
20
+ cd $1
21
+ fi
22
+
23
+ echo "Downloading VOC2012 trainval ..."
24
+ # Download the data.
25
+ curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
26
+ echo "Done downloading."
27
+
28
+
29
+ # Extract data
30
+ echo "Extracting trainval ..."
31
+ tar -xvf VOCtrainval_11-May-2012.tar
32
+ echo "removing tar ..."
33
+ rm VOCtrainval_11-May-2012.tar
34
+
35
+ end=`date +%s`
36
+ runtime=$((end-start))
37
+
38
+ echo "Completed in" $runtime "seconds"
data/VOC_split.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
data/organize_VOC.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ print(os.path.exists('../data/train.txt'))
2
+ f = open('../data/train.txt', 'r')
3
+ lines = f.readlines()
4
+
5
+ for line in lines:
6
+ #print(line.split('/')[-1][:-1])
7
+ line = "/".join(line.split('/')[2:])
8
+
9
+ if (os.path.exists(line[:-1])):
10
+ os.system("cp "+ line[:-1] + " VOC/images/train")
11
+
12
+ print(os.path.exists('../data/train.txt'))
13
+ f = open('../data/train.txt', 'r')
14
+ lines = f.readlines()
15
+
16
+ for line in lines:
17
+ #print(line.split('/')[-1][:-1])
18
+ line = "/".join(line.split('/')[2:])
19
+ line = line.replace('JPEGImages', 'labels')
20
+ line = line.replace('jpg', 'txt')
21
+ #print(line)
22
+ if (os.path.exists(line[:-1])):
23
+ os.system("cp "+ line[:-1] + " VOC/labels/train")
24
+
25
+ print(os.path.exists('../data/2007_test.txt'))
26
+ f = open('../data/2007_test.txt', 'r')
27
+ lines = f.readlines()
28
+
29
+ for line in lines:
30
+ #print(line.split('/')[-1][:-1])
31
+ line = "/".join(line.split('/')[2:])
32
+
33
+ if (os.path.exists(line[:-1])):
34
+ os.system("cp "+ line[:-1] + " VOC/images/val")
35
+
36
+ print(os.path.exists('../data/2007_test.txt'))
37
+ f = open('../data/2007_test.txt', 'r')
38
+ lines = f.readlines()
39
+
40
+ for line in lines:
41
+ #print(line.split('/')[-1][:-1])
42
+ line = "/".join(line.split('/')[2:])
43
+ line = line.replace('JPEGImages', 'labels')
44
+ line = line.replace('jpg', 'txt')
45
+ #print(line)
46
+ if (os.path.exists(line[:-1])):
47
+ os.system("cp "+ line[:-1] + " VOC/labels/val")
data/voc.yml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # train and val datasets (image directory or *.txt file with image paths)
3
+ train: ../VOC/images/train/
4
+ val: ../VOC/images/val//
5
+
6
+ # number of classes
7
+ nc: 20
8
+
9
+ # class names
10
+ names: ['aeroplane', 'bicycle','bird','boat','bottle','bus','car','cat','chair','cow','diningtable','dog','horse','motorbike','person','pottedplant','sheep','sofa','train','tvmonitor']