# Path: src/net.py
# class Net(object):
#     # Sugar syntax
#     def __init__(self):
#         self._server = ParameterServer()
#         self._finalized = False
#         self._dagraph = DAG()
#         coated = sugar.__dict__
#         for name, fun in coated.items():
#             if callable(fun): setattr(Net, name, fun)
#  
#     # To be sugar coated
#     def _x(self, name, *args):
#         assert not self._finalized, \
#         'Graph is finalized by setting an optimizer'
#         return self._dagraph.register_for_slot(
#             name, self._server, *args)
# 
#     def optimize(self, ptr, optimizer,
#                  *args, **kwargs):
#         self._finalized = True
#         self._dagraph.set_closure(ptr)
#         self._server.set_optimizer(
#             optimizer, *args, **kwargs)
# 
#     def forward(self, fetches, feed):
#         return self._dagraph.forward(fetches, feed)
# 
#     def train(self, fetches, feed):
#         val = self._dagraph.forward_to_leaf(fetches, feed)
#         self._dagraph.backward()
#         self._server.apply_optimizer()
#         return val
# 
#     def save_checkpoint(self, file_name):
#         self._server.save(file_name)
# 
#     def load_checkpoint(self, file_name, *args, **kwargs):
#         self._server.load(file_name, *args, **kwargs)
# 
# Path: src/utils/visualqa.py
# def yield_weights(model):
#     for layer in model.layers:
#         weights = layer.get_weights()
#         if len(weights): 
#             weights = [
#                 w.astype(np.float64) 
#                 for w in weights]
#             yield(weights)
# 
# def to_word(predict):
#     label = np.argmax(predict)
#     return labelencoder.inverse_transform(label)
# 
# Path: src/utils/visualqa.py
# 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 read_image(image_file_name):
#     image_features = np.zeros((1, 4096))
#     im = cv2.resize(cv2.imread(image_file_name), (224, 224))
#     return im.astype(np.float64).copy(order = 'C')
# 
# Path: src/utils/visualqa.py
# def glove_embed(question):
# def get_image_model(CNN_weights_file_name):
# def get_VQA_model(VQA_model_file_name, VQA_weights_file_name):
# def yield_weights(model):
# def vqa_models(VQA_model, VQA_weights):
#         def __init__(self, layers):
# def read_image(image_file_name):
# def to_word(predict):
#     class _dummy(object):


import numpy as np
import time
from src.net import Net
from src.utils.visualqa import yield_weights, to_word
from src.utils.visualqa import glove_embed, read_image
from src.utils.visualqa import vgg16_model, lstm3_model, infer_model

'''
Model:

lstm x 3 -----\
                > concatenate -> (dense, tanh) x 3 -> (dense, softmax) -> answer
vgg16   ------/

From: https://github.com/iamaaditya/VQA_Demo
'''


# Path: src/net.py
# class Net(object):
#     # Sugar syntax
#     def __init__(self):
#         self._server = ParameterServer()
#         self._finalized = False
#         self._dagraph = DAG()
#         coated = sugar.__dict__
#         for name, fun in coated.items():
#             if callable(fun): setattr(Net, name, fun)
#  
#     # To be sugar coated
#     def _x(self, name, *args):
#         assert not self._finalized, \
#         'Graph is finalized by setting an optimizer'
#         return self._dagraph.register_for_slot(
#             name, self._server, *args)
# 
#     def optimize(self, ptr, optimizer,
#                  *args, **kwargs):
#         self._finalized = True
#         self._dagraph.set_closure(ptr)
#         self._server.set_optimizer(
#             optimizer, *args, **kwargs)
# 
#     def forward(self, fetches, feed):
#         return self._dagraph.forward(fetches, feed)
# 
#     def train(self, fetches, feed):
#         val = self._dagraph.forward_to_leaf(fetches, feed)
#         self._dagraph.backward()
#         self._server.apply_optimizer()
#         return val
# 
#     def save_checkpoint(self, file_name):
#         self._server.save(file_name)
# 
#     def load_checkpoint(self, file_name, *args, **kwargs):
#         self._server.load(file_name, *args, **kwargs)
# 
# Path: src/utils/visualqa.py
# def yield_weights(model):
#     for layer in model.layers:
#         weights = layer.get_weights()
#         if len(weights): 
#             weights = [
#                 w.astype(np.float64) 
#                 for w in weights]
#             yield(weights)
# 
# def to_word(predict):
#     label = np.argmax(predict)
#     return labelencoder.inverse_transform(label)
# 
# Path: src/utils/visualqa.py
# 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 read_image(image_file_name):
#     image_features = np.zeros((1, 4096))
#     im = cv2.resize(cv2.imread(image_file_name), (224, 224))
#     return im.astype(np.float64).copy(order = 'C')
# 
# Path: src/utils/visualqa.py
# def glove_embed(question):
# def get_image_model(CNN_weights_file_name):
# def get_VQA_model(VQA_model_file_name, VQA_weights_file_name):
# def yield_weights(model):
# def vqa_models(VQA_model, VQA_weights):
#         def __init__(self, layers):
# def read_image(image_file_name):
# def to_word(predict):
#     class _dummy(object):


# Path: visual-answer.py
import numpy as np
import time
from src.net import Net
from src.utils.visualqa import yield_weights, to_word
from src.utils.visualqa import glove_embed, read_image
from src.utils.visualqa import vgg16_model, lstm3_model, infer_model


'''
Model:

lstm x 3 -----\
                > concatenate -> (dense, tanh) x 3 -> (dense, softmax) -> answer
vgg16   ------/

From: https://github.com/iamaaditya/VQA_Demo
'''


vgg16_weights = yield_weights(vgg16_model)