Пример #1
0
test_datagen = ImageDataGenerator(rescale=1. / 255)
single_validation_generator = test_datagen.flow_from_directory(
    valid_dir,
    target_size=(INPUT1_DIMS[1], INPUT1_DIMS[1]),
    batch_size=BS,
    class_mode='categorical')

CLASSES = single_train_generator.num_classes
params.num_labels = CLASSES

# initialize the model
print("[INFO] creating model...")
overwriting = os.path.exists(history_filename) and restore_from is None
assert not overwriting, "Weights found in model_dir, aborting to avoid overwrite"
loss_history = LossHistory(history_filename)
EPOCHS += loss_history.get_initial_epoch()

if LOSS_FN == 'center':
    loss_fn = get_center_loss(CENTER_LOSS_ALPHA, CLASSES)
elif LOSS_FN == 'softmax':
    loss_fn = get_softmax_loss()
else:
    loss_fn = get_total_loss(LAMBDA, CENTER_LOSS_ALPHA, CLASSES)

if restore_from is None:
    if model_name == 'densenet':
        model = DenseNetBaseModel(CLASSES, use_imagenet_weights).model
    elif model_name == "inception":
        model = Inceptionv3Model(CLASSES, use_imagenet_weights).model
    elif model_name == 'vgg':
        model = VGGModel(CLASSES, use_imagenet_weights).model
Пример #2
0
    parallelism=4)

x_batch_shape = x_train_batch.get_shape().as_list()
y_batch_shape = y_train_batch.get_shape().as_list()

x_train_input = Input(tensor=x_train_batch, batch_shape=x_batch_shape)
y_train_in_out = Input(tensor=y_train_batch,
                       batch_shape=y_batch_shape,
                       name='y_labels')

# initialize the model
print("[INFO] creating model...")
overwriting = os.path.exists(history_filename) and restore_from is None
assert not overwriting, "Weights found in model_dir, aborting to avoid overwrite"
loss_history = LossHistory(history_filename)
initial_epoch = loss_history.get_initial_epoch()
EPOCHS += initial_epoch
if restore_from is None:
    if model_name == 'base':
        model = DenseNetBaseModel(CLASSES, use_imagenet_weights).model
    elif model_name == 'inject':
        model = DenseNetInceptionConcat(
            num_labels=CLASSES,
            use_imagenet_weights=use_imagenet_weights).model
    else:
        model = DenseNetInception(input_shape=IMAGE_DIMS, params=params).model
else:
    # Restore Model
    file_path = os.path.join(restore_from, "best.weights.hdf5")
    assert os.path.exists(file_path), "No model in restore from directory"
    model = load_model(file_path)