# Path: foo_three.py
# def foo():
# 
#     # Determine proper input shape
# 	if keras.__version__ > '1.0.3':
# 		K.set_image_dim_ordering('th')
# 	input_shape = (1, 224, 224)
# 
# 	#img_input = Input(shape=input_shape)
# 
# 	model = Sequential()
# 
# 	model.add(Convolution2D(32, 3, 3,
# 			        input_shape=input_shape,init=weight_init, name='conv1_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 3, 3,init=weight_init, name='conv1_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(64, 3, 3,init=weight_init, name='conv2_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 3, 3,init=weight_init, name='conv2_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 3, 3,init=weight_init, name='conv2_3'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))  
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(128, 3, 3,init=weight_init, name='conv3_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(128, 3, 3,init=weight_init, name='conv3_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))  
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(512, 3,3,init=weight_init, border_mode='same', name='conv4_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(512, 3,3,init=weight_init, border_mode='same', name='conv4_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))  
# 	model.add(Dropout(dropout))
# 
# 	model.add(Flatten())
# 	model.add(Dense(120, init=weight_init))
# 	model.add(Activation('relu'))
# 	model.add(Dropout(dropout))
# 
# 	model.add(Dropout(dropout))
# 	model.add(Dense(2))
# 	model.add(Activation('sigmoid'))
# 
# 	return model


import keras
import keras.backend as K
import cPickle
import numpy as np
import getpass
from keras.optimizers import SGD, adadelta, rmsprop, adam
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import np_utils
from keras.metrics import matthews_correlation, precision, recall
from foo_three import foo
   	tn = K.sum(y_neg * y_pred_neg)

  	fp = K.sum(y_neg * y_pred_pos)
  	fn = K.sum(y_pos * y_pred_neg)

	se = tp / (tp + fn)
	return se

def spec(y_true, y_pred):

	y_pred_pos = K.round(K.clip(y_pred, 0, 1))
    	y_pred_neg = 1 - y_pred_pos

   	y_pos = K.round(K.clip(y_true, 0, 1))
   	y_neg = 1 - y_pos

   	tp = K.sum(y_pos * y_pred_pos)
   	tn = K.sum(y_neg * y_pred_neg)

  	fp = K.sum(y_neg * y_pred_pos)
  	fn = K.sum(y_pos * y_pred_neg)

	sp = tn / (fp + tn)
	return sp



def get_weights(n_dataset):
    weights='best_weights_{0}_{1}.h5'.format(i,'santiago')
    model = foo()

# Path: foo_three.py
# def foo():
# 
#     # Determine proper input shape
# 	if keras.__version__ > '1.0.3':
# 		K.set_image_dim_ordering('th')
# 	input_shape = (1, 224, 224)
# 
# 	#img_input = Input(shape=input_shape)
# 
# 	model = Sequential()
# 
# 	model.add(Convolution2D(32, 3, 3,
# 			        input_shape=input_shape,init=weight_init, name='conv1_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 3, 3,init=weight_init, name='conv1_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(64, 3, 3,init=weight_init, name='conv2_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 3, 3,init=weight_init, name='conv2_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 3, 3,init=weight_init, name='conv2_3'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))  
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(128, 3, 3,init=weight_init, name='conv3_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(128, 3, 3,init=weight_init, name='conv3_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))  
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(512, 3,3,init=weight_init, border_mode='same', name='conv4_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(512, 3,3,init=weight_init, border_mode='same', name='conv4_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2)))  
# 	model.add(Dropout(dropout))
# 
# 	model.add(Flatten())
# 	model.add(Dense(120, init=weight_init))
# 	model.add(Activation('relu'))
# 	model.add(Dropout(dropout))
# 
# 	model.add(Dropout(dropout))
# 	model.add(Dense(2))
# 	model.add(Activation('sigmoid'))
# 
# 	return model


# Path: STM_Code/test_network.py
import keras
import keras.backend as K
import cPickle
import numpy as np
import getpass
from keras.optimizers import SGD, adadelta, rmsprop, adam
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import np_utils
from keras.metrics import matthews_correlation, precision, recall
from foo_three import foo

   	tn = K.sum(y_neg * y_pred_neg)

  	fp = K.sum(y_neg * y_pred_pos)
  	fn = K.sum(y_pos * y_pred_neg)

	se = tp / (tp + fn)
	return se

def spec(y_true, y_pred):

	y_pred_pos = K.round(K.clip(y_pred, 0, 1))
    	y_pred_neg = 1 - y_pred_pos

   	y_pos = K.round(K.clip(y_true, 0, 1))
   	y_neg = 1 - y_pos

   	tp = K.sum(y_pos * y_pred_pos)
   	tn = K.sum(y_neg * y_pred_neg)

  	fp = K.sum(y_neg * y_pred_pos)
  	fn = K.sum(y_pos * y_pred_neg)

	sp = tn / (fp + tn)
	return sp



def get_weights(n_dataset):
    weights='best_weights_{0}_{1}.h5'.format(i,'santiago')
    model = foo()

    model.load_weights(weights)