Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: __init__() missing 1 required positional argument: 'dataset_path' #19

Open
mtk380 opened this issue Aug 12, 2021 · 1 comment

Comments

@mtk380
Copy link

mtk380 commented Aug 12, 2021

when i train the script, this problem occur when running the fid_evaluation.setup_evaluation (Progress to next stage: 2%|▊ | 5000/200000 )

Traceback (most recent call last):
  File "/home/ubuntu541/anaconda3/envs/pigan/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 59, in _wrap
    fn(i, *args)
  File "/home/ubuntu541/yhj_lsp/nerf/pi-GAN-master(1)/pi-GAN-master/train.py", line 362, in train
    fid_evaluation.setup_evaluation(metadata['dataset'], generated_dir, target_size=128)
  File "/home/ubuntu541/yhj_lsp/nerf/pi-GAN-master(1)/pi-GAN-master/fid_evaluation.py", line 37, in setup_evaluation
    dataloader, CHANNELS = datasets.get_dataset(dataset_name, img_size=target_size)
  File "/home/ubuntu541/yhj_lsp/nerf/pi-GAN-master(1)/pi-GAN-master/datasets.py", line 79, in get_dataset
    dataset = globals()[name](**kwargs)
TypeError: __init__() missing 1 required positional argument: 'dataset_path'
@JinWonjoon
Copy link

Hi mtk380!
I got the same error with you, and tried to fix it.
The error was caused because metadata (kwargs) about dataset_path is not delivered to the dataloader.

So, in fid_evaluation.py (maybe line 32)

def setup_evaluation(dataset_name, generated_dir, data_path, target_size=128, num_imgs=8000):  # add data_path
    # Only make real images if they haven't been made yet
    real_dir = os.path.join('EvalImages', dataset_name + '_real_images_' + str(target_size))
    if not os.path.exists(real_dir):
        os.makedirs(real_dir)
        dataloader, CHANNELS = datasets.get_dataset(dataset_name, img_size=target_size, dataset_path=data_path) # add dataset_path
        print('outputting real images...')
        output_real_images(dataloader, num_imgs, real_dir)
        print('...done')

    if generated_dir is not None:
        os.makedirs(generated_dir, exist_ok=True)
    return real_dir

and, in train.py (maybe near line 366)

if opt.eval_freq > 0 and (discriminator.step + 1) % opt.eval_freq == 0:
    generated_dir = os.path.join(opt.output_dir, 'evaluation/generated')

    if rank == 0:
        fid_evaluation.setup_evaluation(metadata['dataset'], generated_dir, data_path=metadata["dataset_path"], target_size=128) # add data_path
    dist.barrier()
    ema.store(generator_ddp.parameters())
    ema.copy_to(generator_ddp.parameters())
    generator_ddp.eval()
    fid_evaluation.output_images(generator_ddp, metadata, rank, world_size, generated_dir)
    ema.restore(generator_ddp.parameters())
    dist.barrier()
    if rank == 0:
        fid = fid_evaluation.calculate_fid(metadata['dataset'], generated_dir, target_size=128)
        with open(os.path.join(opt.output_dir, f'fid.txt'), 'a') as f:
            f.write(f'\n{discriminator.step}:{fid}')

    torch.cuda.empty_cache()

In my case, it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants