示例#1
0
    def on_epoch_end(self, val_loss=None, logs=None):
        # save model
        global num_epoch
        global dataset_name
        global img_rows
        global img_cols
        global mbllen
        num_epoch += 1
        modelname = './models/' + str(num_epoch) + '_' + dataset_name + '_base.h5'
        mbllen.save_weights(modelname)

        # test val data
        path = glob('../dataset/test/*.jpg')
        number = 0
        psnr_ave = 0

        for i in range(len(path)):
            if i>15:
                break

            img_B_path = path[i]
            img_B = utls.imread_color(img_B_path)

            path_mid = os.path.split(img_B_path)
            path_A_1 = path_mid[0] + '_' + dataset_name
            path_A = os.path.join(path_A_1, path_mid[1])
            img_A = utls.imread_color(path_A)

            nw = random.randint(0, img_A.shape[0] - img_rows)
            nh = random.randint(0, img_A.shape[1] - img_cols)

            crop_img_A = img_A[nw:nw + img_rows, nh:nh + img_cols, :]
            crop_img_B = img_B[nw:nw + img_rows, nh:nh + img_cols, :]

            crop_img_A = crop_img_A[np.newaxis, :]
            crop_img_B = crop_img_B[np.newaxis, :]

            fake_B = mbllen.predict(crop_img_A)
            identy_B = mbllen.predict(crop_img_B)

            out_img = np.concatenate([crop_img_A, fake_B, crop_img_B, identy_B], axis=2)
            out_img = out_img[0, :, :, :]

            fake_B = fake_B[0, :, :, :]
            img_B = crop_img_B[0, :, :, :]

            clean_psnr = utls.psnr_cau(fake_B, img_B)
            L_psnr = ("%.4f" % clean_psnr)

            number += 1
            psnr_ave += clean_psnr

            filename = os.path.basename(path[i])
            img_name = './val_images/' + str(num_epoch) + '_' + L_psnr + '_' + filename
            utls.imwrite(img_name, out_img)
        psnr_ave /= number
        print('------------------------------------------------')
        print("[Epoch %d]  [PSNR_AVE :%f]" % (num_epoch,  psnr_ave))
        print('------------------------------------------------')
示例#2
0
文件: test.py 项目: smituk/MBLLEN
path = glob(input_folder+'/*.*')

model_name = arg.model
mbllen = Network.build_mbllen((None, None, 3))
mbllen.load_weights('../models/'+model_name+'.h5')
opt = keras.optimizers.Adam(lr=2 * 1e-04, beta_1=0.9, beta_2=0.999, epsilon=1e-08)
mbllen.compile(loss='mse', optimizer=opt)

flag = arg.com
lowpercent = arg.lowpercent
highpercent = arg.highpercent
maxrange = arg.maxrange/10.
hsvgamma = arg.gamma/10.
for i in range(len(path)):
    img_A_path = path[i]
    img_A = utls.imread_color(img_A_path)
    img_A = img_A[np.newaxis, :]

    starttime = time.clock()
    out_pred = mbllen.predict(img_A)
    endtime = time.clock()
    print('The ' + str(i+1)+'th image\'s Time:' +str(endtime-starttime)+'s.')
    fake_B = out_pred[0, :, :, :3]
    fake_B_o = fake_B

    gray_fake_B = fake_B[:, :, 0] * 0.299 + fake_B[:, :, 1] * 0.587 + fake_B[:, :, 1] * 0.114
    percent_max = sum(sum(gray_fake_B >= maxrange))/sum(sum(gray_fake_B <= 1.0))
    # print(percent_max)
    max_value = np.percentile(gray_fake_B[:], highpercent)
    if percent_max < (100-highpercent)/100.:
        scale = maxrange / max_value