RuntimeError: Expected object of scalar type Long but got scalar type Byte for argument #2 'target'
See original GitHub issueWith 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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.