コード例 #1
0
inputs = Input(shape=(256, 256, 3))
transform_net = TransformNet(inputs, options.conv_filters, options.num_resids)
model = Model(inputs=inputs, outputs=transform_net)
loss_fn = create_loss_fn(style_target, options.content_weight,
                         options.style_weight, options.tv_weight,
                         options.batch_size)
model.compile(optimizer='adam', loss=loss_fn)

if options.model_input:
    model.load_weights(options.model_input)

gen = create_gen(options.train_path,
                 target_size=(256, 256),
                 batch_size=options.batch_size)

if options.steps_per_epoch is None:
    num_samples = count_num_samples(options.train_path)
    options.steps_per_epoch = num_samples // options.batch_size

callbacks = None
if options.test:
    callbacks = [
        OutputPreview(options.test, options.test_increment, options.test_dir)
    ]
model.fit_generator(gen,
                    steps_per_epoch=options.steps_per_epoch,
                    epochs=options.epochs,
                    callbacks=callbacks)
model.save(options.model_output)
コード例 #2
0
        self.increment = increment
        self.iteration = 0

    def on_batch_end(self, batch, logs={}):
        if (self.iteration % self.increment == 0):
            output_img = self.model.predict(self.test_img)[0]
            fname = '%d.jpg' % self.iteration
            out_path = os.path.join(self.preview_dir_path, fname)
            imsave(out_path, output_img)

        self.iteration += 1


gen = create_gen(TRAIN_PATH, TARGET_SIZE, BATCH_SIZE)

num_samples = count_num_samples(TRAIN_PATH)
steps_per_epoch = num_samples // BATCH_SIZE

target_layer = 1

encoder_decoder = EncoderDecoder(target_layer=target_layer)

callbacks = [
    OutputPreview(
        encoder_decoder,
        r'C:\Users\MillerV\Documents\Masters CS\Machine-Learning-Group\advancedML\lab2\monkey.jpg',
        5000, './preview-%d' % target_layer)
]
encoder_decoder.model.fit_generator(gen,
                                    steps_per_epoch=steps_per_epoch,
                                    epochs=epochs,