# Path: little_foo3.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, 8, 8,
# 			        input_shape=input_shape,init=weight_init, name='conv1_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 6, 6,init=weight_init, name='conv1_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 4, 4,init=weight_init, name='conv1_3'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 2, 2,init=weight_init, name='conv1_4'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2))) # in 208, out 104
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(64, 8, 8,init=weight_init, name='conv2_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 6, 6,init=weight_init, name='conv2_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 4, 4,init=weight_init, name='conv2_3'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 2, 2,init=weight_init, name='conv2_4'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2))) # in is 88, out is 44 
# 	model.add(Dropout(dropout))
# 
# 	model.add(Flatten())
# 	model.add(Dense(220, init=weight_init))
# 	model.add(Activation('relu'))
# 	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 little_foo3 import foo
def get_data(n_dataset):    
    f = file('MODS_224_224_{0}_test_3.pkl'.format(n_dataset),'rb')
    data = cPickle.load(f)
    f.close()
    validation_data = data[0]
    training_data = data[1]
    t_data = training_data[0]
    t_label = training_data[1]
    test_data = validation_data[0]
    test_label = validation_data[1]
    
    t_data = np.array(t_data)
    t_label = np.array(t_label)
    test_data = np.array(test_data)
    test_label = np.array(test_label)
    t_data = t_data.reshape(t_data.shape[0], 1, 224, 224)
    test_data = test_data.reshape(test_data.shape[0], 1, 224, 224)
    
    #less precision means less memory needed: 64 -> 32 (half the memory used)
    t_data = t_data.astype('float32')
    test_data = test_data.astype('float32')
    
    return (t_data, t_label), (test_data, test_label)

def test_net(i):

	model = get_weights(i, username)
	print 'using weights from net trained on dataset {0}'.format(i)
	history = LossAccHistory()


# Path: little_foo3.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, 8, 8,
# 			        input_shape=input_shape,init=weight_init, name='conv1_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 6, 6,init=weight_init, name='conv1_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 4, 4,init=weight_init, name='conv1_3'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(32, 2, 2,init=weight_init, name='conv1_4'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2))) # in 208, out 104
# 	model.add(Dropout(dropout))
# 
# 	model.add(Convolution2D(64, 8, 8,init=weight_init, name='conv2_1'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 6, 6,init=weight_init, name='conv2_2'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 4, 4,init=weight_init, name='conv2_3'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(Convolution2D(64, 2, 2,init=weight_init, name='conv2_4'))
# 	model.add(BatchNormalization())
# 	model.add(Activation('relu'))
# 	model.add(MaxPooling2D(pool_size=(2, 2))) # in is 88, out is 44 
# 	model.add(Dropout(dropout))
# 
# 	model.add(Flatten())
# 	model.add(Dense(220, init=weight_init))
# 	model.add(Activation('relu'))
# 	model.add(Dropout(dropout))
# 
# 	model.add(Dense(2))
# 	model.add(Activation('sigmoid'))
# 
# 	return model


# Path: test_lillabcrossval_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 little_foo3 import foo

def get_data(n_dataset):    
    f = file('MODS_224_224_{0}_test_3.pkl'.format(n_dataset),'rb')
    data = cPickle.load(f)
    f.close()
    validation_data = data[0]
    training_data = data[1]
    t_data = training_data[0]
    t_label = training_data[1]
    test_data = validation_data[0]
    test_label = validation_data[1]
    
    t_data = np.array(t_data)
    t_label = np.array(t_label)
    test_data = np.array(test_data)
    test_label = np.array(test_label)
    t_data = t_data.reshape(t_data.shape[0], 1, 224, 224)
    test_data = test_data.reshape(test_data.shape[0], 1, 224, 224)
    
    #less precision means less memory needed: 64 -> 32 (half the memory used)
    t_data = t_data.astype('float32')
    test_data = test_data.astype('float32')
    
    return (t_data, t_label), (test_data, test_label)

def test_net(i):

	model = get_weights(i, username)
	print 'using weights from net trained on dataset {0}'.format(i)
	history = LossAccHistory()


    	(X_train, y_train), (X_test, y_test) = get_data(i)