Ejemplo n.º 1
0
filepath = os.path.join(data_output, "checkpoints",
                        "weights-improvement-{epoch:02d}-{PSNR:.2f}.hdf5")
checkpoint = ModelCheckpoint(filepath, monitor=PSNR, verbose=1, mode='max')
callbacks_list = [checkpoint]

model.fit(X, y, epochs=EPOCHS,
          validation_split=0.20,
          batch_size=BATCH_SIZE, callbacks=callbacks_list, shuffle="batch")

print("Done training!!!")
print("Saving the final model ...")

model.save(os.path.join(data_output,"fsrcnn_Sat-6_Epoch{}_VIS2NIR.h5".format(EPOCHS)))  # creates a HDF5 file

y_pred = model.predict(x_true)
n = y_true.shape[0]
mses  = 0
rmses = 0
psnrs = 0
ssims = 0
for i in range(0,n):
    print("Testing {}/{}...".format(i,n))
    y = y_true[i,:,:,0]
    y_prime = y_pred[i,:,:,0]
    mses  = mses  +  mse(y, y_prime)
    rmses = rmses + rmse(y, y_prime)
    psnrs = psnrs + psnr(y, y_prime, data_range=y_prime.max() - y_prime.min())
    ssims = ssims + ssim(y, y_prime, data_range=y_prime.max() - y_prime.min())
mses  =  mses / n
rmses = rmses / n
Ejemplo n.º 2
0
    batch_psnr = []
    for row in range(0, rows):
        for col in range(0, cols):
            x = col * stride
            y = row * stride
            # Getting patches...
            patch = raw[x:x + stride, y:y + stride]
            scale = Image.fromarray(patch, 'L')
            scale = scale.resize((ratio, ratio), Image.BICUBIC)
            scale = np.array(scale)

            x_true = scale / 255.
            y_true = patch / 255.
            x_prime = np.expand_dims(x_true, axis=2)
            x_prime = np.expand_dims(x_prime, axis=0)
            y_pred = model.predict(x_prime)
            y_pred = y_pred[0, :, :, 0]
            mse = np.mean((y_true - y_pred)**2)
            batch_mse.append(mse)
            psnr = 20 * np.log10(1 / np.sqrt(mse))
            batch_psnr.append(psnr)
            ssim = SSIM(y_true, y_pred)
            batch_ssim.append(ssim)
            #print("Count={} Image={} MSE={} SSIM={} PSNR={}".format(count, filename, mse, ssim, psnr))

            out[x:x + stride, y:y + stride] = (y_pred * 255).astype(np.uint8)
            plt.subplot(131)
            plt.imshow(x_true, cmap='Greys')
            plt.subplot(132)
            plt.imshow(y_true, cmap='Greys')
            plt.subplot(133)