Tests for Detection module


In [1]:
# import modules
from nose.tools import *
from packages.detection import Detection
%matplotlib inline

# to reload recently edited modules
%load_ext autoreload
%autoreload 2


Using gpu device 0: GeForce GT 740M (CNMeM is disabled)

In [2]:
detect = Detection()

In [3]:
x, y = detect.data_loader()

In [4]:
print x.shape, y.shape


(7705, 1, 32, 32) (7705,)

In [7]:
detect.visualize(x)



In [34]:
detect.visualize(detect.shiftup(x))



In [54]:
detect.visualize(detect.shiftdown(x))



In [55]:
detect.visualize(detect.shiftleft(x))



In [56]:
detect.visualize(detect.shiftright(x))



In [57]:
detect.visualize(detect.augment_creator(x)[0])



In [58]:
detect.visualize(detect.preprocess(x))



In [90]:
# testing for training
pos_x = detect.preprocess(x)
pos_y = y

neg_x, neg_y = detect.augment_creator(pos_x)

In [91]:
X, Y = detect.train_setter(pos_x, neg_x, pos_y, neg_y)

In [94]:
detect.net_setter()

In [101]:
detect.trainer(X, Y)


# Neural Network with 273794 learnable parameters

## Layer information

  #  name      size
---  --------  --------
  0  input     1x32x32
  1  conv1     32x28x28
  2  pool1     32x14x14
  3  dropout1  32x14x14
  4  conv2     64x10x10
  5  pool2     64x5x5
  6  dropout2  64x5x5
  7  conv3     128x1x1
  8  hidden4   128
  9  output    2

  epoch    train loss    valid loss    train/val    valid acc  dur
-------  ------------  ------------  -----------  -----------  ------
      1       0.47359       1.60987      0.29418      0.80737  29.73s
      2       0.82662       0.49044      1.68545      0.80737  34.90s
      3       0.53274       0.49344      1.07964      0.80737  29.44s
      4       0.53898       0.49368      1.09176      0.80737  29.41s
      5       0.53840       0.49356      1.09085      0.80737  29.41s
      6       0.53739       0.49344      1.08906      0.80737  29.41s
      7       0.53646       0.49337      1.08734      0.80737  29.41s
      8       0.53583       0.49333      1.08615      0.80737  29.41s
      9       0.53534       0.49329      1.08525      0.80737  29.41s
     10       0.53498       0.49325      1.08461      0.80737  29.47s
     11       0.53468       0.49323      1.08405      0.80737  29.41s
     12       0.53451       0.49321      1.08373      0.80737  29.40s
     13       0.53437       0.49320      1.08349      0.80737  29.41s
     14       0.53426       0.49316      1.08333      0.80737  29.47s
     15       0.53420       0.49315      1.08324      0.80737  29.41s
     16       0.53414       0.49309      1.08326      0.80737  29.41s
     17       0.53409       0.49306      1.08321      0.80737  29.47s
     18       0.53408       0.49293      1.08349      0.80737  29.41s
     19       0.53396       0.49289      1.08332      0.80737  29.42s
     20       0.53404       0.49250      1.08434      0.80737  29.41s
     21       0.53374       0.49249      1.08376      0.80737  29.48s
     22       0.53405       0.49161      1.08632      0.80737  29.40s
     23       0.53307       0.49175      1.08402      0.80737  29.40s
     24       0.53403       0.48967      1.09059      0.80737  29.41s
     25       0.53129       0.49074      1.08264      0.80737  29.40s
     26       0.53418       0.48619      1.09870      0.80737  29.40s
     27       0.52843       0.48983      1.07881      0.80737  29.47s
     28       0.53411       0.48141      1.10947      0.80737  29.40s
     29       0.52432       0.48899      1.07224      0.80737  29.40s
     30       0.53348       0.47568      1.12150      0.80775  29.40s
     31       0.51777       0.48630      1.06471      0.80737  29.40s
     32       0.52974       0.47020      1.12664      0.81025  29.40s
     33       0.50772       0.48180      1.05381      0.80750  29.40s
     34       0.52108       0.46061      1.13128      0.81500  29.46s
     35       0.49917       0.46536      1.07264      0.80937  29.41s
     36       0.47857       0.51649      0.92659      0.81988  29.40s
     37       0.49673       0.45002      1.10379      0.81600  29.40s
     38       0.45852       0.44384      1.03307      0.81725  29.50s
     39       0.46414       0.50163      0.92526      0.81650  30.38s
     40       0.40905       0.59581      0.68655      0.81225  30.79s
     41       0.45642       0.55830      0.81753      0.81225  30.79s
     42       0.51430       0.43171      1.19132      0.82038  30.80s
     43       0.43342       0.39326      1.10211      0.84775  30.80s
     44       0.36735       0.36726      1.00023      0.85720  30.79s
     45       0.29983       0.29982      1.00003      0.89032  30.81s
     46       0.29105       0.35592      0.81774      0.86238  30.80s
     47       0.27710       0.27197      1.01887      0.90990  30.80s
     48       0.22813       0.25335      0.90043      0.91648  36.18s
     49       0.20194       0.21598      0.93502      0.93732  30.89s
     50       0.15096       0.19945      0.75689      0.93220  30.94s

In [104]:
detect.train_saver('detection_tester.pkl')

In [120]:
# predict tester
import numpy as np
from scipy.misc import imread, imresize
from sklearn.feature_extraction import image

img = imread('/home/faizy/workspace/project/project/datasets/svt/svt1/img/00_13.jpg')#[292:405, 391:664, :]
patches = image.extract_patches(img, (113, 90, 3), extraction_step = 5)

new_lst = []
for i in range(patches.shape[0]):
    for j in range(patches.shape[1]):
        new_lst.append(imresize(patches[i, j, 0, :, :, :], (32, 32)))

new_list = np.stack(new_lst)
new_list = new_list.dot([0.299, 0.587, 0.144])
tester = new_list.reshape(patches.shape[0]*patches.shape[1], 1, 32, 32)

tester /= tester.std(axis = None)
tester -= tester.mean()
tester = tester.astype('float32')

preder = detect.net.predict_proba(tester)

detect.generate_heatmap(img, preder, patches.shape[0], patches.shape[1])



In [ ]: