mit-han-lab / gan-compression

[CVPR 2020] GAN Compression: Efficient Architectures for Interactive Conditional GANs
Other
1.1k stars 148 forks source link

get_real_stat.py error #35

Closed ghost closed 4 years ago

ghost commented 4 years ago

@lmxyy i am trying everything from scratch, when running get_real_stat.py i get an error. why does it require creating a val folder? there is already valA and valB

(gan) home@home-lnx:~/programs/level 2/gan-compression$ python get_real_stat.py --dataroot database/horse2zebra/ --output_path real_stat/horse2zebra_B.npz --direction AtoB
Traceback (most recent call last):
  File "get_real_stat.py", line 84, in <module>
    main(opt)
  File "get_real_stat.py", line 15, in main
    dataloader = create_dataloader(opt)
  File "/home/home/programs/level 2/gan-compression/data/__init__.py", line 45, in create_dataloader
    dataloader = CustomDatasetDataLoader(opt, verbose)
  File "/home/home/programs/level 2/gan-compression/data/__init__.py", line 97, in __init__
    self.dataset = dataset_class(opt)
  File "/home/home/programs/level 2/gan-compression/data/aligned_dataset.py", line 24, in __init__
    self.AB_paths = sorted(make_dataset(self.dir_AB))  # get image paths
  File "/home/home/programs/level 2/gan-compression/data/image_folder.py", line 45, in make_dataset
    assert os.path.isdir(dir) or os.path.islink(dir), '%s is not a valid directory' % dir
AssertionError: database/horse2zebra/val is not a valid directory
(gan) home@home-lnx:~/programs/level 2/gan-compression/database/horse2zebra$ tree -d
.
├── testA
├── testB
├── trainA
├── trainB
├── valA -> testA
└── valB -> testB
lmxyy commented 4 years ago

For the horse2zebra, we do not have aligned data. So you may need to specify the dataset mode with an additional argument --dataset_mode single. The whole command may be like this

python get_real_stat.py --dataroot database/horse2zebra/valB --output_path real_stat/horse2zebra_B.npz --direction AtoB --dataset_mode single
ghost commented 4 years ago

by aligned data you mean each input image have it's own output image? if so, then i have an aligned data, should i use --dataset_mode aligned? How can i prepare and train a dataset that have for each image it's own output image?

lmxyy commented 4 years ago

We follow the dataset structure of junyanz/pytorch-CycleGAN-and-pix2pix.

The aligned dataset means each input image have an explicit target output image just like pix2pix. So if you need to prepare it, just specify the dataset_mode as aligned. For example, for the edges2shoe-r dataset

python get_real_stat.py \
--dataroot database/edges2shoes-r \
--output_path real_stat/edges2shoes-r_B.npz \
--direction AtoB

For the unaligned dataset, which means the input image doesn't have an explicit target image, just like horse2zebra. You could use the command I mentioned above. (dataset mode single means only contains the horse images or the zebra images, since you only need to compute the FID stat for only one side)

There's also an option --dataset_mode option for training. Just make it consistent.

ghost commented 4 years ago

i will test the aligned mode after i finish from the single mode, so keep this issue open. but mean-while, for the Select the Best Model step, by default it chooses latest_net_G.pth, whil according to the log.txt from the previous step "Once-for-all" Network Training, the fid_largest is at epoch 260 / 400. should i set it to --restore_G_path logs/cycle_gan/horse2zebra_lite/supernet/checkpoints/260_net_G.pth?

lmxyy commented 4 years ago

Of course you could. In our experiment, we use the lastest checkpoint, which means the last one.

ghost commented 4 years ago

The single mode is working great, i was able to search and find a good model within 3 hours, for horse2zebra.

Now i want to train using the facades dataset which is aligned, i get the same error as before:

python get_real_stat.py --dataset_mode aligned --dataroot database/facades/ --output_path real_stat/facades_B.npz --direction AtoB
Traceback (most recent call last):
  File "get_real_stat.py", line 84, in <module>
    main(opt)
  File "get_real_stat.py", line 15, in main
    dataloader = create_dataloader(opt)
  File "/home/home/programs/level 2/gan-compression/data/__init__.py", line 45, in create_dataloader
    dataloader = CustomDatasetDataLoader(opt, verbose)
  File "/home/home/programs/level 2/gan-compression/data/__init__.py", line 97, in __init__
    self.dataset = dataset_class(opt)
  File "/home/home/programs/level 2/gan-compression/data/aligned_dataset.py", line 24, in __init__
    self.AB_paths = sorted(make_dataset(self.dir_AB))  # get image paths
  File "/home/home/programs/level 2/gan-compression/data/image_folder.py", line 45, in make_dataset
    assert os.path.isdir(dir) or os.path.islink(dir), '%s is not a valid directory' % dir
AssertionError: database/facades/val is not a valid directory
lmxyy commented 4 years ago

Could you please provide the directory structure of database/facades? Does the directory database/facades/val exist? If not, you could create it with a symlink

cd database/facades/
ln -s test val
ghost commented 4 years ago

The facades dataset have valA and valB, how to solve

home@home-lnx:~/programs/level 2/gan-compression$ bash datasets/download_cyclegan_dataset.sh facades
home@home-lnx:~/programs/level 2/gan-compression$ cd database/facades/
home@home-lnx:~/programs/level 2/gan-compression/database/facades$ tree -d
.
├── testA
├── testB
├── trainA
├── trainB
├── valA -> testA
└── valB -> testB
lmxyy commented 4 years ago

Oh, you have downloaded the unaligned version of the dataset (since you used datasets/download_cyclegan_dataset.sh). Just download the dataset in this way

bash datasets/download_pix2pix_dataset.sh facades
ghost commented 4 years ago

So i donwloaded the pix2pix version of facades as you suggested, and i was able to create the real_stat files.

Are you sure that i can train cyclegan using aligned dataset, because i get an error:

train.py --dataroot database/facades --dataset_mode aligned --model cycle_gan --netG resnet_9blocks --log_dir logs/cycle_gan/facades/full --real_stat_A_path real_stat/facades_A.npz --real_stat_B_path real_stat/facades_B.npz
dataset [AlignedDataset] was created
The number of training images = 400
Traceback (most recent call last):
  File "train.py", line 4, in <module>
    trainer = Trainer('train')
  File "/home/home/programs/level 2/gan-compression/trainer.py", line 51, in __init__
    model = create_model(opt)  # create a model given opt.model and other options
  File "/home/home/programs/level 2/gan-compression/models/__init__.py", line 47, in create_model
    instance = model(opt)
  File "/home/home/programs/level 2/gan-compression/models/cycle_gan_model.py", line 88, in __init__
    assert opt.dataset_mode == 'unaligned'
AssertionError

So i decided to change unaligned to aligned in cycle_gan_model.py, i am currently training and will report back later

lmxyy commented 4 years ago

I do not think you could change unaligned to aligned in cycle_gan_model.py. If you did that, you would need to modify many codes regarding to data preprocess.

The best way to launch the experiment is as follows:

ghost commented 4 years ago

My dataset have for each input image a corresponding output image, so it's an exact input and it's exact output. if i use the commands that you posted, will i be able to train using my dataset. or should i switch to pix2pix?

lmxyy commented 4 years ago

Both are okay. It depends on which model are you going to compress.

ghost commented 4 years ago
lmxyy commented 4 years ago
ghost commented 4 years ago
lmxyy commented 4 years ago

You could use the argument '--load_size' and '--crop_size' to change the resolution during training, searching or other things.

ghost commented 4 years ago

For get_real_stat i should change also yes?

lmxyy commented 4 years ago

You do not have to change it in get_real_stat.py since the inception model for computing FID has already rescaled the images to a fixed size. But remember to change it while training, searching and testing.

ghost commented 4 years ago

How can i resume training? lets say i stopped at epoch 32 and iteration 100000 which is the latest

MuyangLi-Dawnlight commented 4 years ago

You could use --restore_G_path, --restore_D_path to specify the checkpoints you would like to resume. By changing the your starting epoch and iteration with --epoch_base and --iter_base, you can go on training.

lmxyy commented 4 years ago

I will close the issue since it seems that your problem is not regarding to get_real_stat.py. If you have any other problems, feel free to open another issue.

ghost commented 4 years ago

haha, i know right, i asked you questions on how to train from scratch Thanks!