Imports


In [1]:
import sys 
import os
sys.path.append(os.path.join(os.getcwd(), '../Code/'))

In [2]:
from DataSets.Ladicky import LadickyDataset

In [3]:
from Models.VGG16 import VGG16


Using TensorFlow backend.

In [4]:
import tensorflow as tf

In [5]:
import numpy as np

In [6]:
from PIL import Image

Utility Function


In [7]:
def show_normals(npnorms):
    return Image.fromarray(((npnorms+1)/2*255).astype(np.uint8))

Load data


In [8]:
file = '../Data/LadickyDataset10.mat'

In [9]:
dataset = LadickyDataset(file)

In [10]:
dataset.size


Out[10]:
10

Loss Function


In [11]:
def mean_dot_product(y_true, y_pred):
    dot = tf.einsum('ijkl,ijkl->ijk', y_true, y_pred) # Dot product
    n = tf.cast(tf.count_nonzero(dot),tf.float32)
    mean = tf.reduce_sum(dot) / n
    return -1 * mean

Testing


In [66]:
model = VGG16(weights=None)
imnetmodel1 = VGG16()
imnetmodel2 = VGG16()

In [67]:
# Compile model
model.compile(loss= mean_dot_product, optimizer='sgd')

In [63]:
model.layers[17].get_weights()


Out[63]:
[array([[[[  2.97863223e-03,   1.28228441e-02,   2.28409469e-02, ...,
            -1.64264236e-02,  -2.06242874e-03,  -1.41646732e-02],
          [ -1.46831293e-02,  -7.01227412e-03,  -2.22474448e-02, ...,
             1.48497596e-02,   2.34740488e-02,  -8.31191428e-03],
          [  1.17747299e-03,   4.57974151e-04,  -1.33952545e-02, ...,
             7.44706392e-03,  -1.16428109e-02,  -8.69392045e-03],
          ..., 
          [  6.40907139e-03,  -1.83722563e-02,   2.06986256e-03, ...,
            -2.18210686e-02,  -2.33048629e-02,  -1.82466954e-02],
          [  1.72219165e-02,   1.34307928e-02,  -2.29290444e-02, ...,
            -1.22297956e-02,   3.62585485e-03,  -1.43011119e-02],
          [ -2.17402689e-02,   1.00728981e-02,  -2.15632841e-02, ...,
             2.34434903e-02,  -2.16306467e-02,  -4.82864678e-03]],
 
         [[  6.60762191e-03,   6.80020079e-03,   1.40808038e-02, ...,
             1.32532977e-03,   4.04108129e-03,  -1.60943437e-02],
          [  1.16630457e-02,   2.15415843e-03,   1.34641789e-02, ...,
             1.60018764e-02,  -2.12483741e-02,  -1.99593790e-02],
          [ -1.84749085e-02,  -1.38911530e-02,  -1.42830014e-02, ...,
             1.62274987e-02,  -1.05021112e-02,   1.27960779e-02],
          ..., 
          [  1.77514441e-02,  -1.41886538e-02,  -1.02344370e-02, ...,
            -1.16005745e-02,  -2.46897917e-02,  -7.27749057e-03],
          [  5.84983453e-03,  -1.79015435e-02,   2.53207721e-02, ...,
             1.13533325e-02,  -3.04124877e-03,  -2.19952948e-02],
          [ -2.48971265e-02,  -1.93032753e-02,   8.18118826e-03, ...,
            -1.57351382e-02,   1.26231052e-02,  -1.74970608e-02]],
 
         [[  6.20040670e-03,   1.84290260e-02,  -2.24113129e-02, ...,
            -1.68563165e-02,   5.18609397e-03,   2.42354125e-02],
          [ -1.85499955e-02,  -1.76137090e-02,   2.35170498e-03, ...,
            -2.14527734e-02,  -2.50892639e-02,   2.53424607e-02],
          [  1.14159621e-02,   2.13510804e-02,  -8.59836116e-04, ...,
             8.87878612e-03,   1.15386471e-02,   1.73856132e-02],
          ..., 
          [  4.26326506e-03,   1.11424848e-02,  -2.53325440e-02, ...,
             6.86885789e-03,  -1.25526832e-02,  -1.79664344e-02],
          [  7.65752047e-03,   1.16895549e-02,  -1.55165205e-02, ...,
             2.23948099e-02,  -4.59836796e-04,   2.47118436e-02],
          [ -7.66264275e-03,  -3.90143879e-03,   1.18682869e-02, ...,
            -6.48817979e-03,   4.91175801e-03,  -1.30476747e-02]]],
 
 
        [[[ -1.57313421e-02,   1.94170885e-03,  -2.51325462e-02, ...,
             2.62051076e-03,  -2.46763229e-02,   1.59399845e-02],
          [ -1.20002944e-02,  -1.33063281e-02,   1.90028772e-02, ...,
             7.87005946e-03,  -8.02840479e-03,   1.22625791e-02],
          [ -2.67282128e-03,   2.35385261e-02,  -1.95490979e-02, ...,
            -2.55130604e-03,  -9.63975117e-03,   4.94353473e-04],
          ..., 
          [  5.07023744e-03,  -1.51898442e-02,   1.17098987e-02, ...,
             6.75043464e-03,  -1.83533616e-02,   3.47271748e-03],
          [ -1.54698975e-02,   1.71472952e-02,  -2.35678349e-02, ...,
            -2.41691247e-03,   1.84634775e-02,  -1.36565845e-02],
          [  2.19969563e-02,  -2.00663731e-02,   2.47493424e-02, ...,
             2.00224891e-02,  -3.77281196e-03,  -9.63377766e-03]],
 
         [[ -2.36477461e-02,  -1.88639406e-02,  -1.51247028e-02, ...,
             1.89337693e-03,  -8.84097256e-03,   1.20868348e-02],
          [  1.58262253e-02,   6.25919551e-03,   2.53399909e-02, ...,
             5.57873398e-03,  -1.53144635e-03,   8.04319978e-04],
          [ -5.15140779e-03,  -1.19063258e-03,  -6.06175326e-03, ...,
             1.82795823e-02,   1.65280402e-02,   1.85969286e-03],
          ..., 
          [ -1.39168184e-02,   6.94024563e-03,  -1.14168441e-02, ...,
             2.21273713e-02,  -1.01660658e-02,   2.23134942e-02],
          [ -7.22661614e-03,  -2.53585987e-02,   1.00457482e-02, ...,
             2.09324807e-02,  -2.83124484e-03,   1.85148790e-03],
          [ -1.74658224e-02,   2.13892572e-03,  -1.13943899e-02, ...,
            -2.96473503e-04,  -2.24212166e-02,   1.52032375e-02]],
 
         [[ -1.16342697e-02,   1.62520558e-02,  -2.27730423e-02, ...,
            -1.76951960e-02,   7.52706826e-03,   1.51971914e-02],
          [ -2.45386176e-03,  -1.54734505e-02,  -1.46863172e-02, ...,
             1.50473453e-02,  -1.80290453e-02,   1.91794783e-02],
          [  1.21157989e-02,  -8.88707116e-04,   2.31134817e-02, ...,
             1.12242065e-02,   7.82692805e-04,  -1.20730335e-02],
          ..., 
          [  1.42763332e-02,  -7.59820081e-03,  -1.03396242e-02, ...,
             1.38394982e-02,   9.66026261e-03,   2.57481821e-03],
          [  3.54413129e-03,  -2.50295177e-02,   2.48579308e-04, ...,
            -1.57478340e-02,   8.11498612e-04,  -2.19917800e-02],
          [  2.42031887e-02,   9.32026282e-03,  -9.02323052e-03, ...,
             6.99178502e-03,  -2.18530670e-02,  -1.61593743e-02]]],
 
 
        [[[ -1.95154622e-02,   8.44391808e-03,  -2.22022943e-02, ...,
            -2.14012489e-02,   1.68560483e-02,  -2.49935407e-02],
          [  2.00865828e-02,  -2.22440269e-02,   7.47460499e-03, ...,
             2.30856389e-02,  -4.23055515e-03,  -1.29918056e-02],
          [  2.00944282e-02,   2.90169567e-03,  -1.78309102e-02, ...,
             1.57026611e-02,   1.09147765e-02,   1.71319954e-03],
          ..., 
          [  5.20389527e-04,  -1.36108128e-02,   2.17537135e-02, ...,
            -2.50865519e-03,   4.46834229e-03,   6.64455816e-04],
          [ -2.62905844e-03,   1.55351534e-02,   1.98277906e-02, ...,
             1.22710280e-02,   2.09811330e-03,   1.00660138e-02],
          [ -1.52182588e-02,  -2.25759000e-02,  -7.84025155e-03, ...,
            -1.83350947e-02,   1.22586600e-02,  -2.08215788e-04]],
 
         [[ -1.12448242e-02,  -1.34378625e-02,   2.24824511e-02, ...,
             7.32972473e-03,  -2.28549670e-02,  -1.11691281e-03],
          [  1.26070790e-02,   5.18887490e-03,  -5.46715222e-03, ...,
             2.23184153e-02,  -1.15190018e-02,   8.67045671e-03],
          [  2.52181478e-03,   1.95648670e-02,   1.56272128e-02, ...,
            -2.09681690e-03,  -1.34344008e-02,  -2.02040523e-02],
          ..., 
          [ -1.12587977e-02,  -1.28838196e-02,  -1.51368640e-02, ...,
             1.29120648e-02,   3.09682079e-03,  -2.16703229e-02],
          [ -8.59331340e-05,   2.44374126e-02,   2.27360725e-02, ...,
            -1.69215184e-02,  -2.20709126e-02,  -2.68112496e-03],
          [ -6.94960915e-03,   2.03035958e-02,   2.09865384e-02, ...,
             2.38048919e-02,   2.22529620e-02,   8.56805965e-03]],
 
         [[ -1.50632793e-02,  -1.23814419e-02,  -1.47635695e-02, ...,
             1.88121274e-02,   1.76029950e-02,  -4.32478637e-03],
          [ -6.98835403e-03,   7.99366087e-03,   1.84450634e-02, ...,
            -1.82788167e-02,   8.61377642e-03,   2.13979334e-02],
          [  1.20098516e-02,  -1.03659229e-02,  -1.73351727e-03, ...,
             6.81245700e-04,  -2.63796933e-03,  -9.44178551e-03],
          ..., 
          [ -1.36380177e-02,  -2.51967069e-02,   1.99382827e-02, ...,
             5.61660156e-04,  -1.56662390e-02,  -4.82030772e-03],
          [  2.39377171e-02,   1.33076832e-02,  -1.53474333e-02, ...,
            -2.25423612e-02,  -2.52824277e-04,   1.04387105e-03],
          [  2.00259909e-02,  -2.07979307e-02,  -1.33877536e-02, ...,
            -4.42648865e-03,   2.00053751e-02,   1.54837370e-02]]]], dtype=float32),
 array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
         0.,  0.,  0.,  0.,  0.], dtype=float32)]

In [64]:
imnetmodel1.layers[17].get_weights()


Out[64]:
[array([[[[  4.07882966e-04,   4.82621184e-03,  -9.11695044e-03, ...,
             1.51569908e-02,  -2.73966836e-03,  -4.83311387e-03],
          [  3.48924054e-03,   2.60589737e-03,  -8.10198858e-03, ...,
             8.86987546e-04,  -7.08238874e-03,  -7.96321197e-04],
          [ -1.12759033e-02,  -6.43836753e-03,  -8.05236772e-03, ...,
             1.90410519e-03,   3.87627119e-03,   1.96338408e-02],
          ..., 
          [ -1.49949323e-02,   1.20318262e-02,   9.87236737e-04, ...,
            -2.89861043e-03,   4.03315574e-03,  -5.93429338e-03],
          [ -7.53336679e-03,   6.08530594e-03,   9.90014290e-04, ...,
             1.63243050e-04,  -3.09621776e-03,  -3.01808352e-03],
          [ -2.62522907e-03,   3.51887429e-03,  -2.58309790e-03, ...,
            -6.02027494e-03,  -8.85035843e-03,   9.85825085e-04]],
 
         [[  3.02846078e-04,   2.64736195e-03,  -1.37099335e-02, ...,
             1.49135189e-02,  -4.65666235e-04,  -6.84898719e-03],
          [ -9.60117579e-03,   5.01031429e-03,  -1.13053191e-02, ...,
             8.86707660e-03,   6.21224102e-03,   2.48882570e-03],
          [ -1.13499342e-02,  -4.72285505e-03,  -8.57903156e-03, ...,
            -3.04920389e-03,   9.67197306e-03,   1.90250184e-02],
          ..., 
          [ -4.48127137e-03,   5.53716440e-03,   4.68912302e-03, ...,
            -4.91005788e-03,   6.40070112e-03,  -8.28019064e-03],
          [ -6.00830279e-03,  -7.51605199e-04,   8.29616503e-04, ...,
             2.07461347e-03,   3.22994636e-03,  -1.69727230e-03],
          [ -2.81035155e-03,   1.36994272e-02,  -2.04460253e-03, ...,
            -5.17683988e-03,  -9.04289633e-03,  -1.79657899e-03]],
 
         [[  3.09069827e-03,  -7.85107608e-04,  -1.12262042e-02, ...,
             1.38624888e-02,  -1.50248851e-03,  -2.83075101e-03],
          [ -1.78263709e-02,  -4.06336552e-03,  -1.11764381e-02, ...,
             1.76884588e-02,  -1.14172359e-03,   1.50952139e-03],
          [ -1.26420632e-02,  -1.19902752e-03,  -1.03873471e-02, ...,
            -1.54873531e-03,   3.21487361e-03,   1.84067711e-02],
          ..., 
          [  4.99952445e-03,   8.96072667e-03,   2.35912274e-03, ...,
            -6.95799524e-03,   9.11425054e-03,  -1.76598097e-03],
          [ -3.11188446e-03,  -4.81695170e-03,   2.14671413e-03, ...,
             8.69878661e-03,   4.66441829e-03,   3.96351190e-03],
          [ -1.56560540e-03,   1.01758400e-02,  -1.81451999e-03, ...,
            -7.93038029e-03,  -7.92690739e-03,   9.85421613e-03]]],
 
 
        [[[  2.21009902e-03,   5.53841889e-03,  -1.51329748e-02, ...,
             1.92244705e-02,  -2.94085429e-03,  -2.05214042e-03],
          [  4.31180233e-03,  -4.67703957e-03,  -9.83539224e-03, ...,
            -1.16664264e-03,  -7.47026131e-03,   8.98758229e-03],
          [ -1.00150378e-02,  -3.31197702e-03,  -4.38165246e-03, ...,
             1.28704909e-04,   6.90069282e-05,   5.32614533e-03],
          ..., 
          [ -1.65325180e-02,   5.79520175e-03,  -1.08136714e-03, ...,
            -3.87264206e-03,   3.87065555e-03,  -8.52444116e-03],
          [ -1.10835498e-02,   6.04208373e-03,   6.12878706e-03, ...,
            -4.66409931e-03,  -1.65367487e-03,  -4.93706390e-03],
          [ -5.82469627e-03,   2.77068373e-03,   2.59765168e-03, ...,
            -9.57501866e-03,  -3.32338479e-03,   3.07677989e-03]],
 
         [[  3.59932799e-03,   1.19693214e-02,  -1.60994809e-02, ...,
             1.80910621e-02,   3.29896147e-06,  -6.10836258e-04],
          [ -7.41903298e-03,  -5.61146066e-03,  -1.38216335e-02, ...,
             2.96197180e-03,   2.69207382e-03,   7.01817824e-03],
          [ -8.48251395e-03,   9.95878596e-04,   6.25522574e-04, ...,
            -3.68017773e-03,   1.27349654e-02,   4.87677474e-03],
          ..., 
          [ -8.20725970e-03,   1.95525214e-03,   2.69707199e-03, ...,
            -4.49266564e-03,   6.45229314e-03,  -1.28380703e-02],
          [ -5.50353806e-03,   1.61080994e-03,   1.39699667e-03, ...,
            -2.52319360e-03,  -4.11227718e-03,  -5.21757640e-03],
          [ -2.69698747e-03,   2.70054420e-03,   3.79564380e-03, ...,
            -7.66708190e-03,  -9.20492224e-03,  -4.52092383e-03]],
 
         [[  2.48262100e-03,   6.13112841e-03,  -1.47995697e-02, ...,
             1.69335436e-02,   1.16662926e-03,   1.17623655e-03],
          [ -1.69411730e-02,  -8.71018134e-03,  -1.29530905e-02, ...,
             1.87354535e-03,  -6.88433880e-04,  -1.68701622e-03],
          [ -6.59902534e-03,   3.46401357e-03,  -3.11806914e-03, ...,
            -4.05590283e-03,   7.37769250e-03,   5.51742781e-03],
          ..., 
          [  9.51702707e-04,   1.64372730e-03,   1.49127271e-03, ...,
            -7.65326899e-03,   1.19846454e-02,  -9.10102390e-03],
          [  2.88849953e-03,  -5.35335718e-03,  -3.08376068e-04, ...,
             3.87483276e-04,  -4.36716061e-03,  -2.73425644e-03],
          [ -1.54271268e-03,   4.30263951e-03,  -4.31923472e-05, ...,
            -5.21167647e-03,  -8.79874174e-03,  -2.11346560e-04]]],
 
 
        [[[ -2.93453527e-03,   4.62880917e-03,  -9.69677325e-03, ...,
             1.48544796e-02,   3.87839018e-03,   1.85810984e-03],
          [  5.63784037e-03,  -6.04889123e-03,  -5.59245935e-03, ...,
            -4.98529337e-03,  -1.92062720e-03,   4.07473044e-03],
          [ -4.84194839e-03,   2.70295335e-04,  -3.02166585e-03, ...,
            -1.49492722e-03,  -1.31164724e-02,   2.69274553e-03],
          ..., 
          [ -1.79702230e-02,  -3.29879066e-03,  -6.12194091e-03, ...,
            -7.89267663e-03,  -1.74841529e-03,  -2.64002383e-03],
          [ -1.11466460e-02,   5.13884844e-03,   1.51880039e-02, ...,
            -4.87166690e-03,   2.45198980e-03,  -3.42866592e-03],
          [ -6.12380216e-03,   8.87359586e-03,  -3.45014478e-03, ...,
            -1.09723555e-02,   2.66773975e-03,  -4.79325093e-03]],
 
         [[ -6.14633691e-03,   1.40388934e-02,  -9.19489283e-03, ...,
             1.60656814e-02,   8.88941437e-03,   6.56510517e-03],
          [ -5.72578516e-03,  -3.33702704e-03,  -8.64025764e-03, ...,
             1.98416272e-03,   7.86264334e-03,   2.50778953e-03],
          [ -3.77366156e-03,   9.24240507e-04,   7.29091058e-04, ...,
            -4.96890210e-03,   3.85057204e-03,  -7.15580711e-04],
          ..., 
          [ -1.22111076e-02,  -2.42003356e-03,  -4.81141545e-03, ...,
            -4.22020489e-03,  -1.01946108e-02,  -5.80721162e-03],
          [ -9.04400460e-03,   1.94370467e-03,   7.34009594e-03, ...,
            -5.14973374e-03,   3.66879918e-04,  -5.37241250e-03],
          [ -3.53684562e-04,   1.53788179e-02,  -8.76262202e-04, ...,
            -7.13666994e-03,  -4.27656015e-03,  -1.42133404e-02]],
 
         [[ -6.67408668e-03,   9.11168288e-03,  -9.18486901e-03, ...,
             1.21346870e-02,   8.51947255e-03,   7.15135690e-03],
          [ -1.64910071e-02,  -2.04550894e-03,  -7.30760070e-03, ...,
            -2.89353775e-03,   1.16095145e-03,  -6.60440046e-03],
          [ -7.68517129e-05,   4.32093628e-03,  -6.93119306e-04, ...,
            -3.48316878e-03,  -1.47545757e-03,  -2.85687298e-03],
          ..., 
          [ -4.66702832e-03,  -1.39780261e-03,   3.67210196e-05, ...,
            -4.95146902e-04,   7.23151665e-04,  -6.29519764e-03],
          [  3.63699184e-03,  -4.63909749e-03,   5.31478412e-03, ...,
            -1.50180201e-03,  -7.48660788e-03,  -1.94359326e-03],
          [ -1.03440508e-03,   1.57131702e-02,  -1.98940560e-03, ...,
            -5.38550608e-04,  -5.37431426e-03,  -9.20103770e-03]]]], dtype=float32),
 array([  1.88378572e-01,  -5.00367463e-01,   5.42223394e-01,
          2.46460959e-01,   1.54070303e-01,  -2.36067176e-01,
         -1.17649809e-02,   3.57512347e-02,   7.58338273e-02,
          1.63476378e-01,  -1.34778112e-01,  -8.40371996e-02,
          2.50966042e-01,  -1.67475253e-01,  -2.82782689e-02,
          4.04935628e-01,   4.92739901e-02,   3.43014568e-01,
         -2.48226017e-01,  -8.52851495e-02,   1.14871934e-01,
         -8.34204536e-03,  -7.97333941e-02,   2.08946794e-01,
          2.29255453e-01,  -3.57115209e-01,   3.54569256e-01,
          4.94823381e-02,   2.67764390e-01,   1.16772160e-01,
          2.48077109e-01,   1.90769851e-01,   2.27198079e-01,
          2.07326874e-01,   4.33389664e-01,  -2.14167282e-01,
          4.27582026e-01,   2.85164490e-02,  -1.01103269e-01,
         -1.16591506e-01,   1.57484300e-02,  -1.92446187e-01,
          5.09383738e-01,  -1.01140939e-01,  -1.70503020e-01,
          1.82109758e-01,   6.56641722e-02,   1.48948044e-01,
         -3.34800705e-02,   2.34267697e-01,   1.17521681e-01,
         -1.11647561e-01,   1.67274535e-01,  -2.18229502e-01,
         -1.26343705e-02,   6.51194036e-01,   4.33828384e-01,
          5.46606928e-02,   2.51551688e-01,   2.21985489e-01,
          2.07218826e-02,  -2.58966297e-01,   1.32507131e-01,
          1.47451892e-01,  -1.49491996e-01,  -2.45121513e-02,
         -1.93051482e-03,   3.55903581e-02,  -2.87072897e-01,
          2.04153866e-01,   5.73086739e-02,   1.29463181e-01,
          1.23248003e-01,  -1.90378204e-01,  -5.25708608e-02,
         -8.20820853e-02,   7.67999232e-01,   2.17065111e-01,
          4.36754115e-02,  -6.61685169e-02,   1.55227348e-01,
          6.22618794e-01,   1.98174551e-01,   1.35126531e-01,
          1.28762200e-01,  -4.85090315e-02,   4.69657898e-01,
          4.86439429e-02,   3.53257835e-01,   5.42547941e-01,
         -2.09446177e-01,   1.35347247e-01,   1.24633104e-01,
          2.24511325e-01,  -1.93987757e-01,  -1.69384852e-02,
          6.01346325e-03,   2.04649493e-01,  -3.49047594e-02,
          3.08254182e-01,   2.74999171e-01,   6.06408417e-01,
          1.30885825e-01,  -7.84191936e-02,   2.30702013e-01,
          6.21092655e-02,   1.07052080e-01,  -2.47026488e-01,
          3.11956823e-01,   2.79106498e-01,   2.18370885e-01,
          1.03057109e-01,   5.74263111e-02,   1.94899786e+00,
         -9.07675177e-02,   7.99698196e-03,   1.57724932e-01,
          6.45613790e-01,   1.95434928e-01,   6.70031726e-01,
         -1.17897667e-01,   2.08516628e-01,   1.35548666e-01,
          5.05479157e-01,   2.27726430e-01,  -2.85992660e-02,
          7.31752664e-02,   2.16317698e-01,   1.04756050e-01,
          7.34472694e-03,  -9.85700116e-02,  -2.09823661e-02,
         -1.19556062e-01,   4.82213408e-01,   2.29107309e-02,
          7.89495856e-02,   1.66905075e-01,   2.03251719e-01,
          2.19120562e-01,   3.17676008e-01,   2.38415692e-03,
          4.65317338e-04,   5.53632751e-02,   2.63843596e-01,
         -2.68867999e-01,  -6.39354065e-02,   3.14108700e-01,
         -1.04466088e-01,   2.15531588e-01,   2.69292265e-01,
          6.31085504e-03,   2.11812276e-02,   3.03376783e-02,
          1.34254768e-01,   1.78778559e-01,   9.43155289e+00,
          2.75686860e-01,   1.31738886e-01,   1.86976731e-01,
          8.58496577e-02,   1.49559855e-01,  -2.00136185e-01,
         -3.02753776e-01,   6.99055195e-01,   1.03292175e-01,
          5.93839027e-02,   6.86080813e-01,  -1.75999016e-01,
          1.97002128e-01,   2.17421085e-01,   1.00237295e-01,
          2.00453222e-01,   5.19402325e-01,   3.03252012e-01,
          1.08759388e-01,   2.52096474e-01,   9.80204344e-02,
          6.79299794e-03,   4.11590002e-02,   3.55982512e-01,
          9.82239395e-02,  -1.27133965e-01,   5.89193106e-02,
         -2.11274922e-02,  -9.46500301e-02,   3.23439181e-01,
          5.33190012e-01,   2.81205267e-01,  -7.00195059e-02,
          4.50011939e-02,   5.85235953e-02,  -2.72989403e-02,
          1.23330429e-01,   1.57047048e-01,   6.30159453e-02,
         -1.79739177e-01,   1.68211743e-01,  -2.27243900e-02,
          1.42132714e-01,   2.76279449e-01,   4.04965654e-02,
         -1.99054778e-01,   3.65843683e-01,   2.73112729e-02,
         -1.31376877e-01,   9.32270288e-02,  -7.60697424e-02,
          1.93399116e-02,   1.85015425e-03,   4.15253565e-02,
          2.56592147e-02,  -6.57611638e-02,   3.76626439e-02,
          2.72211343e-01,   1.40291587e-01,   3.34124207e-01,
         -4.18526232e-02,  -9.58744287e-02,   2.74706990e-01,
         -1.55596823e-01,   3.64604779e-02,  -1.32014111e-01,
          1.34014981e-02,  -4.87616658e-02,   1.06156722e-01,
          5.36326528e-01,   3.72983187e-01,   3.38566378e-02,
         -8.60288590e-02,   7.98788011e-01,  -1.82336777e-01,
          1.64008543e-01,   1.88149005e-01,   1.57651126e-01,
          8.60020444e-02,   5.53895067e-03,   2.04019845e-02,
          3.66550952e-01,   1.50018111e-01,   6.82196319e-02,
          1.26301348e-01,   2.67437845e-01,   1.32230207e-01,
          6.47044480e-02,   2.42651135e-01,   7.22966492e-02,
          1.25669807e-01,  -6.93451017e-02,   4.69704807e-01,
          1.46840796e-01,   1.52075395e-01,   1.08058611e-02,
          7.89734907e-03,  -1.83315612e-02,   1.02967513e+00,
          2.86464036e-01,   2.72089839e-01,   2.99726725e-02,
          1.12274528e-01,   3.48836958e-01,  -6.20776117e-02,
          2.17991203e-01,   4.28738832e-01,  -4.16037142e-02,
          3.66377145e-01,   1.08046882e-01,  -2.55869627e-02,
         -4.00224268e-01,  -2.40779221e-01,   7.19139993e-01,
         -5.15835034e-03,   4.65480566e-01,   1.19287916e-01,
         -1.20954335e-01,   2.40479499e-01,   4.27416801e-01,
          5.59932351e-01,   1.26139030e-01,  -1.14825912e-01,
          1.22176088e-01,   2.95618027e-02,  -7.13887066e-02,
          2.86794007e-01,   2.46085122e-01,   1.81327894e-01,
          3.12949091e-01,  -9.33331028e-02,   1.16926350e-03,
         -2.63316602e-01,   3.58326316e-01,   1.62727624e-01,
          3.76439899e-01,   3.91090691e-01,   1.10005677e-01,
          1.11292467e-01,   2.07414851e-02,   1.14994623e-01,
          6.28707856e-02,   5.34125865e-01,  -2.11611167e-01,
          5.91500774e-02,  -1.58647493e-01,  -3.78553174e-03,
          3.52953747e-02,  -2.05919351e-02,   1.53826475e-01,
          1.20451070e-01,   1.26241818e-01,  -6.20619431e-02,
         -1.44232456e-02,  -1.47647366e-01,  -1.82920575e-01,
          2.08717108e-01,   3.31947088e-01,  -8.80439430e-02,
          1.55856574e+00,   2.22004980e-01,   2.32446954e-01,
          5.67621551e-02,   3.97473991e-01,   5.03389001e-01,
         -1.44024760e-01,   1.91921026e-01,  -1.38310969e-01,
         -6.44080155e-03,   3.39745015e-01,   4.69098449e-01,
          2.28332952e-02,   6.56073332e-01,   2.45110661e-01,
         -1.68141842e-01,   7.19269738e-02,  -1.22520126e-01,
         -2.34832615e-01,   1.96609661e-01,   8.65012854e-02,
          1.28099874e-01,  -9.01192203e-02,   4.89099592e-01,
         -1.34810328e-01,   1.06568784e-01,   1.27098143e-01,
          4.38580155e-01,   4.55901057e-01,   4.61729169e-02,
          1.65377498e-01,   3.57421547e-01,   9.74082127e-02,
         -2.31282339e-01,   8.46065506e-02,   2.89760232e-01,
         -9.88961682e-02,   9.01378930e-01,   2.52402127e-01,
         -2.15688810e-01,  -5.59736192e-02,  -1.13818742e-01,
         -6.13411656e-03,  -1.34001493e-01,   1.61142886e-01,
         -4.80620004e-02,   1.38647243e-01,  -3.01776342e-02,
          1.83977813e-01,  -1.18016593e-01,   3.89179081e-01,
          6.13915585e-02,   1.58884943e-01,   5.89057468e-02,
          5.19612193e-01,   1.23953849e-01,   5.55581629e-01,
          5.01390219e-01,  -3.79978642e-02,  -1.41257286e-01,
          7.03621209e-02,  -1.73130766e-01,   3.50397527e-01,
         -1.34628639e-01,  -2.30107084e-02,   5.94515465e-02,
          3.11439663e-01,   4.39245671e-01,  -8.34068432e-02,
          8.05468298e-03,   8.24325830e-02,  -6.42216429e-02,
          1.73451111e-01,   9.77575108e-02,  -9.48499516e-02,
          6.00330293e-01,  -2.85697937e-01,   6.63027644e-01,
          2.28900835e-01,  -5.50854504e-02,   1.96810931e-01,
          1.31078482e-01,   1.16677739e-01,   2.73458511e-01,
         -1.60894319e-01,   1.54009443e-02,   1.65677398e-01,
          4.01737362e-01,   1.94677606e-01,  -3.40434372e-01,
          4.65704620e-01,  -2.72638332e-02,   9.78857726e-02,
          3.00865740e-01,   8.31336603e-02,   6.52762055e-02,
          1.93404332e-01,   4.39618938e-02,   1.97853178e-01,
          6.20303333e-01,  -2.47850232e-02,   3.16133723e-02,
          4.27223206e-01,  -1.78643763e-01,   2.27603521e-02,
          1.01879463e-01,  -1.77166402e-01,  -9.12419409e-02,
          6.85135424e-02,   2.09163412e-01,   2.12687582e-01,
          2.60186791e-01,  -1.92657262e-02,   1.86271384e-01,
          8.68155286e-02,  -1.64935917e-01,  -6.73513263e-02,
          3.51010323e-01,   7.94189423e-02,   3.47567499e-01,
         -3.27353388e-01,   2.28438899e-01,   1.91672705e-02,
          4.34933186e-01,   2.34846137e-02,   5.02053857e-01,
          2.87198114e+00,   3.45609011e-03,  -3.42143588e-02,
          3.52340311e-01,   4.58314866e-01,  -1.96509138e-01,
         -1.23567872e-01,   1.77132830e-01,   6.33585453e-02,
         -2.15546321e-03,   3.33019942e-01,  -5.46362288e-02,
          1.94658935e-01,   2.31957555e-01,  -1.94247887e-01,
          7.14528114e-02,   4.19912785e-02,   3.27715337e-01,
         -1.10557206e-01,  -1.07955880e-01,   1.31638125e-01,
          2.46899307e-01,   7.21076829e-03,   2.77655154e-01,
         -1.57194927e-01,   6.24649376e-02,  -1.32860814e-03,
         -1.57012362e-02,   2.07436994e-01,  -9.61607322e-03,
         -4.07151505e-02,   3.30549240e-01,  -5.71658760e-02,
          5.70487320e-01,  -1.03581101e-01,  -1.79280698e-01,
          3.29045117e-01,   5.74648529e-02,  -8.48884210e-02,
          1.71312660e-01,  -5.71665429e-02,   3.82779270e-01,
          2.49197200e-01,  -1.67588264e-01,  -5.42712435e-02,
          4.65058923e-01,  -3.14851582e-01,   3.38773549e-01,
         -1.19772919e-01,   7.56180510e-02,   2.71076292e-01,
          1.29012525e-01,   1.41996786e-01,   3.30376983e-01,
          2.09672466e-01,   2.74694502e-01,   1.87327504e-01,
          2.14084148e-01,   1.21977694e-01,   5.93084395e-01,
          2.13688929e-02,   8.09027970e-01,   3.09404194e-01,
          3.44152540e-01,   1.66218415e-01,   1.36155128e-01,
          2.33373582e-01,   8.00405815e-03,   1.03328384e-01,
          6.38187110e-01,  -2.65396535e-02], dtype=float32)]

In [65]:
imnetmodel2.layers[17].get_weights()


Out[65]:
[array([[[[  4.07882966e-04,   4.82621184e-03,  -9.11695044e-03, ...,
             1.51569908e-02,  -2.73966836e-03,  -4.83311387e-03],
          [  3.48924054e-03,   2.60589737e-03,  -8.10198858e-03, ...,
             8.86987546e-04,  -7.08238874e-03,  -7.96321197e-04],
          [ -1.12759033e-02,  -6.43836753e-03,  -8.05236772e-03, ...,
             1.90410519e-03,   3.87627119e-03,   1.96338408e-02],
          ..., 
          [ -1.49949323e-02,   1.20318262e-02,   9.87236737e-04, ...,
            -2.89861043e-03,   4.03315574e-03,  -5.93429338e-03],
          [ -7.53336679e-03,   6.08530594e-03,   9.90014290e-04, ...,
             1.63243050e-04,  -3.09621776e-03,  -3.01808352e-03],
          [ -2.62522907e-03,   3.51887429e-03,  -2.58309790e-03, ...,
            -6.02027494e-03,  -8.85035843e-03,   9.85825085e-04]],
 
         [[  3.02846078e-04,   2.64736195e-03,  -1.37099335e-02, ...,
             1.49135189e-02,  -4.65666235e-04,  -6.84898719e-03],
          [ -9.60117579e-03,   5.01031429e-03,  -1.13053191e-02, ...,
             8.86707660e-03,   6.21224102e-03,   2.48882570e-03],
          [ -1.13499342e-02,  -4.72285505e-03,  -8.57903156e-03, ...,
            -3.04920389e-03,   9.67197306e-03,   1.90250184e-02],
          ..., 
          [ -4.48127137e-03,   5.53716440e-03,   4.68912302e-03, ...,
            -4.91005788e-03,   6.40070112e-03,  -8.28019064e-03],
          [ -6.00830279e-03,  -7.51605199e-04,   8.29616503e-04, ...,
             2.07461347e-03,   3.22994636e-03,  -1.69727230e-03],
          [ -2.81035155e-03,   1.36994272e-02,  -2.04460253e-03, ...,
            -5.17683988e-03,  -9.04289633e-03,  -1.79657899e-03]],
 
         [[  3.09069827e-03,  -7.85107608e-04,  -1.12262042e-02, ...,
             1.38624888e-02,  -1.50248851e-03,  -2.83075101e-03],
          [ -1.78263709e-02,  -4.06336552e-03,  -1.11764381e-02, ...,
             1.76884588e-02,  -1.14172359e-03,   1.50952139e-03],
          [ -1.26420632e-02,  -1.19902752e-03,  -1.03873471e-02, ...,
            -1.54873531e-03,   3.21487361e-03,   1.84067711e-02],
          ..., 
          [  4.99952445e-03,   8.96072667e-03,   2.35912274e-03, ...,
            -6.95799524e-03,   9.11425054e-03,  -1.76598097e-03],
          [ -3.11188446e-03,  -4.81695170e-03,   2.14671413e-03, ...,
             8.69878661e-03,   4.66441829e-03,   3.96351190e-03],
          [ -1.56560540e-03,   1.01758400e-02,  -1.81451999e-03, ...,
            -7.93038029e-03,  -7.92690739e-03,   9.85421613e-03]]],
 
 
        [[[  2.21009902e-03,   5.53841889e-03,  -1.51329748e-02, ...,
             1.92244705e-02,  -2.94085429e-03,  -2.05214042e-03],
          [  4.31180233e-03,  -4.67703957e-03,  -9.83539224e-03, ...,
            -1.16664264e-03,  -7.47026131e-03,   8.98758229e-03],
          [ -1.00150378e-02,  -3.31197702e-03,  -4.38165246e-03, ...,
             1.28704909e-04,   6.90069282e-05,   5.32614533e-03],
          ..., 
          [ -1.65325180e-02,   5.79520175e-03,  -1.08136714e-03, ...,
            -3.87264206e-03,   3.87065555e-03,  -8.52444116e-03],
          [ -1.10835498e-02,   6.04208373e-03,   6.12878706e-03, ...,
            -4.66409931e-03,  -1.65367487e-03,  -4.93706390e-03],
          [ -5.82469627e-03,   2.77068373e-03,   2.59765168e-03, ...,
            -9.57501866e-03,  -3.32338479e-03,   3.07677989e-03]],
 
         [[  3.59932799e-03,   1.19693214e-02,  -1.60994809e-02, ...,
             1.80910621e-02,   3.29896147e-06,  -6.10836258e-04],
          [ -7.41903298e-03,  -5.61146066e-03,  -1.38216335e-02, ...,
             2.96197180e-03,   2.69207382e-03,   7.01817824e-03],
          [ -8.48251395e-03,   9.95878596e-04,   6.25522574e-04, ...,
            -3.68017773e-03,   1.27349654e-02,   4.87677474e-03],
          ..., 
          [ -8.20725970e-03,   1.95525214e-03,   2.69707199e-03, ...,
            -4.49266564e-03,   6.45229314e-03,  -1.28380703e-02],
          [ -5.50353806e-03,   1.61080994e-03,   1.39699667e-03, ...,
            -2.52319360e-03,  -4.11227718e-03,  -5.21757640e-03],
          [ -2.69698747e-03,   2.70054420e-03,   3.79564380e-03, ...,
            -7.66708190e-03,  -9.20492224e-03,  -4.52092383e-03]],
 
         [[  2.48262100e-03,   6.13112841e-03,  -1.47995697e-02, ...,
             1.69335436e-02,   1.16662926e-03,   1.17623655e-03],
          [ -1.69411730e-02,  -8.71018134e-03,  -1.29530905e-02, ...,
             1.87354535e-03,  -6.88433880e-04,  -1.68701622e-03],
          [ -6.59902534e-03,   3.46401357e-03,  -3.11806914e-03, ...,
            -4.05590283e-03,   7.37769250e-03,   5.51742781e-03],
          ..., 
          [  9.51702707e-04,   1.64372730e-03,   1.49127271e-03, ...,
            -7.65326899e-03,   1.19846454e-02,  -9.10102390e-03],
          [  2.88849953e-03,  -5.35335718e-03,  -3.08376068e-04, ...,
             3.87483276e-04,  -4.36716061e-03,  -2.73425644e-03],
          [ -1.54271268e-03,   4.30263951e-03,  -4.31923472e-05, ...,
            -5.21167647e-03,  -8.79874174e-03,  -2.11346560e-04]]],
 
 
        [[[ -2.93453527e-03,   4.62880917e-03,  -9.69677325e-03, ...,
             1.48544796e-02,   3.87839018e-03,   1.85810984e-03],
          [  5.63784037e-03,  -6.04889123e-03,  -5.59245935e-03, ...,
            -4.98529337e-03,  -1.92062720e-03,   4.07473044e-03],
          [ -4.84194839e-03,   2.70295335e-04,  -3.02166585e-03, ...,
            -1.49492722e-03,  -1.31164724e-02,   2.69274553e-03],
          ..., 
          [ -1.79702230e-02,  -3.29879066e-03,  -6.12194091e-03, ...,
            -7.89267663e-03,  -1.74841529e-03,  -2.64002383e-03],
          [ -1.11466460e-02,   5.13884844e-03,   1.51880039e-02, ...,
            -4.87166690e-03,   2.45198980e-03,  -3.42866592e-03],
          [ -6.12380216e-03,   8.87359586e-03,  -3.45014478e-03, ...,
            -1.09723555e-02,   2.66773975e-03,  -4.79325093e-03]],
 
         [[ -6.14633691e-03,   1.40388934e-02,  -9.19489283e-03, ...,
             1.60656814e-02,   8.88941437e-03,   6.56510517e-03],
          [ -5.72578516e-03,  -3.33702704e-03,  -8.64025764e-03, ...,
             1.98416272e-03,   7.86264334e-03,   2.50778953e-03],
          [ -3.77366156e-03,   9.24240507e-04,   7.29091058e-04, ...,
            -4.96890210e-03,   3.85057204e-03,  -7.15580711e-04],
          ..., 
          [ -1.22111076e-02,  -2.42003356e-03,  -4.81141545e-03, ...,
            -4.22020489e-03,  -1.01946108e-02,  -5.80721162e-03],
          [ -9.04400460e-03,   1.94370467e-03,   7.34009594e-03, ...,
            -5.14973374e-03,   3.66879918e-04,  -5.37241250e-03],
          [ -3.53684562e-04,   1.53788179e-02,  -8.76262202e-04, ...,
            -7.13666994e-03,  -4.27656015e-03,  -1.42133404e-02]],
 
         [[ -6.67408668e-03,   9.11168288e-03,  -9.18486901e-03, ...,
             1.21346870e-02,   8.51947255e-03,   7.15135690e-03],
          [ -1.64910071e-02,  -2.04550894e-03,  -7.30760070e-03, ...,
            -2.89353775e-03,   1.16095145e-03,  -6.60440046e-03],
          [ -7.68517129e-05,   4.32093628e-03,  -6.93119306e-04, ...,
            -3.48316878e-03,  -1.47545757e-03,  -2.85687298e-03],
          ..., 
          [ -4.66702832e-03,  -1.39780261e-03,   3.67210196e-05, ...,
            -4.95146902e-04,   7.23151665e-04,  -6.29519764e-03],
          [  3.63699184e-03,  -4.63909749e-03,   5.31478412e-03, ...,
            -1.50180201e-03,  -7.48660788e-03,  -1.94359326e-03],
          [ -1.03440508e-03,   1.57131702e-02,  -1.98940560e-03, ...,
            -5.38550608e-04,  -5.37431426e-03,  -9.20103770e-03]]]], dtype=float32),
 array([  1.88378572e-01,  -5.00367463e-01,   5.42223394e-01,
          2.46460959e-01,   1.54070303e-01,  -2.36067176e-01,
         -1.17649809e-02,   3.57512347e-02,   7.58338273e-02,
          1.63476378e-01,  -1.34778112e-01,  -8.40371996e-02,
          2.50966042e-01,  -1.67475253e-01,  -2.82782689e-02,
          4.04935628e-01,   4.92739901e-02,   3.43014568e-01,
         -2.48226017e-01,  -8.52851495e-02,   1.14871934e-01,
         -8.34204536e-03,  -7.97333941e-02,   2.08946794e-01,
          2.29255453e-01,  -3.57115209e-01,   3.54569256e-01,
          4.94823381e-02,   2.67764390e-01,   1.16772160e-01,
          2.48077109e-01,   1.90769851e-01,   2.27198079e-01,
          2.07326874e-01,   4.33389664e-01,  -2.14167282e-01,
          4.27582026e-01,   2.85164490e-02,  -1.01103269e-01,
         -1.16591506e-01,   1.57484300e-02,  -1.92446187e-01,
          5.09383738e-01,  -1.01140939e-01,  -1.70503020e-01,
          1.82109758e-01,   6.56641722e-02,   1.48948044e-01,
         -3.34800705e-02,   2.34267697e-01,   1.17521681e-01,
         -1.11647561e-01,   1.67274535e-01,  -2.18229502e-01,
         -1.26343705e-02,   6.51194036e-01,   4.33828384e-01,
          5.46606928e-02,   2.51551688e-01,   2.21985489e-01,
          2.07218826e-02,  -2.58966297e-01,   1.32507131e-01,
          1.47451892e-01,  -1.49491996e-01,  -2.45121513e-02,
         -1.93051482e-03,   3.55903581e-02,  -2.87072897e-01,
          2.04153866e-01,   5.73086739e-02,   1.29463181e-01,
          1.23248003e-01,  -1.90378204e-01,  -5.25708608e-02,
         -8.20820853e-02,   7.67999232e-01,   2.17065111e-01,
          4.36754115e-02,  -6.61685169e-02,   1.55227348e-01,
          6.22618794e-01,   1.98174551e-01,   1.35126531e-01,
          1.28762200e-01,  -4.85090315e-02,   4.69657898e-01,
          4.86439429e-02,   3.53257835e-01,   5.42547941e-01,
         -2.09446177e-01,   1.35347247e-01,   1.24633104e-01,
          2.24511325e-01,  -1.93987757e-01,  -1.69384852e-02,
          6.01346325e-03,   2.04649493e-01,  -3.49047594e-02,
          3.08254182e-01,   2.74999171e-01,   6.06408417e-01,
          1.30885825e-01,  -7.84191936e-02,   2.30702013e-01,
          6.21092655e-02,   1.07052080e-01,  -2.47026488e-01,
          3.11956823e-01,   2.79106498e-01,   2.18370885e-01,
          1.03057109e-01,   5.74263111e-02,   1.94899786e+00,
         -9.07675177e-02,   7.99698196e-03,   1.57724932e-01,
          6.45613790e-01,   1.95434928e-01,   6.70031726e-01,
         -1.17897667e-01,   2.08516628e-01,   1.35548666e-01,
          5.05479157e-01,   2.27726430e-01,  -2.85992660e-02,
          7.31752664e-02,   2.16317698e-01,   1.04756050e-01,
          7.34472694e-03,  -9.85700116e-02,  -2.09823661e-02,
         -1.19556062e-01,   4.82213408e-01,   2.29107309e-02,
          7.89495856e-02,   1.66905075e-01,   2.03251719e-01,
          2.19120562e-01,   3.17676008e-01,   2.38415692e-03,
          4.65317338e-04,   5.53632751e-02,   2.63843596e-01,
         -2.68867999e-01,  -6.39354065e-02,   3.14108700e-01,
         -1.04466088e-01,   2.15531588e-01,   2.69292265e-01,
          6.31085504e-03,   2.11812276e-02,   3.03376783e-02,
          1.34254768e-01,   1.78778559e-01,   9.43155289e+00,
          2.75686860e-01,   1.31738886e-01,   1.86976731e-01,
          8.58496577e-02,   1.49559855e-01,  -2.00136185e-01,
         -3.02753776e-01,   6.99055195e-01,   1.03292175e-01,
          5.93839027e-02,   6.86080813e-01,  -1.75999016e-01,
          1.97002128e-01,   2.17421085e-01,   1.00237295e-01,
          2.00453222e-01,   5.19402325e-01,   3.03252012e-01,
          1.08759388e-01,   2.52096474e-01,   9.80204344e-02,
          6.79299794e-03,   4.11590002e-02,   3.55982512e-01,
          9.82239395e-02,  -1.27133965e-01,   5.89193106e-02,
         -2.11274922e-02,  -9.46500301e-02,   3.23439181e-01,
          5.33190012e-01,   2.81205267e-01,  -7.00195059e-02,
          4.50011939e-02,   5.85235953e-02,  -2.72989403e-02,
          1.23330429e-01,   1.57047048e-01,   6.30159453e-02,
         -1.79739177e-01,   1.68211743e-01,  -2.27243900e-02,
          1.42132714e-01,   2.76279449e-01,   4.04965654e-02,
         -1.99054778e-01,   3.65843683e-01,   2.73112729e-02,
         -1.31376877e-01,   9.32270288e-02,  -7.60697424e-02,
          1.93399116e-02,   1.85015425e-03,   4.15253565e-02,
          2.56592147e-02,  -6.57611638e-02,   3.76626439e-02,
          2.72211343e-01,   1.40291587e-01,   3.34124207e-01,
         -4.18526232e-02,  -9.58744287e-02,   2.74706990e-01,
         -1.55596823e-01,   3.64604779e-02,  -1.32014111e-01,
          1.34014981e-02,  -4.87616658e-02,   1.06156722e-01,
          5.36326528e-01,   3.72983187e-01,   3.38566378e-02,
         -8.60288590e-02,   7.98788011e-01,  -1.82336777e-01,
          1.64008543e-01,   1.88149005e-01,   1.57651126e-01,
          8.60020444e-02,   5.53895067e-03,   2.04019845e-02,
          3.66550952e-01,   1.50018111e-01,   6.82196319e-02,
          1.26301348e-01,   2.67437845e-01,   1.32230207e-01,
          6.47044480e-02,   2.42651135e-01,   7.22966492e-02,
          1.25669807e-01,  -6.93451017e-02,   4.69704807e-01,
          1.46840796e-01,   1.52075395e-01,   1.08058611e-02,
          7.89734907e-03,  -1.83315612e-02,   1.02967513e+00,
          2.86464036e-01,   2.72089839e-01,   2.99726725e-02,
          1.12274528e-01,   3.48836958e-01,  -6.20776117e-02,
          2.17991203e-01,   4.28738832e-01,  -4.16037142e-02,
          3.66377145e-01,   1.08046882e-01,  -2.55869627e-02,
         -4.00224268e-01,  -2.40779221e-01,   7.19139993e-01,
         -5.15835034e-03,   4.65480566e-01,   1.19287916e-01,
         -1.20954335e-01,   2.40479499e-01,   4.27416801e-01,
          5.59932351e-01,   1.26139030e-01,  -1.14825912e-01,
          1.22176088e-01,   2.95618027e-02,  -7.13887066e-02,
          2.86794007e-01,   2.46085122e-01,   1.81327894e-01,
          3.12949091e-01,  -9.33331028e-02,   1.16926350e-03,
         -2.63316602e-01,   3.58326316e-01,   1.62727624e-01,
          3.76439899e-01,   3.91090691e-01,   1.10005677e-01,
          1.11292467e-01,   2.07414851e-02,   1.14994623e-01,
          6.28707856e-02,   5.34125865e-01,  -2.11611167e-01,
          5.91500774e-02,  -1.58647493e-01,  -3.78553174e-03,
          3.52953747e-02,  -2.05919351e-02,   1.53826475e-01,
          1.20451070e-01,   1.26241818e-01,  -6.20619431e-02,
         -1.44232456e-02,  -1.47647366e-01,  -1.82920575e-01,
          2.08717108e-01,   3.31947088e-01,  -8.80439430e-02,
          1.55856574e+00,   2.22004980e-01,   2.32446954e-01,
          5.67621551e-02,   3.97473991e-01,   5.03389001e-01,
         -1.44024760e-01,   1.91921026e-01,  -1.38310969e-01,
         -6.44080155e-03,   3.39745015e-01,   4.69098449e-01,
          2.28332952e-02,   6.56073332e-01,   2.45110661e-01,
         -1.68141842e-01,   7.19269738e-02,  -1.22520126e-01,
         -2.34832615e-01,   1.96609661e-01,   8.65012854e-02,
          1.28099874e-01,  -9.01192203e-02,   4.89099592e-01,
         -1.34810328e-01,   1.06568784e-01,   1.27098143e-01,
          4.38580155e-01,   4.55901057e-01,   4.61729169e-02,
          1.65377498e-01,   3.57421547e-01,   9.74082127e-02,
         -2.31282339e-01,   8.46065506e-02,   2.89760232e-01,
         -9.88961682e-02,   9.01378930e-01,   2.52402127e-01,
         -2.15688810e-01,  -5.59736192e-02,  -1.13818742e-01,
         -6.13411656e-03,  -1.34001493e-01,   1.61142886e-01,
         -4.80620004e-02,   1.38647243e-01,  -3.01776342e-02,
          1.83977813e-01,  -1.18016593e-01,   3.89179081e-01,
          6.13915585e-02,   1.58884943e-01,   5.89057468e-02,
          5.19612193e-01,   1.23953849e-01,   5.55581629e-01,
          5.01390219e-01,  -3.79978642e-02,  -1.41257286e-01,
          7.03621209e-02,  -1.73130766e-01,   3.50397527e-01,
         -1.34628639e-01,  -2.30107084e-02,   5.94515465e-02,
          3.11439663e-01,   4.39245671e-01,  -8.34068432e-02,
          8.05468298e-03,   8.24325830e-02,  -6.42216429e-02,
          1.73451111e-01,   9.77575108e-02,  -9.48499516e-02,
          6.00330293e-01,  -2.85697937e-01,   6.63027644e-01,
          2.28900835e-01,  -5.50854504e-02,   1.96810931e-01,
          1.31078482e-01,   1.16677739e-01,   2.73458511e-01,
         -1.60894319e-01,   1.54009443e-02,   1.65677398e-01,
          4.01737362e-01,   1.94677606e-01,  -3.40434372e-01,
          4.65704620e-01,  -2.72638332e-02,   9.78857726e-02,
          3.00865740e-01,   8.31336603e-02,   6.52762055e-02,
          1.93404332e-01,   4.39618938e-02,   1.97853178e-01,
          6.20303333e-01,  -2.47850232e-02,   3.16133723e-02,
          4.27223206e-01,  -1.78643763e-01,   2.27603521e-02,
          1.01879463e-01,  -1.77166402e-01,  -9.12419409e-02,
          6.85135424e-02,   2.09163412e-01,   2.12687582e-01,
          2.60186791e-01,  -1.92657262e-02,   1.86271384e-01,
          8.68155286e-02,  -1.64935917e-01,  -6.73513263e-02,
          3.51010323e-01,   7.94189423e-02,   3.47567499e-01,
         -3.27353388e-01,   2.28438899e-01,   1.91672705e-02,
          4.34933186e-01,   2.34846137e-02,   5.02053857e-01,
          2.87198114e+00,   3.45609011e-03,  -3.42143588e-02,
          3.52340311e-01,   4.58314866e-01,  -1.96509138e-01,
         -1.23567872e-01,   1.77132830e-01,   6.33585453e-02,
         -2.15546321e-03,   3.33019942e-01,  -5.46362288e-02,
          1.94658935e-01,   2.31957555e-01,  -1.94247887e-01,
          7.14528114e-02,   4.19912785e-02,   3.27715337e-01,
         -1.10557206e-01,  -1.07955880e-01,   1.31638125e-01,
          2.46899307e-01,   7.21076829e-03,   2.77655154e-01,
         -1.57194927e-01,   6.24649376e-02,  -1.32860814e-03,
         -1.57012362e-02,   2.07436994e-01,  -9.61607322e-03,
         -4.07151505e-02,   3.30549240e-01,  -5.71658760e-02,
          5.70487320e-01,  -1.03581101e-01,  -1.79280698e-01,
          3.29045117e-01,   5.74648529e-02,  -8.48884210e-02,
          1.71312660e-01,  -5.71665429e-02,   3.82779270e-01,
          2.49197200e-01,  -1.67588264e-01,  -5.42712435e-02,
          4.65058923e-01,  -3.14851582e-01,   3.38773549e-01,
         -1.19772919e-01,   7.56180510e-02,   2.71076292e-01,
          1.29012525e-01,   1.41996786e-01,   3.30376983e-01,
          2.09672466e-01,   2.74694502e-01,   1.87327504e-01,
          2.14084148e-01,   1.21977694e-01,   5.93084395e-01,
          2.13688929e-02,   8.09027970e-01,   3.09404194e-01,
          3.44152540e-01,   1.66218415e-01,   1.36155128e-01,
          2.33373582e-01,   8.00405815e-03,   1.03328384e-01,
          6.38187110e-01,  -2.65396535e-02], dtype=float32)]

In [68]:
# Variables
images = np.empty([dataset.size, dataset.batch_height, dataset.batch_width, 3], dtype=np.float32)
normals = np.empty([dataset.size, dataset.batch_height, dataset.batch_width, 3], dtype=np.float32)
preds = np.empty([dataset.size, dataset.batch_height, dataset.batch_width, 3], dtype=np.float32)

In [73]:
for i in range(dataset.size):
        images[i], normals[i] = dataset.get_data(i)

In [83]:
for i in range(25):
    model.train_on_batch(images,normals)

In [79]:
# Prediction
for i in range(dataset.size):
        print('Index: '+str(i))
        preds[i] = model.predict_on_batch(images[i].reshape((1,dataset.batch_height, dataset.batch_width, 3 )))


Index: 0
Index: 1
Index: 2
Index: 3
Index: 4
Index: 5
Index: 6
Index: 7
Index: 8
Index: 9

In [80]:
show_normals(preds[1])


Out[80]:

Code


In [71]:
%%writefile ../Code/Models/VGG16.py
"""Model based on VGG16:

# Reference

- [Very Deep Convolutional Networks for Large-Scale Image Recognition](https://arxiv.org/abs/1409.1556)

"""

import warnings

import tensorflow as tf

from keras.models import Model
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Input
from keras.layers import Reshape
from keras.layers import Lambda
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.utils.data_utils import get_file



WEIGHTS_PATH_NO_TOP = 'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5'


def VGG16(weights='imagenet',
          input_shape=(240, 320, 3)):
    """Instantiates the VGG16-based architecture.

    Optionally loads weights pre-trained
    on ImageNet. Note that when using TensorFlow,
    for best performance you should set
    `image_data_format='channels_last'` in your Keras config
    at ~/.keras/keras.json.

    # Arguments
        weights: one of `None` (random initialization)
            or 'imagenet' (pre-training on ImageNet).
        input_shape: optional shape tuple,
            It should have exactly 3 input channels,
            and width and height should be no smaller than 48.
            E.g. `(200, 200, 3)` would be one valid value.

    # Returns
        A Keras model instance.

    # Raises
        ValueError: in case of invalid argument for `weights`,
            or invalid input shape.
    """
    if weights not in {'imagenet', None}:
        raise ValueError('The `weights` argument should be either '
                         '`None` (random initialization) or `imagenet` '
                         '(pre-training on ImageNet).')


    img_input = Input(shape=input_shape)

    # Block 1
    x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1')(img_input)
    x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(x)

    # Block 2
    x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1')(x)
    x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)

    # Block 3
    x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1')(x)
    x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2')(x)
    x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name='block3_pool')(x)

    # Block 4
    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1')(x)
    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2')(x)
    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x)

    # Block 5
    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1')(x)
    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2')(x)
    x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3')(x)
    x = MaxPooling2D((2, 2), strides=(2, 2), name='block5_pool')(x)

    # Top Layers
    x = Flatten()(x)
    x = Dense(4096, activation='relu', name='fc1')(x)
    x = Dense(80*60*3, activation='relu', name='fc2')(x)
    x = Reshape((60,80,3))(x)
    x = Lambda(lambda x: tf.image.resize_bilinear(x , [240,320]) )(x)
    x = Lambda(lambda x: tf.nn.l2_normalize(x, 3) )(x)
    
    # Create model.
    inputs = img_input
    model = Model(inputs, x, name='vgg16')

    # load weights
    if weights == 'imagenet':
        weights_path = get_file('vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5',
                                WEIGHTS_PATH_NO_TOP,
                                cache_subdir='models')
        model.load_weights(weights_path, by_name=True)
    
    return model


Overwriting ../Code/Models/VGG16.py

In [ ]: