import numpy as np
from keras.models import Model, Sequential
from keras.layers import Conv2D, MaxPooling2D, Reshape
from keras.applications.vgg19 import VGG19
from keras.callbacks import CSVLogger, ModelCheckpoint

IMG_WIDTH, IMG_HEIGHT = 368, 368

vgg19 = VGG19(include_top=False, weights='imagenet', input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))

for i in range(8):
    vgg19.layers.pop()
vgg19.outputs = [vgg19.layers[-1].output]

m = Sequential()
m.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block4_conv3_CPM',
             input_shape=vgg19.layers[-1].output_shape[1:]))
m.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block4_conv4_CPM'))

# stage1 part confidence map
m.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block5_conv1_CMP_L2'))
m.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block5_conv2_CMP_L2'))
m.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block5_conv3_CMP_L2'))
m.add(Conv2D(512, (1, 1), activation='relu', padding='same', name='block5_conv4_CMP_L2'))
m.add(Conv2D(1,   (1, 1), activation='relu', padding='same', name='block5_conv5_CMP_L2'))
m.add(Reshape((46 * 46 * 1, )))

# PoseNet
model = Model(inputs=vgg19.inputs, outputs=m(vgg19.outputs))
model.summary()

data = np.load('data/input_img_data.npy')
heatmaps = np.load('data/heatmaps.npy')
filenames = np.load('data/filenames.npy')

heatmaps = heatmaps.reshape((-1, 46 * 46 * 1))

logger = CSVLogger('train.log')
weight_file = 'train.{epoch:02d}-{loss:.3f}.h5'
checkpoint = ModelCheckpoint(
    weight_file,
    monitor='loss',
    verbose=1,
    save_best_only=True,
    mode='auto')

def custom_loss(y_true, y_pred):
    epsilon = K.variable(value=np.zeros_like(y_true) + 1e-10)
    mask = K.cast(K.greater(y_true, epsilon), dtype='float32')
    y_true = y_true * mask
    y_pred = y_pred * mask
    return K.sum(K.square(y_pred - y_true), axis=[1])

model.compile(loss='mean_squared_error', optimizer='adam')
#model.compile(loss=custom_loss, optimizer='adam')
model.fit(data, heatmaps, batch_size=16, epochs=20, verbose=1,
          callbacks=[logger, checkpoint])

@@ -12,16 +12,42 @@
 y as np%0A
+import keras.backend as K%0A
 from ker
@@ -269,16 +269,48 @@
 8, 368%0A%0A
+# Do not use imagenet weights!!%0A
 vgg19 = 
@@ -346,18 +346,12 @@
 hts=
-'imagenet'
+None
 , in
@@ -1451,16 +1451,98 @@
 .npy')%0A%0A
+# for MemoryError%0Afor i in range(len(data)):%0A    data%5Bi%5D = data%5Bi%5D / 256.0 - 0.5%0A%0A
 heatmaps
@@ -2053,16 +2053,17 @@
 s=%5B1%5D)%0A%0A
+#
 model.co
@@ -2113,17 +2113,16 @@
 'adam')%0A
-#
 model.co
@@ -2204,10 +2204,10 @@
 ize=
-16
+32
 , ep
@@ -2211,17 +2211,18 @@
  epochs=
-2
+10
 0, verbo

Modify not to use imagenet weights