def get_train_data(): #/Users/amilgeorge/Documents/StudySS2015/DeepLearning/Training\ Data/data/raw_images/train_faces/ img_faces = imread_collection( "data/train_set/dataset/13/train/faces/*.png") # img_bkgs = imread_collection( "data/train_set/dataset/13/train/nonfaces/*.jpg") #img_faces = imread_collection("data/processed_images/13_train_set_aflw/train/faces/*.jpg") #img_bkgs = imread_collection("data/processed_images/13_train_set_aflw/train/nonfaces/*.jpg") x, y = prepare_data(img_faces, img_bkgs) #x=x[:1000] #y=y[:1000] borrow = True shared_x = theano.shared( np.asarray(x, dtype=theano.config.floatX), # @UndefinedVariable borrow=borrow) shared_y = theano.shared( np.asarray(y, dtype=theano.config.floatX), # @UndefinedVariable borrow=borrow) return shared_x, T.cast(shared_y, 'int32')
def get_train_data(): img_faces = imread_collection("data/processed_images/28_28_big_new/train/faces/*.png") img_bkgs = imread_collection("data/processed_images/28_28_big_new/train/nonfaces/*.jpg") x, y = prepare_data(img_faces, img_bkgs) return x, y
def get_train_data(): img_faces = imread_collection( "data/processed_images/28_28_big_new/train/faces/*.png") img_bkgs = imread_collection( "data/processed_images/28_28_big_new/train/nonfaces/*.jpg") x, y = prepare_data(img_faces, img_bkgs) return x, y
def evaluate_trained_net_on_patches(state,folder="data/train_set/dataset/13/validation/faces/*.png"): img_collection = imread_collection(folder) arr_imgs = concatenate_images(img_collection) arr_imgs=arr_imgs[:,:,:,np.newaxis] arr_imgs = np.rollaxis(arr_imgs, 3, 1) #arr_imgs = arr_imgs[0:10,:,:,:] borrow = True shared_x = theano.shared(np.asarray(arr_imgs, dtype=theano.config.floatX), # @UndefinedVariable borrow=borrow) num_arr_imgs= arr_imgs.shape[0] iT = T.lscalar() x = T.tensor3("x") layer0_input = x.reshape((1, NUM_CHANNELS, 13, 13)) net = twelve_net(layer0_input, None, relu, state) prediction = net.log_regression_layer.y_pred py_x = net.log_regression_layer.p_y_given_x test_model = theano.function( [iT], [prediction, py_x, layer0_input], givens={ x: shared_x[iT, :, :, :] } ) min_py_x = 99999; max_py_x = 0 num_faces = 0 thresholds = [] for i in xrange(num_arr_imgs): [out_predict,out_py_x,out_face]=test_model(i) thresholds.append(out_py_x[0,1]) if out_py_x[0,1] < min_py_x : min_py_x = out_py_x[0,1] if out_py_x[0,1] > max_py_x : max_py_x = out_py_x[0,1] if out_predict ==1: num_faces =num_faces +1 recall_index = int(num_arr_imgs * .01) thresholds.sort() t = thresholds[recall_index] print "Num faces: %d" %(num_faces) print "min_py_x(for face): %f" %(min_py_x) print "max_py_x(for face): %f" %(max_py_x) print "Num images evaluated: %d" %(num_arr_imgs) print "Threshold %f" %(t)
def get_valid_data(): #/Users/amilgeorge/Documents/StudySS2015/DeepLearning/Training\ Data/data/raw_images/train_faces/ img_faces = imread_collection("data/train_set/dataset/13/validation/faces/*.png") # img_bkgs = imread_collection("data/train_set/dataset/13/validation/nonfaces/*.jpg") #img_faces = imread_collection("data/processed_images/13_train_set_aflw/validation/faces/*.jpg") #img_bkgs = imread_collection("data/processed_images/13_train_set_aflw/validation/nonfaces/*.jpg") x, y = prepare_data(img_faces, img_bkgs) borrow = True shared_x = theano.shared(np.asarray(x, dtype=theano.config.floatX), # @UndefinedVariable borrow=borrow) shared_y = theano.shared(np.asarray(y, dtype=theano.config.floatX), # @UndefinedVariable borrow=borrow) return shared_x,T.cast(shared_y, 'int32')
def evaluate_trained_net_on_patches( state, folder="data/train_set/dataset/13/validation/faces/*.png"): img_collection = imread_collection(folder) arr_imgs = concatenate_images(img_collection) arr_imgs = arr_imgs[:, :, :, np.newaxis] arr_imgs = np.rollaxis(arr_imgs, 3, 1) #arr_imgs = arr_imgs[0:10,:,:,:] borrow = True shared_x = theano.shared( np.asarray(arr_imgs, dtype=theano.config.floatX), # @UndefinedVariable borrow=borrow) num_arr_imgs = arr_imgs.shape[0] iT = T.lscalar() x = T.tensor3("x") layer0_input = x.reshape((1, NUM_CHANNELS, 13, 13)) net = twelve_net(layer0_input, None, relu, state) prediction = net.log_regression_layer.y_pred py_x = net.log_regression_layer.p_y_given_x test_model = theano.function([iT], [prediction, py_x, layer0_input], givens={x: shared_x[iT, :, :, :]}) min_py_x = 99999 max_py_x = 0 num_faces = 0 thresholds = [] for i in xrange(num_arr_imgs): [out_predict, out_py_x, out_face] = test_model(i) thresholds.append(out_py_x[0, 1]) if out_py_x[0, 1] < min_py_x: min_py_x = out_py_x[0, 1] if out_py_x[0, 1] > max_py_x: max_py_x = out_py_x[0, 1] if out_predict == 1: num_faces = num_faces + 1 recall_index = int(num_arr_imgs * .01) thresholds.sort() t = thresholds[recall_index] print "Num faces: %d" % (num_faces) print "min_py_x(for face): %f" % (min_py_x) print "max_py_x(for face): %f" % (max_py_x) print "Num images evaluated: %d" % (num_arr_imgs) print "Threshold %f" % (t)