├── data
├── map.pbtxt
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
├── 5.jpg
├── 6.jpg
├── 7.jpg
├── 8.jpg
├── 9.jpg
├── 10.jpg
├── 11.jpg
├── 12.jpg
├── 13.jpg
├── 14.jpg
├── 15.jpg
├── 16.jpg
├── 17.jpg
├── 18.jpg
├── 19.jpg
├── 20.jpg
├── 21.jpg
├── 22.jpg
├── 23.jpg
├── 24.jpg
├── 25.jpg
├── 26.jpg
├── 27.jpg
├── 28.jpg
├── 29.jpg
├── 30.jpg
├── 31.jpg
├── 32.jpg
├── 33.jpg
├── 34.jpg
├── 35.jpg
├── 36.jpg
├── 37.jpg
├── 38.jpg
├── 39.jpg
├── 40.jpg
├── 41.jpg
├── 42.jpg
├── 43.jpg
├── 44.jpg
├── 45.jpg
├── 46.jpg
├── 47.jpg
├── 48.jpg
├── 49.jpg
├── 50.jpg
├── 51.jpg
├── 52.jpg
├── 53.jpg
├── 54.jpg
├── 55.jpg
├── 56.jpg
├── 57.jpg
├── 58.jpg
├── 59.jpg
├── 60.jpg
├── 24.xml
├── 43.xml
├── 15.xml
├── 17.xml
├── 27.xml
├── 3.xml
├── 30.xml
├── 33.xml
├── 38.xml
├── 39.xml
├── 44.xml
├── 49.xml
├── 23.xml
├── 57.xml
├── 2.xml
├── 9.xml
├── 1.xml
├── 10.xml
├── 18.xml
├── 20.xml
├── 26.xml
├── 29.xml
├── 31.xml
├── 35.xml
├── 4.xml
├── 42.xml
├── 48.xml
├── 5.xml
├── 50.xml
├── 16.xml
├── 28.xml
├── 34.xml
├── 36.xml
├── 47.xml
├── 56.xml
├── 60.xml
├── 51.xml
├── 7.xml
├── 22.xml
├── 25.xml
├── 32.xml
├── 37.xml
├── 46.xml
├── 55.xml
├── 59.xml
├── 19.xml
├── 45.xml
├── 13.xml
├── 21.xml
├── 6.xml
├── 41.xml
├── 11.xml
├── 58.xml
├── 14.xml
├── 8.xml
├── 54.xml
├── 12.xml
├── 40.xml
├── 53.xml
└── 52.xml
├── .gitignore
├── test
├── 1.jpg
├── 2.jpg
├── 3.jpg
└── 4.jpg
├── README.md
├── annotate.py
├── ssd_mobilenet_v1_coco.config
└── create_pascal_tf_record.py
/data/map.pbtxt:
--------------------------------------------------------------------------------
1 | item {
2 | id: 1
3 | name: "race car"
4 | }
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /*.tfrecord
2 | /ssd_mobilenet_v1_coco_11_06_2017/
3 | /inference/
4 | /test/*.xml
5 | /training/
6 |
--------------------------------------------------------------------------------
/data/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/1.jpg
--------------------------------------------------------------------------------
/data/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/2.jpg
--------------------------------------------------------------------------------
/data/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/3.jpg
--------------------------------------------------------------------------------
/data/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/4.jpg
--------------------------------------------------------------------------------
/data/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/5.jpg
--------------------------------------------------------------------------------
/data/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/6.jpg
--------------------------------------------------------------------------------
/data/7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/7.jpg
--------------------------------------------------------------------------------
/data/8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/8.jpg
--------------------------------------------------------------------------------
/data/9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/9.jpg
--------------------------------------------------------------------------------
/test/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/test/1.jpg
--------------------------------------------------------------------------------
/test/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/test/2.jpg
--------------------------------------------------------------------------------
/test/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/test/3.jpg
--------------------------------------------------------------------------------
/test/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/test/4.jpg
--------------------------------------------------------------------------------
/data/10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/10.jpg
--------------------------------------------------------------------------------
/data/11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/11.jpg
--------------------------------------------------------------------------------
/data/12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/12.jpg
--------------------------------------------------------------------------------
/data/13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/13.jpg
--------------------------------------------------------------------------------
/data/14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/14.jpg
--------------------------------------------------------------------------------
/data/15.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/15.jpg
--------------------------------------------------------------------------------
/data/16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/16.jpg
--------------------------------------------------------------------------------
/data/17.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/17.jpg
--------------------------------------------------------------------------------
/data/18.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/18.jpg
--------------------------------------------------------------------------------
/data/19.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/19.jpg
--------------------------------------------------------------------------------
/data/20.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/20.jpg
--------------------------------------------------------------------------------
/data/21.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/21.jpg
--------------------------------------------------------------------------------
/data/22.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/22.jpg
--------------------------------------------------------------------------------
/data/23.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/23.jpg
--------------------------------------------------------------------------------
/data/24.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/24.jpg
--------------------------------------------------------------------------------
/data/25.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/25.jpg
--------------------------------------------------------------------------------
/data/26.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/26.jpg
--------------------------------------------------------------------------------
/data/27.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/27.jpg
--------------------------------------------------------------------------------
/data/28.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/28.jpg
--------------------------------------------------------------------------------
/data/29.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/29.jpg
--------------------------------------------------------------------------------
/data/30.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/30.jpg
--------------------------------------------------------------------------------
/data/31.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/31.jpg
--------------------------------------------------------------------------------
/data/32.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/32.jpg
--------------------------------------------------------------------------------
/data/33.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/33.jpg
--------------------------------------------------------------------------------
/data/34.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/34.jpg
--------------------------------------------------------------------------------
/data/35.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/35.jpg
--------------------------------------------------------------------------------
/data/36.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/36.jpg
--------------------------------------------------------------------------------
/data/37.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/37.jpg
--------------------------------------------------------------------------------
/data/38.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/38.jpg
--------------------------------------------------------------------------------
/data/39.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/39.jpg
--------------------------------------------------------------------------------
/data/40.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/40.jpg
--------------------------------------------------------------------------------
/data/41.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/41.jpg
--------------------------------------------------------------------------------
/data/42.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/42.jpg
--------------------------------------------------------------------------------
/data/43.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/43.jpg
--------------------------------------------------------------------------------
/data/44.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/44.jpg
--------------------------------------------------------------------------------
/data/45.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/45.jpg
--------------------------------------------------------------------------------
/data/46.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/46.jpg
--------------------------------------------------------------------------------
/data/47.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/47.jpg
--------------------------------------------------------------------------------
/data/48.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/48.jpg
--------------------------------------------------------------------------------
/data/49.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/49.jpg
--------------------------------------------------------------------------------
/data/50.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/50.jpg
--------------------------------------------------------------------------------
/data/51.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/51.jpg
--------------------------------------------------------------------------------
/data/52.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/52.jpg
--------------------------------------------------------------------------------
/data/53.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/53.jpg
--------------------------------------------------------------------------------
/data/54.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/54.jpg
--------------------------------------------------------------------------------
/data/55.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/55.jpg
--------------------------------------------------------------------------------
/data/56.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/56.jpg
--------------------------------------------------------------------------------
/data/57.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/57.jpg
--------------------------------------------------------------------------------
/data/58.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/58.jpg
--------------------------------------------------------------------------------
/data/59.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/59.jpg
--------------------------------------------------------------------------------
/data/60.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AndrewCarterUK/tf-example-object-detection-api-race-cars/HEAD/data/60.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Example: Annotating Large Datasets with the TensorFlow Object Detection API
2 |
3 | This repository holds the example project that demonstrates how the TensorFlow Object Detection API can be used to predict annotations for large datasets.
4 |
5 | The example images inside the `data/` directory are from a variety of sources. They are not provided under any license, nor covered by any license used by this project or its dependencies.
6 |
--------------------------------------------------------------------------------
/data/24.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 24.jpg
4 | /home/andrew/Desktop/formula-1/24.jpg
5 |
6 | Unknown
7 |
8 |
9 | 259
10 | 194
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/43.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 43.jpg
4 | /home/andrew/Desktop/formula-1/43.jpg
5 |
6 | Unknown
7 |
8 |
9 | 275
10 | 183
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/15.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 15.jpg
4 | /home/andrew/Desktop/formula-1/15.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1500
10 | 1000
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/17.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 17.jpg
4 | /home/andrew/Desktop/formula-1/17.jpg
5 |
6 | Unknown
7 |
8 |
9 | 720
10 | 250
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/27.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 27.jpg
4 | /home/andrew/Desktop/formula-1/27.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1280
10 | 720
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/3.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 3.jpg
4 | /home/andrew/Desktop/formula-1/3.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1536
10 | 864
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/30.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 30.jpg
4 | /home/andrew/Desktop/formula-1/30.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1024
10 | 683
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/33.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 33.jpg
4 | /home/andrew/Desktop/formula-1/33.jpg
5 |
6 | Unknown
7 |
8 |
9 | 750
10 | 500
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/38.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 38.jpg
4 | /home/andrew/Desktop/formula-1/38.jpg
5 |
6 | Unknown
7 |
8 |
9 | 623
10 | 415
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/39.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 39.jpg
4 | /home/andrew/Desktop/formula-1/39.jpg
5 |
6 | Unknown
7 |
8 |
9 | 800
10 | 534
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/44.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 44.jpg
4 | /home/andrew/Desktop/formula-1/44.jpg
5 |
6 | Unknown
7 |
8 |
9 | 600
10 | 400
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/49.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 49.jpg
4 | /home/andrew/Desktop/formula-1/49.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1000
10 | 667
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/23.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 23.jpg
4 | /home/andrew/Desktop/formula-1/23.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1600
10 | 1067
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/57.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 57.jpg
4 | /home/andrew/Desktop/formula-1/57.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1000
10 | 667
11 | 3
12 |
13 | 0
14 |
26 |
27 |
--------------------------------------------------------------------------------
/data/2.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 2.jpg
4 | /home/andrew/Desktop/formula-1/2.jpg
5 |
6 | Unknown
7 |
8 |
9 | 400
10 | 267
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/9.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 9.jpg
4 | /home/andrew/Desktop/formula-1/9.jpg
5 |
6 | Unknown
7 |
8 |
9 | 285
10 | 177
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/1.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 1.jpg
4 | /home/andrew/Desktop/formula-1/1.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1536
10 | 864
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/10.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 10.jpg
4 | /home/andrew/Desktop/formula-1/10.jpg
5 |
6 | Unknown
7 |
8 |
9 | 427
10 | 240
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/18.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 18.jpg
4 | /home/andrew/Desktop/formula-1/18.jpg
5 |
6 | Unknown
7 |
8 |
9 | 615
10 | 409
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/20.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 20.jpg
4 | /home/andrew/Desktop/formula-1/20.jpg
5 |
6 | Unknown
7 |
8 |
9 | 427
10 | 240
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/26.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 26.jpg
4 | /home/andrew/Desktop/formula-1/26.jpg
5 |
6 | Unknown
7 |
8 |
9 | 710
10 | 355
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/29.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 29.jpg
4 | /home/andrew/Desktop/formula-1/29.jpg
5 |
6 | Unknown
7 |
8 |
9 | 580
10 | 280
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/31.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 31.jpg
4 | /home/andrew/Desktop/formula-1/31.jpg
5 |
6 | Unknown
7 |
8 |
9 | 750
10 | 500
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/35.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 35.jpg
4 | /home/andrew/Desktop/formula-1/35.jpg
5 |
6 | Unknown
7 |
8 |
9 | 275
10 | 183
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/4.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 4.jpg
4 | /home/andrew/Desktop/formula-1/4.jpg
5 |
6 | Unknown
7 |
8 |
9 | 768
10 | 432
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/42.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 42.jpg
4 | /home/andrew/Desktop/formula-1/42.jpg
5 |
6 | Unknown
7 |
8 |
9 | 275
10 | 183
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/48.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 48.jpg
4 | /home/andrew/Desktop/formula-1/48.jpg
5 |
6 | Unknown
7 |
8 |
9 | 800
10 | 533
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/5.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 5.jpg
4 | /home/andrew/Desktop/formula-1/5.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1200
10 | 675
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/50.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 50.jpg
4 | /home/andrew/Desktop/formula-1/50.jpg
5 |
6 | Unknown
7 |
8 |
9 | 800
10 | 533
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/16.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 16.jpg
4 | /home/andrew/Desktop/formula-1/16.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1200
10 | 800
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/28.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 28.jpg
4 | /home/andrew/Desktop/formula-1/28.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1280
10 | 720
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/34.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 34.jpg
4 | /home/andrew/Desktop/formula-1/34.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1000
10 | 425
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/36.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 36.jpg
4 | /home/andrew/Desktop/formula-1/36.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1200
10 | 800
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/47.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 47.jpg
4 | /home/andrew/Desktop/formula-1/47.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1013
10 | 675
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/56.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 56.jpg
4 | /home/andrew/Desktop/formula-1/56.jpg
5 |
6 | Unknown
7 |
8 |
9 | 835
10 | 557
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/60.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 60.jpg
4 | /home/andrew/Desktop/formula-1/60.jpg
5 |
6 | Unknown
7 |
8 |
9 | 918
10 | 613
11 | 3
12 |
13 | 0
14 |
26 |
38 |
39 |
--------------------------------------------------------------------------------
/data/51.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 51.jpg
4 | /home/andrew/Desktop/formula-1/51.jpg
5 |
6 | Unknown
7 |
8 |
9 | 660
10 | 372
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/7.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 7.jpg
4 | /home/andrew/Desktop/formula-1/7.jpg
5 |
6 | Unknown
7 |
8 |
9 | 750
10 | 406
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/22.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 22.jpg
4 | /home/andrew/Desktop/formula-1/22.jpg
5 |
6 | Unknown
7 |
8 |
9 | 795
10 | 530
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/25.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 25.jpg
4 | /home/andrew/Desktop/formula-1/25.jpg
5 |
6 | Unknown
7 |
8 |
9 | 600
10 | 400
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/32.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 32.jpg
4 | /home/andrew/Desktop/formula-1/32.jpg
5 |
6 | Unknown
7 |
8 |
9 | 810
10 | 541
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/37.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 37.jpg
4 | /home/andrew/Desktop/formula-1/37.jpg
5 |
6 | Unknown
7 |
8 |
9 | 623
10 | 415
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/46.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 46.jpg
4 | /home/andrew/Desktop/formula-1/46.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1600
10 | 1067
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/55.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 55.jpg
4 | /home/andrew/Desktop/formula-1/55.jpg
5 |
6 | Unknown
7 |
8 |
9 | 918
10 | 613
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/59.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 59.jpg
4 | /home/andrew/Desktop/formula-1/59.jpg
5 |
6 | Unknown
7 |
8 |
9 | 780
10 | 520
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
51 |
--------------------------------------------------------------------------------
/data/19.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 19.jpg
4 | /home/andrew/Desktop/formula-1/19.jpg
5 |
6 | Unknown
7 |
8 |
9 | 710
10 | 240
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
63 |
--------------------------------------------------------------------------------
/data/45.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 45.jpg
4 | /home/andrew/Desktop/formula-1/45.jpg
5 |
6 | Unknown
7 |
8 |
9 | 275
10 | 183
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
63 |
--------------------------------------------------------------------------------
/data/13.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 13.jpg
4 | /home/andrew/Desktop/formula-1/13.jpg
5 |
6 | Unknown
7 |
8 |
9 | 900
10 | 616
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
63 |
--------------------------------------------------------------------------------
/data/21.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 21.jpg
4 | /home/andrew/Desktop/formula-1/21.jpg
5 |
6 | Unknown
7 |
8 |
9 | 941
10 | 529
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
63 |
--------------------------------------------------------------------------------
/data/6.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 6.jpg
4 | /home/andrew/Desktop/formula-1/6.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1500
10 | 1000
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
63 |
--------------------------------------------------------------------------------
/data/41.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 41.jpg
4 | /home/andrew/Desktop/formula-1/41.jpg
5 |
6 | Unknown
7 |
8 |
9 | 275
10 | 183
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
87 |
--------------------------------------------------------------------------------
/data/11.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 11.jpg
4 | /home/andrew/Desktop/formula-1/11.jpg
5 |
6 | Unknown
7 |
8 |
9 | 795
10 | 530
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
87 |
--------------------------------------------------------------------------------
/data/58.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 58.jpg
4 | /home/andrew/Desktop/formula-1/58.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1280
10 | 720
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
99 |
--------------------------------------------------------------------------------
/data/14.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 14.jpg
4 | /home/andrew/Desktop/formula-1/14.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1000
10 | 440
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
111 |
--------------------------------------------------------------------------------
/data/8.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 8.jpg
4 | /home/andrew/Desktop/formula-1/8.jpg
5 |
6 | Unknown
7 |
8 |
9 | 690
10 | 366
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
122 |
123 |
--------------------------------------------------------------------------------
/data/54.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 54.jpg
4 | /home/andrew/Desktop/formula-1/54.jpg
5 |
6 | Unknown
7 |
8 |
9 | 904
10 | 603
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
122 |
123 |
--------------------------------------------------------------------------------
/data/12.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 12.jpg
4 | /home/andrew/Desktop/formula-1/12.jpg
5 |
6 | Unknown
7 |
8 |
9 | 710
10 | 240
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
122 |
134 |
146 |
147 |
--------------------------------------------------------------------------------
/annotate.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import os
3 | import tensorflow as tf
4 | from PIL import Image
5 | from utils import label_map_util
6 | from pascal_voc_writer import Writer
7 |
8 | if tf.__version__ < '1.4.0':
9 | raise ImportError('Please upgrade your tensorflow installation to v1.4.* or later!')
10 |
11 | PATH_TO_CKPT = 'inference/frozen_inference_graph.pb'
12 | PATH_TO_LABELS = 'data/map.pbtxt'
13 |
14 | TOTAL_IMAGES = 10 #Edit this number to the numbers of images you have.
15 |
16 | NUM_CLASSES = 1
17 |
18 | detection_graph = tf.Graph()
19 | with detection_graph.as_default():
20 | od_graph_def = tf.GraphDef()
21 | with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
22 | serialized_graph = fid.read()
23 | od_graph_def.ParseFromString(serialized_graph)
24 | tf.import_graph_def(od_graph_def, name='')
25 |
26 | label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
27 | categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
28 | category_index = label_map_util.create_category_index(categories)
29 |
30 | def load_image_into_numpy_array(image):
31 | (im_width, im_height) = image.size
32 | return np.array(image.getdata()).reshape(
33 | (im_height, im_width, 3)).astype(np.uint8)
34 |
35 | PATH_TO_TEST_IMAGES_DIR = 'test'
36 | TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, '{}.jpg'.format(i)) for i in range(1,TOTAL_IMAGES) ]
37 |
38 | with detection_graph.as_default():
39 | with tf.Session(graph=detection_graph) as sess:
40 | # Definite input and output Tensors for detection_graph
41 | image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
42 | # Each box represents a part of the image where a particular object was detected.
43 | detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
44 | # Each score represent how level of confidence for each of the objects.
45 | # Score is shown on the result image, together with the class label.
46 | detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
47 | detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
48 | num_detections = detection_graph.get_tensor_by_name('num_detections:0')
49 | for image_path in TEST_IMAGE_PATHS:
50 | image = Image.open(image_path)
51 | image_width, image_height = image.size
52 | # the array based representation of the image will be used later in order to prepare the
53 | # result image with boxes and labels on it.
54 | image_np = load_image_into_numpy_array(image)
55 | # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
56 | image_np_expanded = np.expand_dims(image_np, axis=0)
57 | # Actual detection.
58 | (boxes, scores, classes, num) = sess.run(
59 | [detection_boxes, detection_scores, detection_classes, num_detections],
60 | feed_dict={image_tensor: image_np_expanded})
61 |
62 | boxes = np.squeeze(boxes)
63 | classes = np.squeeze(classes)
64 | scores = np.squeeze(scores)
65 |
66 | writer = Writer(image_path, image_width, image_height)
67 |
68 | for index, score in enumerate(scores):
69 | if score < 0.5:
70 | continue
71 |
72 | label = category_index[classes[index]]['name']
73 | ymin, xmin, ymax, xmax = boxes[index]
74 |
75 | writer.addObject(label, int(xmin * image_width), int(ymin * image_height),
76 | int(xmax * image_width), int(ymax * image_height))
77 |
78 |
79 | annotation_path = os.path.splitext(image_path)[0] + '.xml'
80 | writer.save(annotation_path)
81 |
--------------------------------------------------------------------------------
/ssd_mobilenet_v1_coco.config:
--------------------------------------------------------------------------------
1 | # SSD with Mobilenet v1 configuration for MSCOCO Dataset.
2 | # Users should configure the fine_tune_checkpoint field in the train config as
3 | # well as the label_map_path and input_path fields in the train_input_reader and
4 | # eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
5 | # should be configured.
6 |
7 | model {
8 | ssd {
9 | num_classes: 1
10 | box_coder {
11 | faster_rcnn_box_coder {
12 | y_scale: 10.0
13 | x_scale: 10.0
14 | height_scale: 5.0
15 | width_scale: 5.0
16 | }
17 | }
18 | matcher {
19 | argmax_matcher {
20 | matched_threshold: 0.5
21 | unmatched_threshold: 0.5
22 | ignore_thresholds: false
23 | negatives_lower_than_unmatched: true
24 | force_match_for_each_row: true
25 | }
26 | }
27 | similarity_calculator {
28 | iou_similarity {
29 | }
30 | }
31 | anchor_generator {
32 | ssd_anchor_generator {
33 | num_layers: 6
34 | min_scale: 0.2
35 | max_scale: 0.95
36 | aspect_ratios: 1.0
37 | aspect_ratios: 2.0
38 | aspect_ratios: 0.5
39 | aspect_ratios: 3.0
40 | aspect_ratios: 0.3333
41 | }
42 | }
43 | image_resizer {
44 | fixed_shape_resizer {
45 | height: 300
46 | width: 300
47 | }
48 | }
49 | box_predictor {
50 | convolutional_box_predictor {
51 | min_depth: 0
52 | max_depth: 0
53 | num_layers_before_predictor: 0
54 | use_dropout: false
55 | dropout_keep_probability: 0.8
56 | kernel_size: 1
57 | box_code_size: 4
58 | apply_sigmoid_to_scores: false
59 | conv_hyperparams {
60 | activation: RELU_6,
61 | regularizer {
62 | l2_regularizer {
63 | weight: 0.00004
64 | }
65 | }
66 | initializer {
67 | truncated_normal_initializer {
68 | stddev: 0.03
69 | mean: 0.0
70 | }
71 | }
72 | batch_norm {
73 | train: true,
74 | scale: true,
75 | center: true,
76 | decay: 0.9997,
77 | epsilon: 0.001,
78 | }
79 | }
80 | }
81 | }
82 | feature_extractor {
83 | type: 'ssd_mobilenet_v1'
84 | min_depth: 16
85 | depth_multiplier: 1.0
86 | conv_hyperparams {
87 | activation: RELU_6,
88 | regularizer {
89 | l2_regularizer {
90 | weight: 0.00004
91 | }
92 | }
93 | initializer {
94 | truncated_normal_initializer {
95 | stddev: 0.03
96 | mean: 0.0
97 | }
98 | }
99 | batch_norm {
100 | train: true,
101 | scale: true,
102 | center: true,
103 | decay: 0.9997,
104 | epsilon: 0.001,
105 | }
106 | }
107 | }
108 | loss {
109 | classification_loss {
110 | weighted_sigmoid {
111 | anchorwise_output: true
112 | }
113 | }
114 | localization_loss {
115 | weighted_smooth_l1 {
116 | anchorwise_output: true
117 | }
118 | }
119 | hard_example_miner {
120 | num_hard_examples: 3000
121 | iou_threshold: 0.99
122 | loss_type: CLASSIFICATION
123 | max_negatives_per_positive: 3
124 | min_negatives_per_image: 0
125 | }
126 | classification_weight: 1.0
127 | localization_weight: 1.0
128 | }
129 | normalize_loss_by_num_matches: true
130 | post_processing {
131 | batch_non_max_suppression {
132 | score_threshold: 1e-8
133 | iou_threshold: 0.6
134 | max_detections_per_class: 100
135 | max_total_detections: 100
136 | }
137 | score_converter: SIGMOID
138 | }
139 | }
140 | }
141 |
142 | train_config: {
143 | batch_size: 8
144 | optimizer {
145 | rms_prop_optimizer: {
146 | learning_rate: {
147 | exponential_decay_learning_rate {
148 | initial_learning_rate: 0.004
149 | decay_steps: 800720
150 | decay_factor: 0.95
151 | }
152 | }
153 | momentum_optimizer_value: 0.9
154 | decay: 0.9
155 | epsilon: 1.0
156 | }
157 | }
158 | fine_tune_checkpoint: "ssd_mobilenet_v1_coco_11_06_2017/model.ckpt"
159 | from_detection_checkpoint: true
160 | # Note: The below line limits the training process to 200K steps, which we
161 | # empirically found to be sufficient enough to train the pets dataset. This
162 | # effectively bypasses the learning rate schedule (the learning rate will
163 | # never decay). Remove the below line to train indefinitely.
164 | num_steps: 200000
165 | data_augmentation_options {
166 | random_horizontal_flip {
167 | }
168 | }
169 | data_augmentation_options {
170 | ssd_random_crop {
171 | }
172 | }
173 | }
174 |
175 | train_input_reader: {
176 | tf_record_input_reader {
177 | input_path: "dataset.tfrecord"
178 | }
179 | label_map_path: "data/map.pbtxt"
180 | }
181 |
--------------------------------------------------------------------------------
/data/40.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 40.jpg
4 | /home/andrew/Desktop/formula-1/40.jpg
5 |
6 | Unknown
7 |
8 |
9 | 800
10 | 440
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
122 |
134 |
146 |
158 |
170 |
182 |
194 |
206 |
218 |
230 |
242 |
254 |
266 |
267 |
--------------------------------------------------------------------------------
/data/53.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 53.jpg
4 | /home/andrew/Desktop/formula-1/53.jpg
5 |
6 | Unknown
7 |
8 |
9 | 918
10 | 613
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
122 |
134 |
146 |
158 |
170 |
182 |
194 |
206 |
218 |
230 |
242 |
254 |
266 |
267 |
--------------------------------------------------------------------------------
/create_pascal_tf_record.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | # The script below has been modified to create TFRecord files for
17 | # datasets that use the PASCAL VOC annotation format.
18 | #
19 | # This script assumes that files exist in a data directory with a strict
20 | # format. The annotation file path must be the same as the image file
21 | # path, but 'xml' instead of 'jpg' as the extension. File path information
22 | # inside the XML file is ignored.
23 | #
24 | # The original can be found here:
25 | # https://github.com/tensorflow/models/blob/master/research/object_detection/dataset_tools/create_pascal_tf_record.py
26 |
27 | r"""Convert raw PASCAL dataset to TFRecord for object_detection.
28 |
29 | Example usage:
30 | python object_detection/dataset_tools/create_pascal_tf_record.py \
31 | --data_dir=/home/user/data \
32 | --output_path=/home/user/pascal.record \
33 | --label_map_path=/home/user/data/map.pbtxt
34 | """
35 | from __future__ import absolute_import
36 | from __future__ import division
37 | from __future__ import print_function
38 |
39 | import hashlib
40 | import io
41 | import logging
42 | import os
43 | import glob
44 |
45 | from lxml import etree
46 | import PIL.Image
47 | import tensorflow as tf
48 |
49 | from object_detection.utils import dataset_util
50 | from object_detection.utils import label_map_util
51 |
52 |
53 | flags = tf.app.flags
54 | flags.DEFINE_string('data_dir', None, 'Root directory to raw PASCAL VOC dataset.')
55 | flags.DEFINE_string('output_path', None, 'Path to output TFRecord')
56 | flags.DEFINE_string('label_map_path', None,
57 | 'Path to label map proto')
58 | flags.DEFINE_boolean('ignore_difficult_instances', False, 'Whether to ignore '
59 | 'difficult instances')
60 | FLAGS = flags.FLAGS
61 |
62 |
63 | def dict_to_tf_example(data,
64 | image_path,
65 | label_map_dict,
66 | ignore_difficult_instances=False):
67 | """Convert XML derived dict to tf.Example proto.
68 |
69 | Notice that this function normalizes the bounding box coordinates provided
70 | by the raw data.
71 |
72 | Args:
73 | data: dict holding PASCAL XML fields for a single image (obtained by
74 | running dataset_util.recursive_parse_xml_to_dict)
75 | image_path: Path to image described by the PASCAL XML file
76 | label_map_dict: A map from string label names to integers ids.
77 | ignore_difficult_instances: Whether to skip difficult instances in the
78 | dataset (default: False).
79 |
80 | Returns:
81 | example: The converted tf.Example.
82 |
83 | Raises:
84 | ValueError: if the image pointed to by data['filename'] is not a valid JPEG
85 | """
86 | with tf.gfile.GFile(image_path, 'rb') as fid:
87 | encoded_jpg = fid.read()
88 | encoded_jpg_io = io.BytesIO(encoded_jpg)
89 | image = PIL.Image.open(encoded_jpg_io)
90 | if image.format != 'JPEG':
91 | raise ValueError('Image format not JPEG')
92 | key = hashlib.sha256(encoded_jpg).hexdigest()
93 |
94 | width = int(data['size']['width'])
95 | height = int(data['size']['height'])
96 |
97 | xmin = []
98 | ymin = []
99 | xmax = []
100 | ymax = []
101 | classes = []
102 | classes_text = []
103 | truncated = []
104 | poses = []
105 | difficult_obj = []
106 | for obj in data['object']:
107 | difficult = bool(int(obj['difficult']))
108 | if ignore_difficult_instances and difficult:
109 | continue
110 |
111 | difficult_obj.append(int(difficult))
112 |
113 | xmin.append(float(obj['bndbox']['xmin']) / width)
114 | ymin.append(float(obj['bndbox']['ymin']) / height)
115 | xmax.append(float(obj['bndbox']['xmax']) / width)
116 | ymax.append(float(obj['bndbox']['ymax']) / height)
117 | classes_text.append(obj['name'].encode('utf8'))
118 | classes.append(label_map_dict[obj['name']])
119 | truncated.append(int(obj['truncated']))
120 | poses.append(obj['pose'].encode('utf8'))
121 |
122 | example = tf.train.Example(features=tf.train.Features(feature={
123 | 'image/height': dataset_util.int64_feature(height),
124 | 'image/width': dataset_util.int64_feature(width),
125 | 'image/filename': dataset_util.bytes_feature(
126 | data['filename'].encode('utf8')),
127 | 'image/source_id': dataset_util.bytes_feature(
128 | data['filename'].encode('utf8')),
129 | 'image/key/sha256': dataset_util.bytes_feature(key.encode('utf8')),
130 | 'image/encoded': dataset_util.bytes_feature(encoded_jpg),
131 | 'image/format': dataset_util.bytes_feature('jpeg'.encode('utf8')),
132 | 'image/object/bbox/xmin': dataset_util.float_list_feature(xmin),
133 | 'image/object/bbox/xmax': dataset_util.float_list_feature(xmax),
134 | 'image/object/bbox/ymin': dataset_util.float_list_feature(ymin),
135 | 'image/object/bbox/ymax': dataset_util.float_list_feature(ymax),
136 | 'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
137 | 'image/object/class/label': dataset_util.int64_list_feature(classes),
138 | 'image/object/difficult': dataset_util.int64_list_feature(difficult_obj),
139 | 'image/object/truncated': dataset_util.int64_list_feature(truncated),
140 | 'image/object/view': dataset_util.bytes_list_feature(poses),
141 | }))
142 | return example
143 |
144 |
145 | def main(_):
146 | data_dir = FLAGS.data_dir
147 |
148 | if not data_dir:
149 | logging.error('Must provide a data directory')
150 | return
151 |
152 | output_path = FLAGS.output_path
153 |
154 | if not output_path:
155 | logging.error('Must provide an output path')
156 | return
157 |
158 | label_map_path = FLAGS.label_map_path
159 |
160 | if not label_map_path:
161 | logging.error('Must provide a label map path')
162 | return
163 |
164 | writer = tf.python_io.TFRecordWriter(output_path)
165 |
166 | label_map_dict = label_map_util.get_label_map_dict(label_map_path)
167 |
168 | logging.info('Reading from data directory.')
169 |
170 | data_dir_jpg_query = os.path.join(data_dir, '*.jpg')
171 |
172 | for idx, image_path in enumerate(glob.glob(data_dir_jpg_query)):
173 | if idx % 20 == 0:
174 | logging.info('On image %d (%s)', idx, image_path)
175 |
176 | annotation_path = os.path.splitext(image_path)[0] + '.xml'
177 |
178 | with tf.gfile.GFile(annotation_path, 'r') as fid:
179 | xml_str = fid.read()
180 |
181 | xml = etree.fromstring(xml_str)
182 | data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']
183 |
184 | tf_example = dict_to_tf_example(data, image_path, label_map_dict,
185 | FLAGS.ignore_difficult_instances)
186 |
187 | writer.write(tf_example.SerializeToString())
188 |
189 | writer.close()
190 |
191 |
192 | if __name__ == '__main__':
193 | tf.app.run()
194 |
--------------------------------------------------------------------------------
/data/52.xml:
--------------------------------------------------------------------------------
1 |
2 | formula-1
3 | 52.jpg
4 | /home/andrew/Desktop/formula-1/52.jpg
5 |
6 | Unknown
7 |
8 |
9 | 1000
10 | 667
11 | 3
12 |
13 | 0
14 |
26 |
38 |
50 |
62 |
74 |
86 |
98 |
110 |
122 |
134 |
146 |
158 |
170 |
182 |
194 |
206 |
218 |
230 |
242 |
254 |
266 |
278 |
290 |
302 |
314 |
315 |
--------------------------------------------------------------------------------