Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chenmw269 opened this issue Mar 26, 2021 · 2 comments

Comments

@chenmw269
Copy link

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

image

@hdhcy
Copy link

hdhcy commented May 2, 2021

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants