Beispiel #1
0
def train():
    # setting up, options contains all our params
    options = Options(
        library=0,  # use keras
        configs=2,  # use resnet50 model
        transform=1)  # use transform for resnet50

    # initialize model
    model = options.FlowerClassificationModel(options)

    # fit model
    model.fit()
def train():
    # setting up, options contains all our params
    options = Options(
        library=0,  # use keras
        configs=2,  # use resnet50 model
        transform=1)  # use transform for resnet50

    # set options to your specific experiment
    options.experiment = "fine_tuned_oxford102_model_dropout"
    options.dropout = 0.1
    options.number = options.dropout

    # settings
    options.gpu = 2
    options.save_test_result = True

    # early stopping
    options.early_stopping = True
    options.patience = 20

    # general hyperparameters
    options.lr = 1E-2
    options.batch_size = 128

    # reduce lr on plateau
    options.reduce_lr = 0.5

    for i in range(0, 9):

        # initialize model
        model = options.FlowerClassificationModel(options)

        # fit model
        model.fit()

        # evaluate model
        model.evaluate()

        # reset model for next parameter
        model.reset()

        # change dropout from 0.1 to 0.9
        options.dropout += 0.1

        # change the log number saved to checkpoints
        options.number = options.dropout
Beispiel #3
0
def eval():
    # setting up, options contains all our params
    options = Options(
        library=0,  # use keras
        configs=2,  # use resnet50 model
        transform=1)  # use transform for resnet50

    # set options to the specific experiment you are testing on
    # options.gpu = 1
    options.test_batch_size = 84  # since there are 336 test examples

    # load the weight file
    options.load = True
    options.load_file = './checkpoints/2017-10-02_experiment_0/model_best_weights.h5'

    # initialize model
    model = options.FlowerClassificationModel(options)

    # fit model
    model.evaluate()
Beispiel #4
0
    image = tf.cast(image, dtype=tf.float32)

    # setting up, options contains all our params
    options = Options(
        library=0,  # use keras
        configs=2,  # use resnet50 model
        transform=1)  # use transform for resnet50

    # load the weight file
    options.load = True
    options.load_file = osp.join(args.model_dir, args.trained_model)

    input_tensor = preprocess_input(image)

    # initialize model
    model = options.FlowerClassificationModel(options,
                                              input_tensor=input_tensor)

    my_model = model.model

    keys_placeholder = tf.placeholder(tf.string, shape=[None])
    inputs = {'key': keys_placeholder, 'image_bytes': image_str_tensor}

    # To extract the id, we need to add the identity function.
    keys = tf.identity(keys_placeholder)
    outputs = {
        'key': keys,
        'prediction': my_model.output,
    }

    signature_def = build_signature(inputs=inputs, outputs=outputs)
    signature_def_map = {