Ejemplo n.º 1
0
def get_VQA_model(VQA_weights_file_name):
    ''' Given the VQA model and its weights, compiles and returns the model '''

    from models.VQA.VQA import VQA_MODEL
    vqa_model = VQA_MODEL()
    vqa_model.load_weights(VQA_weights_file_name)

    vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
    return vqa_model
Ejemplo n.º 2
0
def get_VQA_model(VQA_weights_file_name):
    ''' Given the VQA model and its weights, compiles and returns the model '''
    from models.VQA.VQA import VQA_MODEL
    vqa_model = VQA_MODEL()
    vqa_model.load_weights(VQA_weights_file_name)
    vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
    return vqa_model
Ejemplo n.º 3
0
def get_VQA_model(VQA_weights_file_name):
    from models.VQA.VQA import VQA_MODEL
    vqa_model = VQA_MODEL()
    vqa_model.load_weights(VQA_weights_file_name)

    vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
    return vqa_model
Ejemplo n.º 4
0
def get_VQA_model(VQA_weights_file_name):
    
    global vqa_model
    vqa_model = VQA_MODEL()
    vqa_model.load_weights(VQA_weights_file_name)
    vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
    print ("VQA Model loaded!")
Ejemplo n.º 5
0
def get_VQA_model(VQA_weights_file_name):
    """
    Given the VQA model and its weights, compiles and returns the model

    :param VQA_weights_file_name: VQA model weight file (including path)
    :return: pre-trained VQA model
    """
    from models.VQA.VQA import VQA_MODEL
    vqa_model = VQA_MODEL()
    vqa_model.load_weights(VQA_weights_file_name)

    vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
    return vqa_model
Ejemplo n.º 6
0
K.set_image_data_format('channels_first')

from models.VQA.VQA import VQA_MODEL
from models.CNN.VGG import VGG_16

app = flask.Flask(__name__)

VQA_weights_file_name = '/input/models/VQA/VQA_MODEL_WEIGHTS.hdf5'
label_encoder_file_name = '/input/models/VQA/FULL_labelencoder_trainval.pkl'
CNN_weights_file_name = '/input/models/CNN/vgg16_weights.h5'

image_model = VGG_16(CNN_weights_file_name)
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
image_model.compile(optimizer=sgd, loss='categorical_crossentropy')
print("Image model loaded!")
vqa_model = VQA_MODEL()
vqa_model.load_weights(VQA_weights_file_name)
vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
print("VQA Model loaded!")


def get_image_features(image_file_name):

    image_features = np.zeros((1, 4096))
    im = cv2.resize(cv2.imread(image_file_name), (224, 224))
    #im = cv2.resize(image_file_name, (224, 224))
    mean_pixel = [103.939, 116.779, 123.68]
    im = im.astype(np.float32, copy=False)
    for c in range(3):
        im[:, :, c] = im[:, :, c] - mean_pixel[c]
    im = im.transpose((2, 0, 1))  # convert the image to RGBA