junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
22.86k stars 6.3k forks source link

ValueError: empty range for randrange() (0, -185, -185) #503

Open NirChachmovitz opened 5 years ago

NirChachmovitz commented 5 years ago

Hello everyone,

I try testing my images using the following command:

python3.5 test.py --dataroot /Desktop/to/data --name 20Jan --model test --netG unet_256 --direction AtoB --dataset_mode single --norm batch --preprocess scale_width_and_crop

and I receive the following problem:

Traceback (most recent call last): File "test.py", line 56, in for i, data in enumerate(dataset): File "/Desktop/pytorch-CycleGAN-and-pix2pix-master/data/init.py", line 90, in iter for i, data in enumerate(self.dataloader): File "/.local/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 637, in next return self._process_next_batch(batch) File "/.local/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 658, in _process_next_batch raise batch.exc_type(batch.exc_msg) ValueError: Traceback (most recent call last): File "/.local/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/.local/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 138, in samples = collate_fn([dataset[i] for i in batch_indices]) File "/Desktop/pytorch-CycleGAN-and-pix2pix-master/data/single_dataset.py", line 35, in getitem A = self.transform(A_img) File "/.local/lib/python3.5/site-packages/torchvision/transforms/transforms.py", line 49, in call img = t(img) File "/.local/lib/python3.5/site-packages/torchvision/transforms/transforms.py", line 421, in call i, j, h, w = self.get_params(img, self.size) File "/.local/lib/python3.5/site-packages/torchvision/transforms/transforms.py", line 399, in get_params i = random.randint(0, h - th) File "/usr/lib/python3.5/random.py", line 218, in randint return self.randrange(a, b+1) File "/usr/lib/python3.5/random.py", line 196, in randrange raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width)) ValueError: empty range for randrange() (0,-185, -185)

However, when i remove the --preprocess, using:

python3.5 test.py --dataroot /Desktop/to/data --name 20Jan --model test --netG unet_256 --direction AtoB --dataset_mode single --norm batch

It actually works. (Though it is necessary since I trained the model by scaling the width and cropping).

Thanks in advance!

junyanz commented 5 years ago

The error is caused by cropping when crop_size is larger than the height or width of the image. Maybe you height (after rescaling) is smaller than crop_size. This Q & A might be relevant. Training and test preprocess options do not have to be the same.