コード例 #1
0
parser.add_argument("--scale", type=int, help="downscale factor")
parser.add_argument("--output_dir", type=str, help="path to store results")
parser.add_argument("--benchmark",
                    type=bool,
                    default=True,
                    help="report benchmark results")
args = parser.parse_args()

SCALE = args.scale
KSIZE = 3 * SCALE + 1
OFFSET_UNIT = SCALE
BENCHMARK = args.benchmark

kernel_generation_net = DSN(k_size=KSIZE, scale=SCALE).cuda()
downsampler_net = Downsampler(SCALE, KSIZE).cuda()
upscale_net = EDSR(32, 256, scale=SCALE).cuda()

kernel_generation_net = nn.DataParallel(kernel_generation_net, [0])
downsampler_net = nn.DataParallel(downsampler_net, [0])
upscale_net = nn.DataParallel(upscale_net, [0])

kernel_generation_net.load_state_dict(
    torch.load(os.path.join(args.model_dir, "{0}x".format(SCALE), "kgn.pth")))
upscale_net.load_state_dict(
    torch.load(os.path.join(args.model_dir, "{0}x".format(SCALE), "usn.pth")))
torch.set_grad_enabled(False)


def validation(img, name, save_imgs=False, save_dir=None):
    kernel_generation_net.eval()
    downsampler_net.eval()
                    model = MSRN(upscale=opt.scale).cuda()
                    model = torch.nn.DataParallel(model).cuda()
                    criterion = nn.L1Loss()

                elif opt.choose_net == "MSRN_blanced_attention":
                    model = MSRN_blanced_attention(upscale=opt.scale).cuda()
                    model = torch.nn.DataParallel(model).cuda()
                    criterion = nn.L1Loss()

                elif opt.choose_net == "EDSR_blanced_attention":
                    model = EDSR_blanced_attention(opt).cuda()
                    model = torch.nn.DataParallel(model).cuda()
                    criterion = nn.L1Loss()

                elif opt.choose_net == "EDSR":
                    model = EDSR(opt).cuda()
                    model = torch.nn.DataParallel(model).cuda()
                    criterion = nn.L1Loss()

                elif opt.choose_net == "AWSRN_blanced_attention":
                    model = AWSRN_blanced_attention(opt).cuda()
                    model = torch.nn.DataParallel(model).cuda()
                    criterion = nn.L1Loss()

                elif opt.choose_net == "MDSR":
                    model = MDSR(scale=opt.scale).to(device)
                    model = torch.nn.DataParallel(model).cuda()
                    criterion = nn.L1Loss()
                elif opt.choose_net == "MDSR_blanced_attention":
                    model = MDSR_blanced_attention(scale=opt.scale).cuda()
                    model = torch.nn.DataParallel(model).cuda()