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

Sizes of tensors must match except in dimension 0. Got 3 and 1 in dimension 1 #3

Open
Dayananda-V opened this issue Oct 31, 2019 · 1 comment

Comments

@Dayananda-V
Copy link

Dayananda-V commented Oct 31, 2019

Encounter training phase problem with Places2 256 size dataset , looking forward help to solve this.

Traceback (most recent call last):
File "train.py", line 2, in
main(mode=1)
File "/home/user/workspace/user/performance/edge-informed-sisr/main.py", line 50, in main
model.train()
File "/home/user/workspace/user/performance/edge-informed-sisr/src/edge_match.py", line 150, in train
self.sample()
File "/home/user/workspace/user/performance/edge-informed-sisr/src/edge_match.py", line 252, in sample
items = next(self.sample_iterator)
File "/home/user/workspace/user/performance/edge-informed-sisr/src/dataset.py", line 146, in create_iterator
for item in sample_loader:
File "/home/user/anaconda3/envs/user_workspace/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 346, in next
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/home/user/anaconda3/envs/user_workspace/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
return self.collate_fn(data)
File "/home/user/anaconda3/envs/user_workspace/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 79, in default_collate
return [default_collate(samples) for samples in transposed]
File "/home/user/anaconda3/envs/user_workspace/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 79, in
return [default_collate(samples) for samples in transposed]
File "/home/user/anaconda3/envs/user_workspace/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 55, in default_collate
return torch.stack(batch, 0, out=out)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 1 in dimension 1 at /opt/conda/conda-bld/pytorch_1570710743984/work/aten/src/TH/generic/THTensor.cpp:689

Note : This problem encounter while evaluation dataset not training dataset

@richardburleigh
Copy link

It means at least one of your images isn't formatted correctly (eg. greyscale).

Here's a hacked together script I made to find and move those images to another folder. Just be aware that I haven't done any checks for filenames, so any other file in the directory will be moved as well.

import os
from scipy.misc import imread
from tqdm import tqdm

directory = 'INDIRECTORY'
movedir = 'OUTDIRECTORY'

for filename in tqdm(os.listdir(directory)):
        file = directory + filename

        try:
            im = imread(file)
            #print(filename + " is " + str(im.shape))
            if im.shape != (1024,1024,3):
                try:
                    os.rename(file, movedir + filename)
                except:
                    continue
                print(filename + " is " + str(im.shape))
        except:
            print("Failed to load " + str(filename))
            try:
                os.rename(file, movedir + filename)
            except:
                continue

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

2 participants