示例#1
0
文件: utils.py 项目: skylooop/GANs
def plot_examples(low_res_folder, gen):
    files = os.listdir(low_res_folder)

    gen.eval()
    for file in files:
        image = Image.open("Data/LR/" + file)
        with torch.no_grad():
            upscaled_img = gen(
                config.test_transform(
                    image=np.asarray(image))["image"].unsqueeze(0).to(
                        config.DEVICE))
        save_image(upscaled_img * 0.5 + 0.5, f"Data/saved/{file}")
    gen.train()
示例#2
0
def plot_examples(low_res_folder, gen):
    files = os.listdir(low_res_folder)

    gen.eval()  # 测试模式
    for file in files:
        print(file)
        image = Image.open(os.path.join(low_res_folder, file))
        with torch.no_grad():
            upscaled_img = gen(
                config.test_transform(
                    image=np.asarray(image))["image"].unsqueeze(0).to(
                        config.DEVICE))
        save_image(upscaled_img, f"saved_images/{file}")
    gen.train()  # 训练模式
示例#3
0
def save_examples(low_res_dir, gen):
    files = os.listdir(low_res_dir)

    gen.eval()

    for file in files:
        image = Image.open(os.path.join(low_res_dir, file))
        with torch.no_grad():
            upscaled_img = gen(
                config.test_transform(
                    image=np.asarray(image))["image"].unsqueeze(0).to(
                        config.DEVICE))

        save_image(upscaled_img * 0.5 + 0.5, f"saved_images/{file}")

    gen.train()