Pytorch-cyclegan-and-pix2pix: ValueError: empty range for randrange() (0, -185, -185)

Created on 21 Jan 2019  路  1Comment  路  Source: junyanz/pytorch-CycleGAN-and-pix2pix

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!

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings