Пример #1
0
    string = f.read()
    model = load_model(model_path)
    model.compile("adadelta", dummy_loss)

    model.load_weights(weights_path)

size_multiple = 4 if len(
    model.layers
) == 69 else 8  # 69 layers in shallow model, 73 in deeper model

img = img_utils.preprocess_image(content_path,
                                 load_dims=True,
                                 resize=True,
                                 img_width=-1,
                                 img_height=-1,
                                 size_multiple=size_multiple)
img /= 255.
width, height = img.shape[2], img.shape[3]

t1 = time.time()
output = model.predict_on_batch(img)
t2 = time.time()

print("Saved image : %s" % output_image)
print("Prediction time : %0.2f seconds" % (t2 - t1))

img = output[0, :, :, :]
img = img_utils.deprocess_image(img)

img_utils.save_result(img, output_image, width, height)
                    validation_fastnet.create_model(validation_path=path)
                    validation_fastnet.model.compile(optimizer, dummy_loss)
                else:
                    validation_fastnet.model.load_weights(path)

                y_pred = validation_fastnet.fastnet_predict(x)

                y_pred = y_pred[0, :, :, :]
                y_pred = y_pred.transpose((1, 2, 0))

                print("Mean per channel : ", np.mean(y_pred, axis=(0, 1)))

                y_pred = np.clip(y_pred, 0, 255).astype('uint8')

                path = "val_epoch_%d_at_iteration_%d.png" % (i + 1, iteration)
                img_utils.save_result(y_pred, path, directory="val_imgs/")

                path = "val_imgs/" + path
                print("Validation image saved at : %s" % path)

            if iteration >= num_iter:
                break

        except KeyboardInterrupt:
            print("Keyboard interrupt detected. Stopping early.")
            early_stop = True
            break

    iteration = 0

    if early_stop: