PyTorch-CycleGAN icon indicating copy to clipboard operation
PyTorch-CycleGAN copied to clipboard

RuntimeError: The expanded size of the tensor (1) must match the existing size (3) at non-singleton dimension 0

Open chenmw269 opened this issue 4 years ago • 2 comments
trafficstars

When I use my own data set, the program runs normally, but with the dataset :horse2zebra, the program starts to report errors:

image

chenmw269 avatar Mar 26 '21 06:03 chenmw269

I also encountered this problem. It may be that some images in the data set are grayscale images instead of rgb images. I deleted these grayscale images to solve this problem. Here is my code. `def remove_single_channel_images(images_files): for path in sorted(os.listdir(images_files)): image_path = os.path.join(images_files, path) image = Image.open(image_path) image = np.array(image) if image.shape != (256, 256, 3): print(image_path) os.remove(image_path)

remove_single_channel_images('datasets/horse2zebra/train/B')`

hdhcy avatar May 02 '21 05:05 hdhcy

The main reason for this problem is that there are single channel images in the data set. Solution: just add. convert ('rgb ') in datasets.py file iterm_B = self.transform(Image.open(self.files_B[random.randint(0, len(self.files_B)-1)]).convert('RGB'))

dushaobo16 avatar Sep 03 '22 10:09 dushaobo16