Пример #1
0
opt.batchSize = 1  # test code only supports batchSize = 1
opt.serial_batches = True  # no shuffle
opt.no_flip = True  # no flip

data_loader = DataLoader(opt)
dataset = data_loader.load_data()
model = CycleGANModel()
model.initialize(opt)
visualizer = Visualizer(opt)

if __name__ == '__main__':
    root_dir = os.path.join(opt.result_root_dir, opt.variable)
    web_dir = os.path.join(root_dir, opt.variable_value, opt.phase)
    webpage = html.HTML(web_dir,
                        'Experiment = GAN2C, Phase = test, Epoch = latest')
    # test
    for i, data in enumerate(dataset):
        model.set_input(data)
        model.test()
        visuals = model.get_current_visuals()

        img_path = model.get_image_paths()
        print('process image... %s' % img_path)
        visualizer.save_images(webpage, visuals, img_path)

        short_path = ntpath.basename(''.join(img_path))
        test_depth_errors = model.get_depth_errors()
        visualizer.test_depth_errors(i + 1, short_path, test_depth_errors)

    webpage.save()
Пример #2
0
    print('creating web directory', web_dir)
    webpage = html.HTML(
        web_dir, 'Experiment = %s, Phase = %s, Epoch = %s' %
        (opt.name, opt.phase, opt.epoch))
    #if opt.eval:
    # model.eval()
    for i, data in enumerate(dataset):
        if i > 10:
            exit()
        #if i >= opt.num_test:  # only apply our model to opt.num_test images.
        # break
        #model.set_input(data)  # unpack data from data loader
        #model.test()         # run inference

        teacher.set_input(data)
        teacher.test()
        model.set_input(
            data)  # unpack data from dataset and apply preprocessing
        model.optimize_parameters()

        model.compute_visuals()
        visuals = model.get_current_visuals()  # get image results
        img_path = model.get_image_paths()  # get image paths
        print(img_path)
        #save_images(webpage, visuals, img_path)

        #visuals = model.get_current_visuals()  # get image results
        #img_path = model.get_image_paths()     # get image paths
        #if i % 5 == 0:  # save images to an HTML file
        #  print('processing (%04d)-th image... %s' % (i, img_path))
    # save_images(webpage, visuals, img_path, aspect_ratio=opt.aspect_ratio, width=opt.display_winsize)
Пример #3
0
    opt.batch_size = 1  # test code only supports batch_size = 1
    opt.serial_batches = True  # disable data shuffling; comment this line if results on randomly chosen images are needed.
    opt.no_flip = True  # no flip; comment this line if results on flipped images are needed.
    dataset = create_dataset(
        opt)  # create a dataset given opt.dataset_mode and other options
    model = CycleGANModel(
        opt)  # create a model given opt.model and other options
    model.setup(
        opt)  # regular setup: load and print networks; create schedulers
    # create results dir
    image_dir = create_results_dir(opt)
    # test with eval mode. This only affects layers like batchnorm and dropout.
    # For [CycleGAN]: It should not affect CycleGAN as CycleGAN uses instancenorm without dropout.
    if opt.eval:
        model.eval()
    for i, data in enumerate(dataset):
        if i >= opt.num_test:  # only apply our model to opt.num_test images.
            break
        model.set_input(data)  # unpack data from data loader
        model.test()  # run inference
        visuals = model.get_current_visuals()  # get image results
        img_path = model.get_image_paths()  # get image paths
        if i % 5 == 0:  # save images to an HTML file
            print('processing (%04d)-th image... %s' % (i, img_path))
        save_images(opt,
                    image_dir,
                    visuals,
                    img_path,
                    aspect_ratio=opt.aspect_ratio,
                    width=opt.display_winsize)