aitorzip / PyTorch-CycleGAN

A clean and readable Pytorch implementation of CycleGAN
https://arxiv.org/abs/1703.10593
GNU General Public License v3.0
1.19k stars 283 forks source link

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

Open chenmw269 opened 3 years ago

chenmw269 commented 3 years ago

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

image

hdhcy commented 3 years ago

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')`

dushaobo16 commented 1 year ago

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'))