Beispiel #1
0
def get_image_model(CNN_weights_file_name):
    
    from models.CNN.VGG import VGG_16
    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')
    return image_model
Beispiel #2
0
def get_image_model(CNN_weights_file_name):

    global image_model
    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')
    #image_model._make_predict_function()
    print ("Image model loaded!")
def get_image_model(CNN_weights_file_name):
    ''' Takes the CNN weights file, and returns the VGG model update 
    with the weights. Requires the file VGG.py inside models/CNN '''
    from models.CNN.VGG import VGG_16
    image_model = VGG_16(CNN_weights_file_name)

    # this is standard VGG 16 without the last two layers
    sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
    # one may experiment with "adam" optimizer, but the loss function for
    # this kind of task is pretty standard
    image_model.compile(optimizer=sgd, loss='categorical_crossentropy')
    return image_model
Beispiel #4
0
def get_image_model(CNN_weights_file_name):
    """
    Takes the CNN weights file, and returns the VGG model update
    with the weights. Requires the file VGG.py inside models/CNN

    :param CNN_weights_file_name: CNN weight file name (including path)
    :return: image CNN model
    """

    from models.CNN.VGG import VGG_16
    image_model = VGG_16(CNN_weights_file_name)

    # # Or use keras.application
    # from keras.applications.vgg16 import VGG16
    # image_model = VGG16(weights='imagenet', include_top=False)

    # this is standard VGG 16 without the last two layers
    sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
    # one may experiment with "adam" optimizer, but the loss function for
    # this kind of task is pretty standard
    image_model.compile(optimizer=sgd, loss='categorical_crossentropy')
    return image_model
Beispiel #5
0
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from keras import backend as K

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]