Exemplo n.º 1
0
def gen_func(images):
    return utils.balance(couples_generator(images))


train_couples_len = sum(1 for e in gen_func(images_train))
validation_couples_len = sum(1 for e in gen_func(images_validation))
test_couples_len = sum(1 for e in gen_func(images_test))

print('Training with %d couples.' % train_couples_len)
print('Validation with %d couples.' % validation_couples_len)
print('Testing with %d couples.' % test_couples_len)
print(input_shape)

data_gen = utils.get_ImageDataGenerator(all_images, input_shape)
train_iterator = utils.CouplesIterator(
    utils.make_infinite(gen_func, images_train), input_shape, data_gen,
    BATCH_SIZE)
validation_iterator = utils.CouplesIterator(
    utils.make_infinite(gen_func, images_validation), input_shape, data_gen,
    BATCH_SIZE)
test_iterator = utils.CouplesIterator(
    utils.make_infinite(gen_func, images_test), input_shape, data_gen,
    BATCH_SIZE)

model = network.create(input_shape, args.network)
network.compile(model, args.optimizer)

callbacks_list = [
    ModelCheckpoint('best_pretrain_model.hdf5',
                    monitor='val_accuracy',
                    verbose=1,
Exemplo n.º 2
0
    print(c.shape)
    return [f, c]


images_train = random.sample(all_image_names, int(len(all_image_names) * 0.9))
images_test = [i for i in all_image_names if i not in set(images_train)]


def couples_generator(images):
    for i in images:
        yield load_pair(i), labels[i]


def gen_func(images):
    return couples_generator(images)


train_couples_len = sum(1 for e in gen_func(images_train))
test_couples_len = sum(1 for e in gen_func(images_test))

data_gen = utils.get_ImageDataGenerator(all_images, input_shape)
train_iterator = utils.CouplesIterator(utils.make_infinite(gen_func, images_train), input_shape, data_gen, BATCH_SIZE)
test_iterator = utils.CouplesIterator(utils.make_infinite(gen_func, images_test), input_shape, data_gen, BATCH_SIZE)

model = network.create(input_shape, args.network)
network.compile(model, args.optimizer)

model.fit_generator(train_iterator, steps_per_epoch=train_couples_len / BATCH_SIZE, epochs=EPOCHS)
score = model.evaluate_generator(test_iterator, steps=test_couples_len / BATCH_SIZE)
print(score)
Exemplo n.º 3
0
        random.shuffle(images)
        for e in utils.balance(couples_generator(images)):
            yield e


train_couples_len = sum(
    1 for e in utils.balance(couples_generator(images_train)))
test_couples_len = sum(1
                       for e in utils.balance(couples_generator(images_test)))

print('Training with %d couples.' % train_couples_len)
print('Testing with %d couples.' % test_couples_len)
print(input_shape)

data_gen = utils.get_ImageDataGenerator(all_images, input_shape)
train_iterator = utils.CouplesIterator(inf_couples_generator(images_train),
                                       input_shape, data_gen, BATCH_SIZE)
test_iterator = utils.CouplesIterator(inf_couples_generator(images_test),
                                      input_shape, data_gen, BATCH_SIZE)

model = network.create(input_shape)
network.compile(model)

model.save('pretrain.h5')

model.fit_generator(train_iterator,
                    steps_per_epoch=train_couples_len / BATCH_SIZE,
                    epochs=EPOCHS)

model.save('pretrain.h5')

score = model.evaluate_generator(test_iterator,