question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError: Expected object of scalar type Long but got scalar type Byte for argument #2 'target'

See original GitHub issue

With optimizer = torch.optim.Adam( model.parameters(), lr = learning_rate, weight_decay = weight_decay)

criterion = nn.CrossEntropyLoss( weight = None, ignore_index = ignore_index, reduce = False)

and then executing

lr_finder = LRFinder(model, optimizer, criterion, device="cuda") lr_finder.range_test( dataLoader[ 'train'], end_lr=100, num_iter=100) lr_finder.plot() # to inspect the loss-learning rate graph lr_finder.reset() # to reset the model and optimizer to their initial state

I am getting the error,

RuntimeError: Expected object of scalar type Long but got scalar type Byte for argument #2 ‘target’

Please find below the whole trace. So far training my models with the above optimizer and criterion I do not have any problem.

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vpapaioannoucommented, Jan 21, 2020

Thanks for your prompt response.

I have been running this code for months now on Google Colab with no problem and with batch size = 256. I observe that after installing the lr-finder the code breaks. Errors are reported where there was no problem.

In other words, I would suggest that it is a compatibility issue. I would be happy, if I could help somehow on that.

Thanks,

Vassilis

0reactions
davidtvscommented, Jun 11, 2020

A new release (v0.2.0) is available that addresses issues like this one by allowing the user to wrap the training and validation DataLoader in a TrainDataLoaderIter and `TrainDataLoaderIter’ and do further data processing/handling/conversions there. For a usage example see: examples/lrfinder_cifar10_dataloader_iter.

However, I still think that the best way to deal with this issue is by placing all needed data processing/handling/conversions in the DataLoader as described in my previous comment.

Closing this in the meantime feel free to reopen if not resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expected object of scalar type Long but got ... - Stack Overflow
The title of your question is telling what is causing this error. The target should have type torch.LongTensor , but it is instead...
Read more >
RuntimeError: Expected object of scalar ... - PyTorch Forums
I have a NN that ends with the following linear layers dense = nn.Linear(input_size, 1) if I use CrossEntropyLoss as loss function (as...
Read more >
RuntimeError: Expected object of scalar type Long ... - GitHub
During data loading, the target should be of type Long for cross-entropy loss. In the dataloader set: target = target.to(dtype=torch.long) Whereas, in case...
Read more >
pytorch RuntimeError: Expected object of scalar type Double ...
I am trying to implement a custom dataset for my neural network. But got this error when running the forward function. The code...
Read more >
expected scalar type float but found byte - You.com | The AI ...
Runtimeerror : Expected Scalar Type Byte but Found Float If you're seeing this error, it means that you're trying to use a byte...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found