In [1]:
%matplotlib inline
import pandas as pd
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from termcolor import colored

face_cascade = cv2.CascadeClassifier('/home/mckc/Downloads/opencv-2.4.13/data/haarcascades_GPU/haarcascade_frontalface_default.xml')

In [2]:
#Reading the image data into numpy
def rgb2gray(rgb):
    return np.dot(rgb[:,:,:], [0.299, 0.587, 0.114])

def load_data():
    import pandas as pd
    import numpy as np
    from PIL import Image
    
    train = pd.read_csv('/home/mckc/Images/train.csv')
    test = pd.read_csv('/home/mckc/Images/test.csv')
    print 'the training data shape is ',train.shape
    print 'the test data shape is ', test.shape
    
    X_tr = np.zeros((1,1944,2592),dtype=np.uint8)
    for i in train.values[:,0]:
        image = rgb2gray(np.array(Image.open(i))).astype(np.uint8).reshape(1,1944,2592)
#     print X_tr.shape,image.shape
        X_tr =  np.vstack((X_tr,image))
    Y_tr = train.values[:,1]
    X_tr = X_tr[1:,:,:]
    X_ts = np.zeros((1,1944,2592),dtype=np.uint8)
    for i in test.values[:,0]:
        image = rgb2gray(np.array(Image.open(i))).astype(np.uint8).reshape(1,1944,2592)
        X_ts = np.vstack((X_ts,image))
    Y_ts = test.values[:,1]
    X_ts = X_ts[1:,:,:]
    print 'the training file shape',X_tr.shape,Y_tr.shape
    print 'the testing file shape',X_ts.shape,Y_ts.shape
    
    return X_tr,X_ts,Y_tr,Y_ts

In [3]:
def simulate(X,Y):
    import scipy as sp
    from scipy import misc
    complete = np.zeros((1,1944,2592),dtype=np.uint8)
    Y_complete = []
    for i in range(len(X)):
        complete = np.vstack((complete,X[i,:,:].reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = 5).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = 10).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = 15).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = -5).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = -15).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = -10).reshape(1,1944,2592)))
        rotated = np.fliplr(X[i,:,:])
        complete = np.vstack((complete,sp.misc.imrotate(rotated, angle = 5).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(rotated, angle = 10).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(rotated, angle = 15).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(rotated, angle = -5).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(rotated, angle = -10).reshape(1,1944,2592)))
        complete = np.vstack((complete,sp.misc.imrotate(rotated, angle = -15).reshape(1,1944,2592)))
        complete = np.vstack((complete,rotated.reshape(1,1944,2592)))
        Y_complete = np.append(Y_complete,([Y[i]]*14))
        if i % 10==0:
            print colored((float(i)/len(X)*100 ,' Percentage complete'),'green')
    complete = complete[1:,:,:]
    return complete,Y_complete

In [4]:
def extract_faces(X_tr,Y_tr):
    from skimage.transform import resize
    import time
    start_time = time.clock()
    all_faces = np.zeros((1,96,96),dtype=np.uint8)
    missing = []
    multiple = []
    Y= []
    for i in range(len(X_tr)):
        faces  = face_cascade.detectMultiScale(X_tr[i,:,:],scaleFactor=1.3,minNeighbors=5,minSize=(70, 70))
        n_faces = len(faces)
        if n_faces is 1:
            for (x,y,w,h) in faces:
                fac = np.array(X_tr[i,:,:])[y:(y+h),x:(x+h)]
                out = (resize(fac,(96,96))).reshape((1,96,96))
                all_faces = np.vstack((all_faces,out))
                Y = np.append(Y,Y_tr[i])
        else:
            if n_faces > 1:
                #print ('There are multiple faces for index %d and with length %d' % (i , n_faces))
                missing = np.append(missing,i)
                #all_faces = np.vstack((all_faces,np.zeros((1,96,96),dtype=np.uint8)))
            else:
                #print ('The face is missing for index %d' %i)
                multiple = np.append(multiple,i)
        if i % 50==0:
            print colored((float(i)/len(X_tr)*100 ,' Percentage complete'), 'green')

    all_faces = all_faces[1:,:,:]
    print all_faces.shape
    print time.clock() - start_time, "seconds"
    return all_faces,missing,multiple,Y

In [5]:
X_tr,X_tst,Y_tr,Y_tst = load_data()


---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-5-7a0087c8fa35> in <module>()
----> 1 X_tr,X_tst,Y_tr,Y_tst = load_data()

<ipython-input-2-9e1210878e51> in load_data()
      8     from PIL import Image
      9 
---> 10     train = pd.read_csv('/home/mckc/Images/train.csv')
     11     test = pd.read_csv('/home/mckc/Images/test.csv')
     12     print 'the training data shape is ',train.shape

/home/mckc/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
    527                     skip_blank_lines=skip_blank_lines)
    528 
--> 529         return _read(filepath_or_buffer, kwds)
    530 
    531     parser_f.__name__ = name

/home/mckc/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in _read(filepath_or_buffer, kwds)
    293 
    294     # Create the parser.
--> 295     parser = TextFileReader(filepath_or_buffer, **kwds)
    296 
    297     if (nrows is not None) and (chunksize is not None):

/home/mckc/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in __init__(self, f, engine, **kwds)
    610             self.options['has_index_names'] = kwds['has_index_names']
    611 
--> 612         self._make_engine(self.engine)
    613 
    614     def _get_options_with_defaults(self, engine):

/home/mckc/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in _make_engine(self, engine)
    745     def _make_engine(self, engine='c'):
    746         if engine == 'c':
--> 747             self._engine = CParserWrapper(self.f, **self.options)
    748         else:
    749             if engine == 'python':

/home/mckc/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in __init__(self, src, **kwds)
   1117         kwds['allow_leading_cols'] = self.index_col is not False
   1118 
-> 1119         self._reader = _parser.TextReader(src, **kwds)
   1120 
   1121         # XXX

pandas/parser.pyx in pandas.parser.TextReader.__cinit__ (pandas/parser.c:3246)()

pandas/parser.pyx in pandas.parser.TextReader._setup_parser_source (pandas/parser.c:6111)()

IOError: File /home/mckc/Images/train.csv does not exist

In [6]:
import time
start_time = time.clock()
X_train,Y_train = simulate(X_tr,Y_tr)
print X_train.shape,Y_train.shape
print time.clock() - start_time, "seconds"


(0.0, ' Percentage complete')
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-6-dee938310e87> in <module>()
      1 import time
      2 start_time = time.clock()
----> 3 X_train,Y_train = simulate(X_tr,Y_tr)
      4 print X_train.shape,Y_train.shape
      5 print time.clock() - start_time, "seconds"

<ipython-input-3-953887d7b86d> in simulate(X, Y)
      8         complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = 5).reshape(1,1944,2592)))
      9         complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = 10).reshape(1,1944,2592)))
---> 10         complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = 15).reshape(1,1944,2592)))
     11         complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = -5).reshape(1,1944,2592)))
     12         complete = np.vstack((complete,sp.misc.imrotate(X[i,:,:], angle = -15).reshape(1,1944,2592)))

/hoome/mckc/anaconda/lib/python2.7/site-packages/scipy/misc/pilutil.pyc in imrotate(arr, angle, interp)
    398     func = {'nearest': 0, 'lanczos': 1, 'bilinear': 2, 'bicubic': 3, 'cubic': 3}
    399     im = toimage(arr)
--> 400     im = im.rotate(angle, resample=func[interp])
    401     return fromimage(im)
    402 

/hoome/mckc/anaconda/lib/python2.7/site-packages/PIL/Image.pyc in rotate(self, angle, resample, expand)
   1597             resample = NEAREST
   1598 
-> 1599         return self._new(self.im.rotate(angle, resample, expand))
   1600 
   1601     def save(self, fp, format=None, **params):

KeyboardInterrupt: 

In [7]:
X,missing,multiple,Y = extract_faces(X_train[:,:,:],Y_train)
X_test,missing_test,multiple_test,Y_test = extract_faces(X_tst,Y_tst)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-cd03607a02f2> in <module>()
----> 1 X,missing,multiple,Y = extract_faces(X_train[:,:,:],Y_train)
      2 X_test,missing_test,multiple_test,Y_test = extract_faces(X_tst,Y_tst)

NameError: name 'X_train' is not defined

In [18]:
def Save_data(X,Y):
    for i in range(len(X)):
        file_name = '/home/mckc/imagees/'+Y[i]+'_'+str(i)+'.npy'
        np.save(file_name,X[i,:,:])

In [21]:
def load():
    import os
    import numpy as np
    files = os.listdir('/home/mckc/imagees/')
    X = []
    Y = []
    for i in files:
        X = np.append(X,np.load(i))
        index = i.index('_')
        Y = np.append(Y,i[:index])
    return X,Y


Out[21]:
(1706, 96, 96)

In [ ]:
from PIL import Image
image = np.array(Image.open(train.values[3,0]))
plt.imshow(X_tr[1,:,:], cmap = cm.Greys_r)
plt.show()

In [83]:
# get row number
def rgb2gray(rgb):
    return np.dot(rgb[:,:,:], [0.299, 0.587, 0.114])

gray = rgb2gray(image).astype(np.uint8)
gray.shape
plt.imshow(gray, cmap = plt.get_cmap('gray'))
plt.show()



In [45]:
faces = face_cascade.detectMultiScale(
    gray,
    scaleFactor=1.3,
    minNeighbors=6,
    minSize=(40, 40))
print "Found {0} faces!".format(len(faces))
for (x,y,w,h) in faces:
    fac = np.array(gray)[y:(y+h),x:(x+h)]
    
plt.imshow(fac,cmap=plt.get_cmap('gray'))


Found 1 faces!
Out[45]:
<matplotlib.image.AxesImage at 0x7fb4c3d6b890>

In [7]:
#Normalising
X = X -0.5
X_test = X_test - 0.5

print X.mean(),X_test.mean()

In [3]:
X.mean()


Out[3]:
0.036512346746588729

In [13]:
map, Y_number = np.unique(Y, return_inverse=True)
Y_test_numer = np.unique(Y_test, return_inverse=True)[1]

In [14]:
print map,X.dtype


['Abhay' 'Gopika'] float64

In [15]:
print len(X),len(Y_number),X.shape


15722496 1706 (15722496,)

In [16]:
X = X.astype(np.float16)
X_test = X_test.astype(np.float16)

In [165]:
import lasagne
#from lasagne.layers.cuda_convnet import Conv2DCCLayer as Conv2DLayer
#from lasagne.layers.cuda_convnet import MaxPool2DCCLayer as MaxPool2DLayer
from lasagne import layers
from lasagne.objectives import categorical_crossentropy
from lasagne.updates import nesterov_momentum
from nolearn.lasagne import BatchIterator,visualize,NeuralNet
Conv2DLayer = layers.Conv2DLayer
MaxPool2DLayer = layers.MaxPool2DLayer

net = NeuralNet(
    layers=[
        ('input', layers.InputLayer),
        ('conv1', Conv2DLayer),
        ('pool1', MaxPool2DLayer),
        ('dropout1', layers.DropoutLayer),
        ('conv2', Conv2DLayer),
        ('pool2', MaxPool2DLayer),
        ('dropout2', layers.DropoutLayer),
        ('conv3', Conv2DLayer),
        ('pool3', MaxPool2DLayer),
        ('dropout3', layers.DropoutLayer),
        ('hidden4', layers.DenseLayer),
        ('dropout4', layers.DropoutLayer),
        ('hidden5', layers.DenseLayer),
        ('output', layers.DenseLayer),
        ],
    input_shape=(None, 1, 96, 96),
    conv1_num_filters=32, conv1_filter_size=(3, 3), pool1_pool_size=(2, 2),
    dropout1_p=0.1,
    conv2_num_filters=64, conv2_filter_size=(2, 2), pool2_pool_size=(2, 2),
    dropout2_p=0.2,
    conv3_num_filters=128, conv3_filter_size=(2, 2), pool3_pool_size=(2, 2),
    dropout3_p=0.3,
    hidden4_num_units=1000,
    dropout4_p=0.5,
    hidden5_num_units=1000,
    output_nonlinearity=lasagne.nonlinearities.softmax,
    output_num_units=2,
    
    update = nesterov_momentum,
    update_learning_rate=0.001,
    update_momentum=0.9,
    max_epochs=500,
    verbose=1,
)
net.fit(X.reshape(-1,1,96,96), Y_number.astype(np.uint8))


# Neural Network with 16533474 learnable parameters

## Layer information

  #  name      size
---  --------  ---------
  0  input     1x96x96
  1  conv1     32x94x94
  2  pool1     32x47x47
  3  dropout1  32x47x47
  4  conv2     64x46x46
  5  pool2     64x23x23
  6  dropout2  64x23x23
  7  conv3     128x22x22
  8  pool3     128x11x11
  9  dropout3  128x11x11
 10  hidden4   1000
 11  dropout4  1000
 12  hidden5   1000
 13  output    2

  epoch    trn loss    val loss    trn/val    valid acc  dur
-------  ----------  ----------  ---------  -----------  ------
      1     0.69386     0.69041    1.00499      0.67251  46.65s
      2     0.68817     0.68435    1.00558      0.75731  44.38s
      3     0.68142     0.67762    1.00561      0.58480  44.78s
      4     0.67365     0.67043    1.00480      0.56725  46.58s
      5     0.66619     0.66254    1.00550      0.59064  43.95s
      6     0.65711     0.65319    1.00601      0.69006  42.65s
      7     0.64663     0.64165    1.00777      0.78947  44.25s
      8     0.62987     0.62646    1.00544      0.87427  45.83s
      9     0.61122     0.60604    1.00855      0.93567  44.73s
     10     0.58295     0.57761    1.00924      0.96491  44.37s
     11     0.54561     0.53743    1.01523      0.97661  44.72s
     12     0.49048     0.47991    1.02202      0.97661  44.16s
     13     0.42260     0.40200    1.05124      0.99415  44.93s
     14     0.33434     0.30805    1.08534      0.99415  43.58s
     15     0.23833     0.21522    1.10739      1.00000  44.94s
     16     0.16309     0.14372    1.13483      1.00000  43.03s
     17     0.11459     0.09866    1.16145      1.00000  42.60s
     18     0.07609     0.07191    1.05821      1.00000  41.71s
     19     0.05872     0.05578    1.05272      0.99708  43.05s
     20     0.05021     0.04533    1.10761      1.00000  43.41s
     21     0.04533     0.03812    1.18902      1.00000  45.03s
     22     0.03874     0.03306    1.17168      1.00000  44.62s
     23     0.03362     0.02901    1.15886      1.00000  45.08s
     24     0.03155     0.02584    1.22116      1.00000  45.25s
     25     0.02783     0.02340    1.18947      1.00000  44.63s
     26     0.02994     0.02166    1.38224      1.00000  44.96s
     27     0.02250     0.01975    1.13891      1.00000  47.26s
     28     0.02625     0.01812    1.44872      1.00000  45.91s
     29     0.02363     0.01680    1.40666      1.00000  43.91s
     30     0.02441     0.01569    1.55531      1.00000  44.97s
     31     0.01992     0.01469    1.35623      1.00000  48.68s
     32     0.01973     0.01381    1.42831      1.00000  48.98s
     33     0.01964     0.01301    1.50989      1.00000  49.83s
     34     0.01868     0.01233    1.51568      1.00000  48.44s
     35     0.01630     0.01178    1.38346      1.00000  51.70s
     36     0.02007     0.01113    1.80338      1.00000  48.99s
     37     0.02058     0.01075    1.91434      1.00000  51.20s
     38     0.01754     0.01067    1.64403      1.00000  51.65s
     39     0.01770     0.00981    1.80525      1.00000  52.89s
     40     0.01868     0.00931    2.00615      1.00000  50.68s
     41     0.01548     0.00892    1.73572      1.00000  56.50s
     42     0.01689     0.00905    1.86603      1.00000  50.03s
     43     0.01426     0.00849    1.68005      1.00000  49.78s
     44     0.01739     0.00790    2.20167      1.00000  51.82s
     45     0.02035     0.00768    2.64940      1.00000  49.89s
     46     0.01627     0.00745    2.18411      1.00000  53.37s
     47     0.01521     0.00710    2.14304      1.00000  55.18s
     48     0.01633     0.00682    2.39436      1.00000  50.51s
     49     0.01355     0.00658    2.06022      1.00000  56.80s
     50     0.01242     0.00638    1.94619      1.00000  54.47s
     51     0.01090     0.00628    1.73600      1.00000  57.36s
     52     0.01294     0.00614    2.10767      1.00000  68.59s
     53     0.01578     0.00597    2.64189      1.00000  59.49s
     54     0.01674     0.00582    2.87715      1.00000  55.62s
     55     0.01341     0.00537    2.49514      1.00000  55.86s
     56     0.01412     0.00521    2.70875      1.00000  57.73s
     57     0.01147     0.00525    2.18502      1.00000  56.06s
     58     0.01495     0.00511    2.92464      1.00000  56.09s
     59     0.01420     0.00478    2.97089      1.00000  59.60s
     60     0.01272     0.00473    2.69186      1.00000  60.99s
     61     0.01360     0.00460    2.95570      1.00000  72.99s
     62     0.01360     0.00466    2.92036      1.00000  67.48s
     63     0.01551     0.00444    3.49214      1.00000  72.90s
     64     0.01362     0.00428    3.17972      1.00000  69.31s
     65     0.01745     0.00451    3.86646      1.00000  70.40s
     66     0.01095     0.00449    2.43671      1.00000  79.56s
     67     0.00953     0.00426    2.23416      1.00000  68.91s
     68     0.01291     0.00391    3.29862      1.00000  74.49s
     69     0.00944     0.00393    2.40320      1.00000  72.75s
     70     0.01004     0.00381    2.63615      1.00000  78.00s
     71     0.00956     0.00382    2.50503      1.00000  69.78s
     72     0.01004     0.00382    2.62855      1.00000  69.43s
     73     0.01030     0.00354    2.90664      1.00000  76.87s
     74     0.01206     0.00343    3.52013      1.00000  71.09s
     75     0.00853     0.00344    2.48096      1.00000  74.92s
     76     0.01207     0.00314    3.84647      1.00000  79.03s
     77     0.01427     0.00344    4.14697      1.00000  73.27s
     78     0.01197     0.00342    3.49651      1.00000  67.44s
     79     0.01101     0.00309    3.56593      1.00000  70.60s
     80     0.00839     0.00292    2.87367      1.00000  74.70s
     81     0.00868     0.00282    3.08111      1.00000  75.34s
     82     0.01229     0.00277    4.43554      1.00000  79.62s
     83     0.00934     0.00271    3.44168      1.00000  69.57s
     84     0.00824     0.00269    3.05767      1.00000  74.54s
     85     0.01330     0.00269    4.93966      1.00000  73.69s
     86     0.01059     0.00285    3.70965      1.00000  74.41s
     87     0.00747     0.00253    2.94887      1.00000  72.10s
     88     0.01090     0.00248    4.38953      1.00000  72.56s
     89     0.01156     0.00245    4.72617      1.00000  71.00s
     90     0.00643     0.00260    2.47157      1.00000  75.79s
     91     0.00696     0.00283    2.45848      1.00000  74.05s
     92     0.00830     0.00304    2.72997      1.00000  67.42s
     93     0.01070     0.00231    4.62959      1.00000  71.54s
     94     0.01764     0.00237    7.45440      1.00000  76.37s
     95     0.01197     0.00236    5.06819      1.00000  74.12s
     96     0.01255     0.00250    5.02182      1.00000  81.11s
     97     0.00849     0.00241    3.52958      1.00000  72.47s
     98     0.01009     0.00223    4.51965      1.00000  76.85s
     99     0.00643     0.00224    2.86369      1.00000  76.78s
    100     0.00851     0.00223    3.80914      1.00000  79.34s
    101     0.01326     0.00237    5.58852      1.00000  73.75s
    102     0.01542     0.00240    6.41913      1.00000  76.24s
    103     0.00748     0.00219    3.41069      1.00000  70.56s
    104     0.00882     0.00211    4.18416      1.00000  82.63s
    105     0.00723     0.00205    3.53423      1.00000  76.62s
    106     0.00746     0.00197    3.78059      1.00000  81.23s
    107     0.00699     0.00201    3.48054      1.00000  72.57s
    108     0.00869     0.00211    4.11963      1.00000  71.23s
    109     0.00554     0.00198    2.80602      1.00000  74.93s
    110     0.00710     0.00178    3.97882      1.00000  73.50s
    111     0.00709     0.00176    4.04107      1.00000  72.26s
    112     0.00980     0.00173    5.67461      1.00000  69.23s
    113     0.01073     0.00204    5.26793      1.00000  69.54s
    114     0.00847     0.00235    3.60333      1.00000  75.65s
    115     0.00766     0.00197    3.89034      1.00000  74.02s
    116     0.01341     0.00200    6.69772      1.00000  69.92s
    117     0.01013     0.00182    5.56408      1.00000  73.31s
    118     0.00631     0.00192    3.28472      1.00000  71.29s
    119     0.00985     0.00178    5.53136      1.00000  63.15s
    120     0.01578     0.00174    9.05199      1.00000  67.16s
    121     0.00868     0.00173    5.02172      1.00000  68.85s
    122     0.01389     0.00167    8.29838      1.00000  75.41s
    123     0.01044     0.00192    5.43054      1.00000  59.92s
    124     0.01137     0.00175    6.50745      1.00000  73.70s
    125     0.00731     0.00172    4.24518      1.00000  64.69s
    126     0.00963     0.00167    5.76700      1.00000  64.81s
    127     0.00950     0.00154    6.15808      1.00000  63.73s
    128     0.01273     0.00157    8.09915      1.00000  69.19s
    129     0.01203     0.00187    6.42885      1.00000  75.84s
    130     0.00716     0.00189    3.77956      1.00000  71.38s
    131     0.01306     0.00179    7.30049      1.00000  73.59s
    132     0.01080     0.00164    6.58957      1.00000  79.44s
    133     0.00885     0.00158    5.61566      1.00000  66.68s
    134     0.00821     0.00159    5.18010      1.00000  82.21s
    135     0.00923     0.00150    6.17046      1.00000  75.07s
    136     0.01112     0.00160    6.94290      1.00000  66.67s
    137     0.00851     0.00187    4.55183      1.00000  72.20s
    138     0.00958     0.00165    5.80460      1.00000  74.52s
    139     0.01002     0.00156    6.43188      1.00000  70.15s
    140     0.00613     0.00144    4.26035      1.00000  75.18s
    141     0.01380     0.00164    8.39468      1.00000  75.18s
    142     0.00507     0.00176    2.87531      1.00000  69.24s
    143     0.00743     0.00144    5.15422      1.00000  72.12s
    144     0.00932     0.00138    6.75579      1.00000  77.35s
    145     0.00812     0.00141    5.76590      1.00000  69.28s
    146     0.00896     0.00145    6.18362      1.00000  76.00s
    147     0.00554     0.00147    3.75942      1.00000  74.77s
    148     0.00844     0.00148    5.70449      1.00000  69.54s
    149     0.01194     0.00141    8.48440      1.00000  71.12s
    150     0.00754     0.00135    5.57978      1.00000  69.36s
    151     0.00455     0.00150    3.03469      1.00000  72.59s
    152     0.00755     0.00146    5.15867      1.00000  74.86s
    153     0.00567     0.00138    4.12407      1.00000  63.53s
    154     0.00925     0.00128    7.23577      1.00000  75.20s
    155     0.00769     0.00135    5.68545      1.00000  66.20s
    156     0.00647     0.00139    4.66575      1.00000  72.10s
    157     0.00901     0.00127    7.12402      1.00000  68.14s
    158     0.00519     0.00118    4.41358      1.00000  79.67s
    159     0.00801     0.00116    6.90565      1.00000  70.63s
    160     0.01016     0.00118    8.59262      1.00000  63.51s
    161     0.00702     0.00123    5.71042      1.00000  77.89s
    162     0.00628     0.00117    5.36959      1.00000  72.27s
    163     0.00562     0.00125    4.48763      1.00000  72.30s
    164     0.00548     0.00115    4.74730      1.00000  70.24s
    165     0.00859     0.00111    7.72670      1.00000  76.44s
    166     0.01002     0.00113    8.87763      1.00000  63.20s
    167     0.00547     0.00125    4.38677      1.00000  82.78s
    168     0.00719     0.00121    5.93819      1.00000  69.67s
    169     0.01437     0.00143   10.01724      1.00000  78.70s
    170     0.00599     0.00154    3.87568      1.00000  75.01s
    171     0.00639     0.00130    4.91892      1.00000  72.42s
    172     0.00873     0.00133    6.53830      1.00000  69.36s
    173     0.01003     0.00136    7.35803      1.00000  77.89s
    174     0.00908     0.00116    7.79308      1.00000  67.92s
    175     0.00512     0.00113    4.54372      1.00000  81.88s
    176     0.01108     0.00117    9.50298      1.00000  69.93s
    177     0.00577     0.00127    4.54928      1.00000  73.15s
    178     0.00858     0.00113    7.58264      1.00000  77.66s
    179     0.00804     0.00113    7.08560      1.00000  71.03s
    180     0.01050     0.00130    8.04521      1.00000  70.98s
    181     0.01148     0.00187    6.12277      1.00000  71.07s
    182     0.01063     0.00143    7.43135      1.00000  77.74s
    183     0.00933     0.00121    7.73413      1.00000  73.11s
    184     0.00608     0.00118    5.16268      1.00000  68.27s
    185     0.00903     0.00124    7.26486      1.00000  73.70s
    186     0.00624     0.00136    4.59702      1.00000  77.45s
    187     0.00962     0.00121    7.96553      1.00000  69.59s
    188     0.00609     0.00110    5.54900      1.00000  79.28s
    189     0.00751     0.00106    7.07117      1.00000  76.92s
    190     0.00811     0.00110    7.37132      1.00000  78.33s
    191     0.00561     0.00116    4.85287      1.00000  82.90s
    192     0.00987     0.00114    8.62804      1.00000  73.69s
    193     0.01156     0.00120    9.60133      1.00000  80.08s
    194     0.00812     0.00114    7.15236      1.00000  69.67s
    195     0.00700     0.00106    6.57650      1.00000  83.11s
    196     0.01120     0.00117    9.56660      1.00000  68.14s
    197     0.00921     0.00119    7.71444      1.00000  78.95s
    198     0.01025     0.00128    8.02687      1.00000  71.80s
    199     0.00508     0.00120    4.22028      1.00000  73.36s
    200     0.00875     0.00122    7.15155      1.00000  81.19s
    201     0.00877     0.00117    7.48564      1.00000  69.92s
    202     0.01140     0.00115    9.90369      1.00000  72.63s
    203     0.01103     0.00112    9.86290      1.00000  73.91s
    204     0.00863     0.00113    7.65130      1.00000  76.88s
    205     0.00874     0.00132    6.59811      1.00000  69.37s
    206     0.01402     0.00136   10.27652      1.00000  84.32s
    207     0.00948     0.00115    8.25207      1.00000  71.26s
    208     0.00612     0.00122    5.00926      1.00000  69.81s
    209     0.00806     0.00110    7.30105      1.00000  70.56s
    210     0.00394     0.00099    3.96114      1.00000  69.18s
    211     0.00902     0.00095    9.44415      1.00000  66.42s
    212     0.00832     0.00095    8.74423      1.00000  73.54s
    213     0.00642     0.00102    6.28596      1.00000  76.21s
    214     0.00677     0.00105    6.45198      1.00000  70.05s
    215     0.00533     0.00101    5.29146      1.00000  74.59s
    216     0.00821     0.00100    8.16962      1.00000  68.33s
    217     0.00855     0.00097    8.77391      1.00000  74.76s
    218     0.01071     0.00096   11.10586      1.00000  62.47s
    219     0.01059     0.00099   10.70862      1.00000  76.83s
    220     0.00937     0.00102    9.17175      1.00000  72.36s
    221     0.00596     0.00099    5.99662      1.00000  69.97s
    222     0.00712     0.00095    7.48546      1.00000  72.01s
    223     0.00586     0.00102    5.72937      1.00000  74.84s
    224     0.00653     0.00101    6.47349      1.00000  71.07s
    225     0.01072     0.00104   10.33222      1.00000  72.16s
    226     0.00676     0.00121    5.57746      1.00000  70.04s
    227     0.00526     0.00118    4.45685      1.00000  63.47s
    228     0.00873     0.00104    8.40872      1.00000  73.52s
    229     0.00566     0.00099    5.71269      1.00000  71.52s
    230     0.00955     0.00096    9.90981      1.00000  69.61s
    231     0.00746     0.00092    8.08581      1.00000  66.03s
    232     0.00943     0.00090   10.42439      1.00000  73.92s
    233     0.00576     0.00094    6.14546      1.00000  66.98s
    234     0.00630     0.00094    6.71741      1.00000  72.69s
    235     0.00413     0.00101    4.07260      1.00000  69.06s
    236     0.00560     0.00104    5.38859      1.00000  71.80s
    237     0.00598     0.00088    6.80729      1.00000  75.78s
    238     0.00379     0.00084    4.52458      1.00000  68.22s
    239     0.00524     0.00083    6.29197      1.00000  69.81s
    240     0.01071     0.00090   11.86309      1.00000  73.90s
    241     0.00582     0.00099    5.88192      1.00000  61.99s
    242     0.00606     0.00086    7.07584      1.00000  78.68s
    243     0.00542     0.00080    6.73182      1.00000  71.51s
    244     0.00531     0.00078    6.82183      1.00000  68.44s
    245     0.01100     0.00099   11.11857      1.00000  68.02s
    246     0.00473     0.00110    4.30551      1.00000  74.99s
    247     0.00724     0.00093    7.76702      1.00000  73.44s
    248     0.00492     0.00081    6.04304      1.00000  62.24s
    249     0.01156     0.00079   14.62161      1.00000  68.05s
    250     0.00544     0.00089    6.10424      1.00000  84.24s
    251     0.00473     0.00088    5.38629      1.00000  67.66s
    252     0.00997     0.00091   10.98123      1.00000  67.88s
    253     0.00706     0.00088    8.07062      1.00000  63.57s
    254     0.00869     0.00086   10.08620      1.00000  77.61s
    255     0.00389     0.00089    4.39257      1.00000  75.59s
    256     0.01067     0.00089   12.00122      1.00000  69.77s
    257     0.00459     0.00091    5.03096      1.00000  72.31s
    258     0.00793     0.00087    9.07415      1.00000  72.25s
    259     0.00712     0.00079    9.00566      1.00000  80.02s
    260     0.00327     0.00074    4.42021      1.00000  70.86s
    261     0.00596     0.00070    8.48364      1.00000  71.90s
    262     0.01033     0.00071   14.60110      1.00000  68.15s
    263     0.01035     0.00078   13.24089      1.00000  80.45s
    264     0.00791     0.00081    9.75291      1.00000  70.03s
    265     0.00655     0.00077    8.46772      1.00000  71.52s
    266     0.00671     0.00073    9.23630      1.00000  70.90s
    267     0.00735     0.00070   10.52327      1.00000  75.20s
    268     0.01017     0.00070   14.47086      1.00000  68.57s
    269     0.00607     0.00076    7.98602      1.00000  75.96s
    270     0.01233     0.00075   16.33838      1.00000  69.40s
    271     0.00852     0.00074   11.48552      1.00000  72.20s
    272     0.00586     0.00080    7.30886      1.00000  67.63s
    273     0.00343     0.00086    3.98308      1.00000  81.36s
    274     0.00637     0.00075    8.53197      1.00000  71.05s
    275     0.00836     0.00086    9.76922      1.00000  78.13s
    276     0.00818     0.00086    9.49368      1.00000  66.63s
    277     0.00773     0.00081    9.49037      1.00000  75.32s
    278     0.00662     0.00072    9.17861      1.00000  69.44s
    279     0.00616     0.00069    8.94115      1.00000  70.14s
    280     0.01035     0.00071   14.64609      1.00000  75.24s
    281     0.00649     0.00084    7.74920      1.00000  64.17s
    282     0.00726     0.00083    8.79716      1.00000  67.91s
    283     0.00485     0.00072    6.69852      1.00000  70.94s
    284     0.01171     0.00079   14.88448      1.00000  73.30s
    285     0.00373     0.00104    3.57980      1.00000  77.06s
    286     0.00589     0.00096    6.12551      1.00000  71.69s
    287     0.00655     0.00077    8.52365      1.00000  78.33s
    288     0.00738     0.00066   11.19891      1.00000  67.89s
    289     0.00482     0.00067    7.22975      1.00000  70.00s
    290     0.00686     0.00069    9.99460      1.00000  76.08s
    291     0.00862     0.00072   11.98104      1.00000  76.85s
    292     0.00644     0.00074    8.74247      1.00000  65.18s
    293     0.00537     0.00066    8.18247      1.00000  71.03s
    294     0.00621     0.00064    9.75987      1.00000  79.53s
    295     0.00868     0.00066   13.23944      1.00000  65.45s
    296     0.00661     0.00068    9.65570      1.00000  77.05s
    297     0.00900     0.00068   13.23838      1.00000  68.57s
    298     0.00705     0.00071    9.86721      1.00000  80.62s
    299     0.00716     0.00069   10.36823      1.00000  70.53s
    300     0.00412     0.00067    6.17635      1.00000  70.22s
    301     0.00501     0.00064    7.82066      1.00000  78.21s
    302     0.01031     0.00064   16.07217      1.00000  66.75s
    303     0.00532     0.00070    7.56776      1.00000  78.64s
    304     0.00836     0.00076   10.98644      1.00000  69.55s
    305     0.00761     0.00071   10.77908      1.00000  80.15s
    306     0.00648     0.00068    9.60143      1.00000  63.87s
    307     0.01092     0.00069   15.90056      1.00000  71.97s
    308     0.00520     0.00070    7.47978      1.00000  67.71s
    309     0.00638     0.00071    9.04730      1.00000  71.63s
    310     0.00782     0.00079    9.93967      1.00000  73.60s
    311     0.00804     0.00076   10.51525      1.00000  67.73s
    312     0.00705     0.00070   10.00167      1.00000  63.48s
    313     0.00325     0.00072    4.49025      1.00000  72.16s
    314     0.00696     0.00070   10.00499      1.00000  74.41s
    315     0.01008     0.00081   12.51918      1.00000  68.24s
    316     0.00876     0.00081   10.77326      1.00000  72.63s
    317     0.00402     0.00073    5.54120      1.00000  73.38s
    318     0.00858     0.00068   12.62889      1.00000  62.78s
    319     0.00403     0.00067    6.00930      1.00000  66.67s
    320     0.00483     0.00067    7.20580      1.00000  73.34s
    321     0.00686     0.00068   10.03537      1.00000  69.40s
    322     0.00512     0.00073    7.00191      1.00000  71.93s
    323     0.00579     0.00078    7.46036      1.00000  66.48s
    324     0.00905     0.00071   12.69941      1.00000  77.19s
    325     0.00800     0.00075   10.63140      1.00000  64.17s
    326     0.00539     0.00073    7.40317      1.00000  74.29s
    327     0.00975     0.00072   13.57277      1.00000  72.08s
    328     0.00733     0.00071   10.37945      1.00000  66.43s
    329     0.00559     0.00069    8.12395      1.00000  66.89s
    330     0.00865     0.00075   11.48111      1.00000  67.19s
    331     0.00768     0.00105    7.30428      1.00000  64.21s
    332     0.00651     0.00102    6.36008      1.00000  70.34s
    333     0.00942     0.00096    9.77463      1.00000  72.68s
    334     0.00881     0.00084   10.50966      1.00000  66.49s
    335     0.00862     0.00089    9.68350      1.00000  71.73s
    336     0.00598     0.00094    6.34267      1.00000  70.67s
    337     0.00763     0.00085    8.94043      1.00000  72.51s
    338     0.00547     0.00075    7.33909      1.00000  64.37s
    339     0.00647     0.00069    9.32824      1.00000  69.86s
    340     0.00664     0.00070    9.44961      1.00000  72.47s
    341     0.01081     0.00076   14.16811      1.00000  72.23s
    342     0.00461     0.00082    5.62492      1.00000  74.06s
    343     0.00570     0.00076    7.50812      1.00000  70.30s
    344     0.00641     0.00074    8.71005      1.00000  69.98s
    345     0.00735     0.00078    9.41473      1.00000  66.31s
    346     0.00886     0.00074   12.02867      1.00000  73.03s
    347     0.00498     0.00073    6.87001      1.00000  75.85s
    348     0.01172     0.00077   15.27702      1.00000  67.25s
    349     0.00798     0.00075   10.58896      1.00000  65.05s
    350     0.00511     0.00083    6.16533      1.00000  74.56s
    351     0.00612     0.00078    7.81767      1.00000  73.29s
    352     0.00688     0.00089    7.76743      1.00000  70.77s
    353     0.00477     0.00084    5.69978      1.00000  59.04s
    354     0.00510     0.00072    7.07192      1.00000  78.20s
    355     0.00707     0.00072    9.75203      1.00000  65.43s
    356     0.00670     0.00081    8.22420      1.00000  73.34s
    357     0.00925     0.00077   12.05116      1.00000  68.67s
    358     0.00641     0.00071    9.07067      1.00000  71.23s
    359     0.00726     0.00072   10.14225      1.00000  69.61s
    360     0.00718     0.00070   10.25715      1.00000  74.37s
    361     0.00952     0.00075   12.63424      1.00000  70.36s
    362     0.00551     0.00080    6.86643      1.00000  69.18s
    363     0.00777     0.00070   11.11166      1.00000  65.13s
    364     0.00800     0.00066   12.13420      1.00000  71.82s
    365     0.00644     0.00066    9.76726      1.00000  72.73s
    366     0.01015     0.00079   12.79656      1.00000  61.30s
    367     0.00592     0.00076    7.74197      1.00000  72.56s
    368     0.00889     0.00077   11.59716      1.00000  77.59s
    369     0.00652     0.00072    9.10415      1.00000  65.78s
    370     0.01151     0.00070   16.54171      1.00000  71.60s
    371     0.00581     0.00068    8.50374      1.00000  66.49s
    372     0.00531     0.00066    8.00588      1.00000  68.53s
    373     0.00345     0.00067    5.11855      1.00000  78.64s
    374     0.00458     0.00067    6.79513      1.00000  63.01s
    375     0.00971     0.00065   15.03442      1.00000  78.19s
    376     0.00747     0.00065   11.41938      1.00000  68.52s
    377     0.00715     0.00066   10.85203      1.00000  67.70s
    378     0.00637     0.00069    9.25245      1.00000  70.56s
    379     0.00545     0.00075    7.27353      1.00000  71.10s
    380     0.00725     0.00074    9.78408      1.00000  79.42s
    381     0.00489     0.00072    6.77888      1.00000  71.80s
    382     0.00783     0.00064   12.14348      1.00000  63.41s
    383     0.00537     0.00066    8.10630      1.00000  82.83s
    384     0.01074     0.00069   15.64217      1.00000  68.76s
    385     0.00973     0.00069   14.16908      1.00000  79.88s
    386     0.00492     0.00065    7.52269      1.00000  67.00s
    387     0.00998     0.00070   14.19369      1.00000  64.71s
    388     0.00581     0.00071    8.14013      1.00000  72.77s
    389     0.00708     0.00071    9.93058      1.00000  73.60s
    390     0.00566     0.00071    7.98373      1.00000  61.90s
    391     0.00798     0.00068   11.72882      1.00000  75.49s
    392     0.00335     0.00069    4.88826      1.00000  66.04s
    393     0.00724     0.00068   10.66876      1.00000  67.23s
    394     0.00943     0.00069   13.58097      1.00000  69.59s
    395     0.00771     0.00070   10.97490      1.00000  68.39s
    396     0.00684     0.00071    9.57294      1.00000  65.45s
    397     0.00904     0.00077   11.67708      1.00000  72.47s
    398     0.00704     0.00080    8.75031      1.00000  65.95s
    399     0.00707     0.00081    8.72700      1.00000  65.76s
    400     0.00601     0.00081    7.40563      1.00000  74.94s
    401     0.00458     0.00075    6.08998      1.00000  68.66s
    402     0.00366     0.00074    4.95106      1.00000  77.43s
    403     0.00975     0.00079   12.27227      1.00000  71.87s
    404     0.00870     0.00075   11.64566      1.00000  79.23s
    405     0.00951     0.00074   12.92352      1.00000  76.65s
    406     0.00562     0.00071    7.94800      1.00000  61.38s
    407     0.00552     0.00069    7.96279      1.00000  77.09s
    408     0.00547     0.00068    8.03528      1.00000  79.06s
    409     0.00434     0.00067    6.46751      1.00000  64.29s
    410     0.00719     0.00068   10.51951      1.00000  75.90s
    411     0.00524     0.00070    7.51424      1.00000  76.50s
    412     0.00452     0.00069    6.52565      1.00000  63.89s
    413     0.00515     0.00066    7.79610      1.00000  71.56s
    414     0.00759     0.00066   11.43698      1.00000  69.35s
    415     0.00612     0.00070    8.76639      1.00000  69.71s
    416     0.00633     0.00071    8.96379      1.00000  83.53s
    417     0.00954     0.00068   13.99709      1.00000  65.44s
    418     0.00693     0.00066   10.57769      1.00000  75.44s
    419     0.00592     0.00067    8.90082      1.00000  68.59s
    420     0.00513     0.00065    7.86432      1.00000  72.31s
    421     0.00730     0.00065   11.18359      1.00000  69.41s
    422     0.00445     0.00078    5.73348      1.00000  67.16s
    423     0.00902     0.00075   12.07112      1.00000  72.42s
    424     0.00656     0.00067    9.76138      1.00000  76.57s
    425     0.00801     0.00064   12.57505      1.00000  71.00s
    426     0.00396     0.00066    6.04371      1.00000  69.94s
    427     0.00512     0.00067    7.69716      1.00000  68.10s
    428     0.00652     0.00063   10.30622      1.00000  65.84s
    429     0.00465     0.00061    7.57041      1.00000  65.53s
    430     0.00913     0.00064   14.34624      1.00000  79.28s
    431     0.00538     0.00064    8.43209      1.00000  64.48s
    432     0.00454     0.00060    7.52715      1.00000  82.01s
    433     0.00500     0.00062    8.10160      1.00000  72.31s
    434     0.01007     0.00067   14.99773      1.00000  70.00s
    435     0.00507     0.00065    7.78268      1.00000  75.12s
    436     0.00603     0.00064    9.38292      1.00000  73.79s
    437     0.00658     0.00066    9.90949      1.00000  73.13s
    438     0.00787     0.00066   11.97070      1.00000  74.68s
    439     0.00435     0.00063    6.92910      1.00000  74.09s
    440     0.00545     0.00063    8.67178      1.00000  66.16s
    441     0.00750     0.00062   12.14439      1.00000  68.89s
    442     0.00379     0.00061    6.20401      1.00000  75.30s
    443     0.00459     0.00061    7.53213      1.00000  78.43s
    444     0.00496     0.00065    7.62264      1.00000  80.86s
    445     0.00524     0.00064    8.18987      1.00000  70.25s
    446     0.00755     0.00061   12.45387      1.00000  70.40s
    447     0.00653     0.00060   10.94597      1.00000  79.44s
    448     0.00625     0.00062   10.07931      1.00000  74.90s
    449     0.00784     0.00061   12.90467      1.00000  68.89s
    450     0.00535     0.00060    8.85610      1.00000  68.56s
    451     0.00585     0.00060    9.71337      1.00000  68.15s
    452     0.00574     0.00059    9.65631      1.00000  77.55s
    453     0.00656     0.00060   10.88725      1.00000  70.79s
    454     0.00861     0.00060   14.44622      1.00000  70.84s
    455     0.00625     0.00060   10.45676      1.00000  71.24s
    456     0.00579     0.00061    9.49400      1.00000  68.72s
    457     0.00711     0.00058   12.21030      1.00000  75.04s
    458     0.00321     0.00057    5.63035      1.00000  82.19s
    459     0.00392     0.00055    7.07220      1.00000  68.80s
    460     0.00410     0.00056    7.32375      1.00000  67.06s
    461     0.00423     0.00055    7.66181      1.00000  67.25s
    462     0.00307     0.00054    5.66990      1.00000  75.69s
    463     0.00771     0.00055   14.00513      1.00000  67.39s
    464     0.00651     0.00054   11.95498      1.00000  69.87s
    465     0.00224     0.00053    4.19353      1.00000  78.00s
    466     0.00615     0.00054   11.49842      1.00000  56.07s
    467     0.00690     0.00056   12.34982      1.00000  81.07s
    468     0.00447     0.00063    7.06208      1.00000  61.25s
    469     0.00815     0.00062   13.21256      1.00000  72.49s
    470     0.00571     0.00062    9.26409      1.00000  69.26s
    471     0.00603     0.00059   10.19677      1.00000  67.28s
    472     0.00542     0.00061    8.81726      1.00000  69.87s
    473     0.00721     0.00059   12.23093      1.00000  72.23s
    474     0.00589     0.00053   11.01901      1.00000  69.12s
    475     0.01024     0.00056   18.36613      1.00000  63.72s
    476     0.00710     0.00053   13.42381      1.00000  70.73s
    477     0.00848     0.00054   15.71615      1.00000  82.24s
    478     0.00719     0.00053   13.69603      1.00000  55.54s
    479     0.00371     0.00051    7.30062      1.00000  66.00s
    480     0.00740     0.00052   14.34664      1.00000  63.09s
    481     0.00486     0.00053    9.10850      1.00000  65.33s
    482     0.00754     0.00055   13.82263      1.00000  71.96s
    483     0.00480     0.00055    8.66797      1.00000  70.14s
    484     0.00479     0.00055    8.77515      1.00000  66.90s
    485     0.00341     0.00054    6.32244      1.00000  62.41s
    486     0.00439     0.00053    8.34561      1.00000  68.09s
    487     0.00669     0.00053   12.70705      1.00000  66.29s
    488     0.00981     0.00054   18.06337      1.00000  66.59s
    489     0.00761     0.00057   13.31201      1.00000  70.09s
    490     0.00410     0.00056    7.29933      1.00000  69.03s
    491     0.00351     0.00057    6.17951      1.00000  66.11s
    492     0.00626     0.00053   11.72878      1.00000  73.55s
    493     0.00541     0.00053   10.14185      1.00000  73.10s
    494     0.00751     0.00054   14.00704      1.00000  61.56s
    495     0.01042     0.00059   17.67584      1.00000  75.55s
    496     0.00637     0.00060   10.68585      1.00000  61.49s
    497     0.00591     0.00062    9.53279      1.00000  71.46s
    498     0.00778     0.00063   12.27328      1.00000  67.79s
    499     0.00473     0.00059    7.98423      1.00000  72.18s
    500     0.00535     0.00059    9.12055      1.00000  61.74s
Out[165]:
NeuralNet(X_tensor_type=None,
     batch_iterator_test=<nolearn.lasagne.base.BatchIterator object at 0x7ff4bcec2710>,
     batch_iterator_train=<nolearn.lasagne.base.BatchIterator object at 0x7ff4bcec2610>,
     check_input=True, conv1_filter_size=(3, 3), conv1_num_filters=32,
     conv2_filter_size=(2, 2), conv2_num_filters=64,
     conv3_filter_size=(2, 2), conv3_num_filters=128, custom_scores=None,
     dropout1_p=0.1, dropout2_p=0.2, dropout3_p=0.3, dropout4_p=0.5,
     hidden4_num_units=1000, hidden5_num_units=1000,
     input_shape=(None, 1, 96, 96),
     layers=[('input', <class 'lasagne.layers.input.InputLayer'>), ('conv1', <class 'lasagne.layers.conv.Conv2DLayer'>), ('pool1', <class 'lasagne.layers.pool.MaxPool2DLayer'>), ('dropout1', <class 'lasagne.layers.noise.DropoutLayer'>), ('conv2', <class 'lasagne.layers.conv.Conv2DLayer'>), ('pool2', <cla..., <class 'lasagne.layers.dense.DenseLayer'>), ('output', <class 'lasagne.layers.dense.DenseLayer'>)],
     loss=None, max_epochs=500, more_params={},
     objective=<function objective at 0x7ff4bcc2ff50>,
     objective_loss_function=<function categorical_crossentropy at 0x7ff4bdb045f0>,
     on_batch_finished=[],
     on_epoch_finished=[<nolearn.lasagne.handlers.PrintLog instance at 0x7ff3df32c368>],
     on_training_finished=[],
     on_training_started=[<nolearn.lasagne.handlers.PrintLayerInfo instance at 0x7ff3df32c290>],
     output_nonlinearity=<function softmax at 0x7ff4bdc62488>,
     output_num_units=2, pool1_pool_size=(2, 2), pool2_pool_size=(2, 2),
     pool3_pool_size=(2, 2), regression=False, scores_train=[],
     scores_valid=[],
     train_split=<nolearn.lasagne.base.TrainSplit object at 0x7ff4bcec2750>,
     update=<function nesterov_momentum at 0x7ff4bdb04ed8>,
     update_learning_rate=0.001, update_momentum=0.9,
     use_label_encoder=False, verbose=1,
     y_tensor_type=TensorType(int32, vector))

In [18]:
predicted = net.predict((X_test.reshape(-1,1,96,96)))

In [19]:
def names(x): return map(x)

In [ ]:
predicted_names = []
for i in predicted:
    predicted_names = np.append(predicted_names,map[i])
    
from sklearn.metrics import confusion_matrix
confusion_matrix(Y_test, predicted_names)

In [22]:
from sklearn.metrics import confusion_matrix
confusion_matrix(Y_test, predicted_names)


Out[22]:
array([[19,  0],
       [ 0, 25]])

In [ ]:
%%capture
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras import backend as K
from keras.optimizers import Adam,SGD
from keras.utils import np_utils


Y_Keras = np_utils.to_categorical(Y_number, 2)
# Create first network with Keras
from keras.models import Sequential
from keras.layers import Dense, Activation,Dropout
model = Sequential()
model.add(Dense(1000, input_dim=9216,activation='relu'))
model.add(Dense(2,activation='softmax'))
sgd = SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True)

# Compile model
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])

import time
model.fit(X.reshape(-1,9216), Y_Keras, nb_epoch=100, batch_size=5,verbose=1,
         validation_data=(X_test.reshape(-1,9216), np_utils.to_categorical(Y_test_numer, 2)))
time.sleep(1)

In [28]:
X_normal = X.reshape(-1,9216)
X_test_normal = X_test.reshape(-1,9216)

In [100]:
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(verbose=1,n_jobs=-1)
clf.fit(X_normal,Y_number)
Y_logictic= clf.predict(X_test.reshape(-1,9216))


[LibLinear]

In [101]:
from sklearn.cross_validation import cross_val_score
score = cross_val_score(clf,X_normal,Y_number)


[LibLinear][LibLinear][LibLinear]

In [102]:
score


Out[102]:
array([ 0.99648506,  0.99824253,  1.        ])

In [90]:
predicted_names = []
for i in Y_logictic:
    predicted_names = np.append(predicted_names,map[i])
    
from sklearn.metrics import confusion_matrix
confusion_matrix(Y_test, predicted_names)


Out[90]:
array([[19,  0],
       [ 0, 25]])

In [92]:
plt.imshow(clf.coef_.reshape(96,96),cmap=cm.Greys_r)


Out[92]:
<matplotlib.image.AxesImage at 0x7ff3d561dc90>

In [93]:
from sklearn.ensemble import RandomForestClassifier
from sklearn.cross_validation import cross_val_score
scores = list()
scores_std = list()
n_trees = [10,   50,  150,250,500]

In [94]:
for n_tree in n_trees:
        print(n_tree)
        recognizer = RandomForestClassifier(n_tree,verbose=0,oob_score=True,n_jobs=5)
        score = cross_val_score(recognizer, X_normal, Y_number)
        scores.append(np.mean(score))
        scores_std.append(np.std(score))


10
50
150
250
500

In [95]:
sc_array = np.array(scores)
std_array = np.array(scores_std)
print('Score: ', sc_array)
print('Std  : ', std_array)

plt.figure(figsize=(4,3))
plt.plot(n_trees, scores)
plt.plot(n_trees, sc_array + std_array, 'b--')
plt.plot(n_trees, sc_array - std_array, 'b--')
plt.ylabel('CV score')
plt.xlabel('# of trees')
#plt.savefig('cv_trees.png')
plt.show()


('Score: ', array([ 0.99706985,  0.99824253,  0.99824253,  0.99824253,  0.99824253]))
('Std  : ', array([ 0.00165623,  0.00143497,  0.00143497,  0.00143497,  0.00143497]))

In [96]:
recognizer = RandomForestClassifier(n_tree,verbose=1,oob_score=True,n_jobs=5)
recognizer.fit(X_normal,Y_number)


[Parallel(n_jobs=5)]: Done  40 tasks      | elapsed:    0.4s
[Parallel(n_jobs=5)]: Done 190 tasks      | elapsed:    1.9s
[Parallel(n_jobs=5)]: Done 440 tasks      | elapsed:    4.3s
[Parallel(n_jobs=5)]: Done 500 out of 500 | elapsed:    4.8s finished
Out[96]:
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
            max_depth=None, max_features='auto', max_leaf_nodes=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, n_estimators=500, n_jobs=5,
            oob_score=True, random_state=None, verbose=1, warm_start=False)

In [97]:
importances = recognizer.feature_importances_
importance_image = importances.reshape(96,96)
#plt.figure(figsize=(7,7))
plt.imshow(importance_image,cmap=cm.Greys_r)


Out[97]:
<matplotlib.image.AxesImage at 0x7ff3c91f1fd0>

In [98]:
plt.imshow(X_normal[1,:].reshape(96,96),cmap=cm.Greys_r)


Out[98]:
<matplotlib.image.AxesImage at 0x7ff3d306eb50>

In [99]:
plt.imshow(X_normal[700,:].reshape(96,96),cm.Greys_r)


Out[99]:
<matplotlib.image.AxesImage at 0x7ff3d25d42d0>

In [157]:
jpgfile = Image.open("/home/mckc/Downloads/1.jpg")
grey = rgb2gray(np.array(jpgfile))
faces  = face_cascade.detectMultiScale(grey.astype(np.uint8),scaleFactor=1.1,minNeighbors=3,minSize=(30, 30))
print faces


for (x,y,w,h) in faces:
    fac = np.array(grey[y:(y+h),x:(x+h)])
    out = resize(fac,(96,96))
    
plt.imshow(out,cmap=cm.Greys_r)

from sklearn.ensemble import RandomForestClassifier
recognizer = RandomForestClassifier(500,verbose=0,oob_score=True,n_jobs=5)
recognizer.fit(X_normal,Y_number)

trial = out.astype(np.float64)
print 'Linear Regression Value',map[clf.predict(trial.reshape(-1,9216))]
print 'Random Forest Value',map[recognizer.predict(trial.reshape(-1,9216))]
print 'Lasagne Value',map[recognizer.predict(trial.reshape(-1,1,96,96))]
print 'Keras Value',map[recognizer.predict(trial.reshape(-1,1,96,96))]


[[70 37 59 59]]
Linear Regression result ['Gopika']
Random Forest Value ['Gopika']

In [ ]:
jpgfile = Image.open("/home/mckc/Downloads/2.jpg")
grey = rgb2gray(np.array(jpgfile))
faces  = face_cascade.detectMultiScale(grey.astype(np.uint8),scaleFactor=1.1,minNeighbors=3,minSize=(30, 30))
print faces


for (x,y,w,h) in faces:
    fac = np.array(grey[y:(y+h),x:(x+h)])
    out = resize(fac,(96,96))
    
plt.imshow(out,cmap=cm.Greys_r)

from sklearn.ensemble import RandomForestClassifier
recognizer = RandomForestClassifier(500,verbose=0,oob_score=True,n_jobs=5)
recognizer.fit(X_normal,Y_number)

trial = out.astype(np.float64)
print 'Linear Regression Value',map[clf.predict(trial.reshape(-1,9216))]
print 'Random Forest Value',map[recognizer.predict(trial.reshape(-1,9216))]
print 'Lasagne Value',map[recognizer.predict(trial.reshape(-1,1,96,96))]
print 'Keras Value',map[recognizer.predict(trial.reshape(-1,1,96,96))]