net = SRResnet(lr=learning_rate)
net.visualize()
net.get_model().summary()

img = cv2.imread('div2k_test.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
r = DATA.patch_size - img.shape[0] % DATA.patch_size
c = DATA.patch_size - img.shape[1] % DATA.patch_size
img = np.pad(img, [(0, r), (0, c), (0, 0)], 'constant')
Image.fromarray(img).save("div2k_padded_test.png")
lr_img = cv2.resize(img, (int(img.shape[1] / 2), int(img.shape[0] / 2)),
                    cv2.INTER_CUBIC)
Image.fromarray(lr_img).save("div2k_padded_test_lr.png")

p, r, c = DATA.patchify(lr_img, scale=2)

for i in range(chk + 1, tryout):
    print("tryout no: ", i)

    samplev = np.random.random_integers(0,
                                        DATA.training_patches_2x.shape[0] - 1,
                                        sample)
    net.fit(DATA.training_patches_2x[samplev],
            DATA.training_patches_Y[samplev], batch_size, epochs)

    net.get_model().save_weights('model_iter' + str(i) + '.h5')
    g = net.get_model().predict(np.array(p))
    gen = DATA.reconstruct(g, r, c, scale=1)
    gen[gen > 255] = 255
    gen[gen < 0] = 0
Ejemplo n.º 2
0
        exit()

    R = DATA.patch_size - img.shape[0] % DATA.patch_size
    C = DATA.patch_size - img.shape[1] % DATA.patch_size
    img = np.pad(img, [(0, R), (0, C), (0, 0)], 'constant')
    Image.fromarray(img).save("test_image_padded.png")
    lr_img = cv2.resize(img,
                        (int(img.shape[1] / scale), int(img.shape[0] / scale)),
                        cv2.INTER_CUBIC)
    Image.fromarray(lr_img).save("test_" + str(scale) + "x_lr_padded.png")
    hr_img_bi = cv2.resize(lr_img, (int(img.shape[1]), int(img.shape[0])),
                           cv2.INTER_CUBIC)
    Image.fromarray(hr_img_bi).save("test_" + str(scale) +
                                    "x_hr_bicubic_padded.png")

    p, r, c = DATA.patchify(lr_img, scale=scale)

    if not test_only:
        for i in range(chk + 1, tryout):
            print("tryout no: ", i)

            samplev = np.random.random_integers(0, x.shape[0] - 1, sample)

            net.fit(x[samplev], y[samplev], batch_size, epochs)

            net.get_model().save_weights('model_' + str(scale) + 'x_iter' +
                                         str(i) + '.h5')
            g = net.get_model().predict(np.array(p))
            gen = DATA.reconstruct(g, r, c, scale=1)
            Image.fromarray(gen).save("test_" + str(scale) + "x_gen_" +
                                      str(i) + ".png")
Ejemplo n.º 3
0
    net = SRResnet(lr=learning_rate, scale=scale, chk=chk)
    if not test_only:
        net.visualize()
        net.get_model().summary()

# Temp stuff for barcode #####
    os.mkdir('bargen')
    loc = '/home/sanchit/Barcodes/HR/detected_barcodes'
    for f in os.listdir(loc):
        if not os.path.isdir(f):
            filename = loc + '/' + f
            img = cv2.imread(filename)
            r = 32 - img.shape[0] % 32
            c = 32 - img.shape[1] % 32
            img = np.pad(img, [(0, r), (0, c), (0, 0)], 'constant')
            gz, r2, c2 = DATA.patchify(img, scale=scale)
            gz = net.get_model().predict(np.array(gz))
            genz = DATA.reconstruct(gz, r2, c2, scale=1)
            Image.fromarray(genz).save('bargen/' + f)

    image_name = values.test_image

    try:
        img = cv2.imread(image_name)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    except cv2.error as e:
        print("Bad image path check the name or path !!")
        exit()

    if not zoom:
        r = DATA.patch_size - img.shape[0] % DATA.patch_size
Ejemplo n.º 4
0
        lr_2x_img = cv2.resize(img,
                               (int(img.shape[1] / 2), int(img.shape[0] / 2)),
                               cv2.INTER_CUBIC)
        Image.fromarray(lr_2x_img).save("test_2x_lr_padded.png")

        lr_4x_img = cv2.resize(img,
                               (int(img.shape[1] / 4), int(img.shape[0] / 4)),
                               cv2.INTER_CUBIC)
        Image.fromarray(lr_4x_img).save("test_4x_lr_padded.png")

        lr_8x_img = cv2.resize(img,
                               (int(img.shape[1] / 8), int(img.shape[0] / 8)),
                               cv2.INTER_CUBIC)
        Image.fromarray(lr_8x_img).save("test_8x_lr_padded.png")

        p, r, c = DATA.patchify(lr_8x_img, scale=8)

        if not os.path.isdir('Results'):
            os.mkdir('Results')

    if not test_only:

        for i in range(chk + 1, tryout):
            gen_acc = 0.0
            dic_acc = 0.0
            print("tryout no: ", i)

            # samplev = np.random.random_integers(0 , x.shape[0]-1 , sample)

            if adv_lambda > 0.0:
                net.fit_discriminator(x, x2, x4, x8, batch_size, epoch=epochs)