Tsinghua-Tencent 100K Tutorial

Hello, welcome to the tutorial of Tsinghua-Tencent 100k, in this tutorial, we will show you:

  • How to run our model with TT100K dataset
  • The structure of TT100K
  • How to observe TT100K
  • How to evaluate your result

How to run our model with TT100K dataset

First we need to download and extract the dataset and code from website http://cg.cs.tsinghua.edu.cn/traffic-sign/, Make sure your disk have 100G free space at least.

In [ ]:
mkdir TT100K && cd TT100K
wget http://cg.cs.tsinghua.edu.cn/traffic-sign/data_model_code/data.zip
wget http://cg.cs.tsinghua.edu.cn/traffic-sign/data_model_code/code.zip
unzip data.zip
unzip code.zip

Next, we have to build caffe code.

In [ ]:
cd code/script
./compile.sh

Then, we need to build the dataset into the LMDB format, and calculate the image mean for caffe training.

In [ ]:
mkdir -p ../../data/lmdb
./1_convert_lmdb.sh
./2_calc_img_mean.sh

Finally, we start the training process.

In [ ]:
../caffe/build/tools/caffe train --solver ../model/solver.prototxt --gpu 0

The training begin! The model converges in 40K iterations, it takes about 3 to 4 days.

The structure of TT100K

Explanation of directories:

code

  • caffe: caffe code that we used
  • model: our caffe model file
  • script: scripts used in this tutorial.
  • python: some python utils
    • anno_func.py: some useful utils function
    • data_show.ipynb: example of displaying images
    • deployer.ipynb: example of deployer
    • eval_check.ipynb: example of evaluating

data

  • train: all train pictures
  • test: all test pictures
  • other: some data that exclude from train and test
  • marks: standard traffic sign picture that are used for data agumentation
  • annotations.json: json file which contains the annotations of the pictures
  • results: results of our model and fast-rcnn

How to observe TT100K

In this section, we will show you the overview of this dataset, first we import the neccesery libraries.

In [8]:
cd ../python/
/mnt/hd1/from_linux/data/TT100K/code/python
In [9]:
import json
import pylab as pl
import random
import numpy as np
import cv2
import anno_func
%matplotlib inline

Then, we load the json annotation file and list of the test images's id

In [10]:
datadir = "../../data/"

filedir = datadir + "/annotations.json"
ids = open(datadir + "/test/ids.txt").read().splitlines()

annos = json.loads(open(filedir).read())

Let's take a look about annotation json file,

annos has two keys:

In [12]:
annos.keys()
Out[12]:
[u'imgs', u'types']

annos['types'] contains types we have in TT100K

In [14]:
",".join(annos['types'])
Out[14]:
u'i1,i10,i11,i12,i13,i14,i15,i2,i3,i4,i5,il100,il110,il50,il60,il70,il80,il90,io,ip,p1,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p2,p20,p21,p22,p23,p24,p25,p26,p27,p28,p3,p4,p5,p6,p7,p8,p9,pa10,pa12,pa13,pa14,pa8,pb,pc,pg,ph1.5,ph2,ph2.1,ph2.2,ph2.4,ph2.5,ph2.8,ph2.9,ph3,ph3.2,ph3.5,ph3.8,ph4,ph4.2,ph4.3,ph4.5,ph4.8,ph5,ph5.3,ph5.5,pl10,pl100,pl110,pl120,pl15,pl20,pl25,pl30,pl35,pl40,pl5,pl50,pl60,pl65,pl70,pl80,pl90,pm10,pm13,pm15,pm1.5,pm2,pm20,pm25,pm30,pm35,pm40,pm46,pm5,pm50,pm55,pm8,pn,pne,po,pr10,pr100,pr20,pr30,pr40,pr45,pr50,pr60,pr70,pr80,ps,pw2,pw2.5,pw3,pw3.2,pw3.5,pw4,pw4.2,pw4.5,w1,w10,w12,w13,w16,w18,w20,w21,w22,w24,w28,w3,w30,w31,w32,w34,w35,w37,w38,w41,w42,w43,w44,w45,w46,w47,w48,w49,w5,w50,w55,w56,w57,w58,w59,w60,w62,w63,w66,w8,wo,i6,i7,i8,i9,ilx,p29,w29,w33,w36,w39,w4,w40,w51,w52,w53,w54,w6,w61,w64,w65,w67,w7,w9,pax,pd,pe,phx,plx,pmx,pnl,prx,pwx,w11,w14,w15,w17,w19,w2,w23,w25,w26,w27,pl0,pl4,pl3,pm2.5,ph4.4,pn40,ph3.3,ph2.6'

You can sample an id and visualize the image by using our utils.

In [29]:
imgid = random.sample(ids, 1)[0]
print imgid

imgdata = anno_func.load_img(annos, datadir, imgid)
imgdata_draw = anno_func.draw_all(annos, datadir, imgid, imgdata)
pl.figure(figsize=(20,20))
pl.imshow(imgdata_draw)
78307
((1106.3541259765625, 977.7344970703125), (18.043243408203125, 20.239809036254883), 122.83193969726562)
Out[29]:
<matplotlib.image.AxesImage at 0x7fbee59b8b90>