Hello, welcome to the tutorial of Tsinghua-Tencent 100k, in this tutorial, we will show you:
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.
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.
cd code/script
./compile.sh
Then, we need to build the dataset into the LMDB format, and calculate the image mean for caffe training.
mkdir -p ../../data/lmdb
./1_convert_lmdb.sh
./2_calc_img_mean.sh
Finally, we start the training process.
../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.
Explanation of directories:
In this section, we will show you the overview of this dataset, first we import the neccesery libraries.
cd ../python/
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
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:
annos.keys()
annos['types'] contains types we have in TT100K
",".join(annos['types'])
You can sample an id and visualize the image by using our utils.
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)
In sample 78307, we have 3 marks. We can dig a little bit more by print the json file.
annos['imgs'][imgid]
The structure of the annotation are show below:
First, load our results, you can replace it with your results.
Function eval_annos will tell you how many marks are right, wrong and missed,
some arguments can be used during evaluate, iou are the bounding box overlap ratio
result_anno_file = "./../results/ours_result_annos.json"
results_annos = json.loads(open(result_anno_file).read())
sm = anno_func.eval_annos(annos, results_annos, iou=0.5, types=anno_func.type45, check_type=True)
print sm['report']
We provide some utils to help you analysis your results,
For example, show the accuracy-recall curve on different size.
import sys
def get_acc_res(results_annos, **argv):
scs = [ obj['score'] for k,img in results_annos['imgs'].items() for obj in img['objects']]
scs = sorted(scs)
accs = [0]
recs = [1]
for i, score in enumerate(np.linspace(0, scs[-1], 100)):
sm = anno_func.eval_annos(annos, results_annos, iou=0.5, check_type=True, types=anno_func.type45, minscore=score, **argv)
print "\r%s %s %s" % (i, score, sm['report']),
sys.stdout.flush()
accs.append(sm['accuracy'])
if len(accs)>=2 and accs[-1]<accs[-2]:
accs[-1] = accs[-2]
recs.append(sm['recall'])
accs.append(1)
recs.append(0)
return accs, recs
sizes = [0,32,96,400]
ac_rc = []
for i in range(4):
if i==3:
l=sizes[0]
r=sizes[-1]
else:
l=sizes[i]
r=sizes[i+1]
acc1, recs1 = get_acc_res(results_annos, minboxsize=l, maxboxsize=r)
#acc2, recs2 = get_acc_res(results_annos2, minboxsize=l, maxboxsize=r)
#ac_rc.append([acc1, recs1, acc2, recs2])
ac_rc.append([acc1, recs1])
pl.figure()
pl.plot(acc1, recs1, label='ours')
#pl.plot(acc2, recs2, label='fast-rcnn')
pl.xlabel("accuracy")
pl.ylabel("recall")
pl.title("size: (%s,%s]"%(l,r))
pl.legend(bbox_to_anchor=(0, 0), loc="lower left")
#pl.savefig("/home/randon/data/newdata/results/ac-rc%s.pdf"%i)
#_ = pl.hist(scs, bins=100)
Report on different size and types
test_annos = results_annos
minscore=40
sm = anno_func.eval_annos(annos, test_annos, iou=0.5, check_type=True, types=anno_func.type45,
minboxsize=0,maxboxsize=400,minscore=minscore)
print sm['report']
sm = anno_func.eval_annos(annos, test_annos, iou=0.5, check_type=True, types=anno_func.type45,
minboxsize=0,maxboxsize=32,minscore=minscore)
print sm['report']
sm = anno_func.eval_annos(annos, test_annos, iou=0.5, check_type=True, types=anno_func.type45,
minboxsize=32,maxboxsize=96,minscore=minscore)
print sm['report']
sm = anno_func.eval_annos(annos, test_annos, iou=0.5, check_type=True, types=anno_func.type45,
minboxsize=96,maxboxsize=400,minscore=minscore)
print sm['report']
for tp in anno_func.type45:
sm = anno_func.eval_annos(annos, test_annos, iou=0.5, check_type=True, types=[tp],minscore=minscore)
print sm['report']
And plot the mark you are wrong or missed
while True:
imgid = random.sample(results_annos['imgs'].keys(), 1)[0]
if len(sm['wrong']["imgs"][imgid]["objects"]) and len(sm['miss']["imgs"][imgid]["objects"]):
break
print imgid
pl.figure(figsize=(20,20))
imgdata = anno_func.load_img(annos, datadir, imgid)
imgdata = anno_func.draw_all(sm['right'], datadir, imgid, imgdata, (0,1,0), False)
imgdata = anno_func.draw_all(sm['wrong'], datadir, imgid, imgdata, (1,0,0), False)
imgdata = anno_func.draw_all(sm['miss'], datadir, imgid, imgdata, (0,0,1), False)
pl.imshow(imgdata)