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

Unable to get the training started #243

Closed
sarthakpati opened this issue Jul 24, 2020 · 4 comments
Closed

Unable to get the training started #243

sarthakpati opened this issue Jul 24, 2020 · 4 comments

Comments

@sarthakpati
Copy link
Contributor

Hey,

I am trying to do dummy train but I am running into a weird error. Here is what I have written:

trainingDataForTorch = torchio.ImagesDataset( ... )
train_loader = DataLoader( ... )

# all good till here

for ep in range(epochs)
    batch_iterator = iter(train_loader)
    for batch_idx, (subject) in enumerate(train_loader):
        batch_train = next(batch_iterator_train)
        image = torch.cat([batch_train[key][torchio.DATA] for key in batch_train.keys()], dim=1) # concatenate channels 

In the last line (taken from #236), I get the following error:

Traceback (most recent call last):
  File "trainer.py", line 287, in <module>
    image = torch.cat([batch_train[key][torchio.DATA] for key in batch_train.keys()], dim=1) # concatenate channels
  File "trainer.py", line 287, in <listcomp>
    image = torch.cat([batch_train[key][torchio.DATA] for key in batch_train.keys()], dim=1) # concatenate channels
IndexError: too many indices for tensor of dimension 2

Pretty sure I am doing some silly syntactic mistake, here but wanted to get your opinion, too. Thanks.

@fepegar
Copy link
Owner

fepegar commented Jul 24, 2020

Hi, @sarthakpati. It's a bit hard to know what's going on without some more code. What is batch_iterator_train? Why not just doing for batch_idx, batch in enumerate(train_loader)? Do you think you can provide a minimal working example?

@sarthakpati
Copy link
Contributor Author

No worries, I got it to work, thanks!

@fepegar
Copy link
Owner

fepegar commented Jul 24, 2020

Good! Can you say where the problem was, for reference?

@sarthakpati
Copy link
Contributor Author

Basically did what you suggested and used for batch_idx, batch in enumerate(train_loader). 😄

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