# Path: src/utils/VGG.py
# def VGG_16(weights_path = None):
#     model = Sequential()
#     model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))
#     model.add(Convolution2D(64, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(64, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(128, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(128, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(256, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(256, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(256, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(Flatten())
#     model.add(Dense(4096, activation='relu'))
#     model.add(Dropout(0.5))
#     model.add(Dense(4096, activation='relu'))
#     model.add(Dropout(0.5))
#     model.add(Dense(1000, activation='softmax'))
# 
#     if weights_path:
#         model.load_weights(weights_path)
# 
#     #Remove the last two layers to get the 4096D activations
#     model = pop(model)
#     model = pop(model)
# 
#     return model


import sys, os 
import cv2, spacy, numpy as np
from keras.models import model_from_json
from keras.optimizers import SGD
from keras import backend as K
from sklearn.externals import joblib
from .VGG import VGG_16
Code modified from 
https://github.com/iamaaditya/VQA_Demo/blob/master/Visual_Question_Answering_Demo_in_python_notebook.ipynb
Please visit there to get the trained weights :)
"""

K.set_image_dim_ordering('th')


VQA_model_file_name     = 'tmp/visualqa/VQA_MODEL.json'
VQA_weights_file_name   = 'tmp/visualqa/VQA_MODEL_WEIGHTS.hdf5'
label_encoder_file_name = 'tmp/visualqa/FULL_labelencoder_trainval.pkl'
CNN_weights_file_name   = 'tmp/visualqa/vgg16_weights.h5'


label_encoder_file_name = '/home/thtrieu/numpyflow/tmp/visualqa/FULL_labelencoder_trainval.pkl'
labelencoder = joblib.load(label_encoder_file_name)
all_words = list()
for count in range(1000):
    all_words.append(labelencoder.inverse_transform(count))

def glove_embed(question):
    word_embeddings = spacy.load(
        'en', vectors = 'en_glove_cc_300_1m_vectors')
    tokens = word_embeddings(question)
    question_tensor = np.zeros((30, 300))
    for j in range(len(tokens)):
        question_tensor[j, :] = tokens[j].vector
    return question_tensor

def get_image_model(CNN_weights_file_name):

# Path: src/utils/VGG.py
# def VGG_16(weights_path = None):
#     model = Sequential()
#     model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))
#     model.add(Convolution2D(64, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(64, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(128, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(128, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(256, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(256, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(256, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(ZeroPadding2D((1,1)))
#     model.add(Convolution2D(512, 3, 3, activation='relu'))
#     model.add(MaxPooling2D((2,2), strides=(2,2)))
# 
#     model.add(Flatten())
#     model.add(Dense(4096, activation='relu'))
#     model.add(Dropout(0.5))
#     model.add(Dense(4096, activation='relu'))
#     model.add(Dropout(0.5))
#     model.add(Dense(1000, activation='softmax'))
# 
#     if weights_path:
#         model.load_weights(weights_path)
# 
#     #Remove the last two layers to get the 4096D activations
#     model = pop(model)
#     model = pop(model)
# 
#     return model


# Path: src/utils/visualqa.py
import sys, os 
import cv2, spacy, numpy as np
from keras.models import model_from_json
from keras.optimizers import SGD
from keras import backend as K
from sklearn.externals import joblib
from .VGG import VGG_16

Code modified from 
https://github.com/iamaaditya/VQA_Demo/blob/master/Visual_Question_Answering_Demo_in_python_notebook.ipynb
Please visit there to get the trained weights :)
"""

K.set_image_dim_ordering('th')


VQA_model_file_name     = 'tmp/visualqa/VQA_MODEL.json'
VQA_weights_file_name   = 'tmp/visualqa/VQA_MODEL_WEIGHTS.hdf5'
label_encoder_file_name = 'tmp/visualqa/FULL_labelencoder_trainval.pkl'
CNN_weights_file_name   = 'tmp/visualqa/vgg16_weights.h5'


label_encoder_file_name = '/home/thtrieu/numpyflow/tmp/visualqa/FULL_labelencoder_trainval.pkl'
labelencoder = joblib.load(label_encoder_file_name)
all_words = list()
for count in range(1000):
    all_words.append(labelencoder.inverse_transform(count))

def glove_embed(question):
    word_embeddings = spacy.load(
        'en', vectors = 'en_glove_cc_300_1m_vectors')
    tokens = word_embeddings(question)
    question_tensor = np.zeros((30, 300))
    for j in range(len(tokens)):
        question_tensor[j, :] = tokens[j].vector
    return question_tensor

def get_image_model(CNN_weights_file_name):

    image_model = VGG_16(CNN_weights_file_name)