Esempio n. 1
0
def run_cache():
    train_root = '%s/train' % cache_root
    test_root = '%s/test' % cache_root
    init_folders(train_root, test_root)
    _opt = load_globals(cache_root, globals(), override=True)
    _train_data_loader, _test_data_loader = init_loaders(_opt)
    save_dataset(train_root, num_train, _train_data_loader)
    save_dataset(test_root, num_test, _test_data_loader)
Esempio n. 2
0

def run_net(opt, _device, _net_path, _source, _target, _train_tag, _tag=''):
    net = init_nets(opt, _net_path, _device, _tag).eval()
    synthesized_paths = collect_synthesized(_source)
    image_suffixes = ['reconstructed_image', 'reconstructed_motif']
    for path in synthesized_paths:
        prefix, _ = os.path.splitext(os.path.split(path)[-1])
        prefix = prefix.split('_')[0]
        sy_np, sy_ts = load_image(path, _device, True)
        results = list(net(sy_ts))
        for idx, result in enumerate(results):
            results[idx] = transform_to_numpy_image(result)
        reconstructed_mask = results[1]
        reconstructed_motif = None
        if len(results) == 3:
            reconstructed_raw_motif = results[2]
            reconstructed_motif = (reconstructed_raw_motif - 1) * reconstructed_mask + 1
        reconstructed_image = reconstructed_mask * results[0] + (1 - reconstructed_mask) * sy_np
        for idx, image in enumerate([reconstructed_image, reconstructed_motif]):
            if image is not None and idx < len(image_suffixes):
                save_numpy_image(image, '%s_%s' % (image_suffixes[idx], _train_tag), _target, _source,
                                 prefix=prefix)
    print('done')


if __name__ == '__main__':
    _opt = load_globals(net_path, {}, override=False)
    init_folders(target_root)
    run_net(_opt, device, net_path, resources_root, target_root, train_tag, load_tag)
Esempio n. 3
0
def run_demo():
    download_data()
    init_folders(RECONSTRUCTED_PATH)
    opt = load_globals(ROOT_PATH, {}, override=False)
    run_net(opt, DEVICE, ROOT_PATH, TEST_PATH, RECONSTRUCTED_PATH, 'demo')
    print("Reconstructed images are at %s" % RECONSTRUCTED_PATH)