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
In [2]:
detect = Detection()
In [3]:
x, y = detect.data_loader()
In [4]:
print x.shape, y.shape
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)
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 [ ]: