Esempio n. 1
0

    os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu


    with open(args.topology, "r") as topology:
        num_filters = tuple(map(int, topology.readline()[1:-1].split(', ')))
    
    files = glob.glob(os.path.join(args.file_dir, "*.png"))

    input_shape = (None, None, 3)
   
    # Reconstruct model from saved weights
    model = Autoencoder(input_shape=input_shape, num_filters=num_filters)
    model = model.build()
    print(model.summary())

    model.load_weights(args.weights)
    model.compile(optimizer="adam", loss="MSE", metrics=["accuracy"])

    # Generate time stamp for unique id of the result
    time_stamp = "{date:%Y-%m-%d-%H-%M-%S}".format(date=datetime.datetime.now())

    # Pass images to network
    for file, i in zip(files, range(len(files))):

        inp_img = cv2.imread(file) / 255
        inp_img = np.expand_dims(inp_img, axis=0)

        out_img = model.predict(inp_img)
Esempio n. 2
0
trainX = np.reshape(trainX, (len(trainX), 64, 64, 3))
testX = np.reshape(testX, (len(testX), 64, 64, 3))

# Шумы
trainNoise = np.random.normal(loc=0.5, scale=0.5, size=trainX.shape)
testNoise = np.random.normal(loc=0.5, scale=0.5, size=testX.shape)
trainXNoisy = np.clip(trainX + trainNoise, 0, 1)
testXNoisy = np.clip(testX + testNoise, 0, 1)

print("[INFO] building autoencoder...")
opt = 'adadelta'

autoencoder = Autoencoder().build(IMAGE_HEIGHT, IMAGE_WIDTH, 3)
autoencoder.compile(loss="mse", optimizer=opt, metrics=["accuracy"])
autoencoder.summary()

H = autoencoder.fit(trainXNoisy,
                    trainX,
                    validation_data=(testXNoisy, testX),
                    epochs=EPOCHS,
                    batch_size=BS)

N = np.arange(0, EPOCHS)
plt.style.use("ggplot")
plt.figure()
plt.plot(N, H.history["loss"], label="train_loss")
plt.plot(N, H.history["val_loss"], label="val_loss")
plt.title("Training Loss and Accuracy")
plt.xlabel("Epoch")
plt.ylabel("Loss/Accuracy")