[go: up one dir, main page]

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: expected scalar type Long but found Int #1989

Closed
skylning opened this issue Nov 9, 2023 · 10 comments
Closed

RuntimeError: expected scalar type Long but found Int #1989

skylning opened this issue Nov 9, 2023 · 10 comments

Comments

@skylning
Copy link
skylning commented Nov 9, 2023

f:\raster-vision\docs\usage\tutorials\train.ipynb cell 41 line 1
----> 1 learner.train(epochs=3)

File d:\Python310\lib\site-packages\rastervision\pytorch_learner\learner.py:391, in Learner.train(self, epochs)
389 for epoch in range(start_epoch, end_epoch):
390 log.info(f'epoch: {epoch}')
--> 391 train_metrics = self.train_epoch(
392 optimizer=self.opt, step_scheduler=self.step_scheduler)
393 if self.epoch_scheduler:
394 self.epoch_scheduler.step()

File d:\Python310\lib\site-packages\rastervision\pytorch_learner\learner.py:415, in Learner.train_epoch(self, optimizer, step_scheduler)
413 batch = (x, y)
414 optimizer.zero_grad()
--> 415 output = self.train_step(batch, batch_ind)
416 output['train_loss'].backward()
417 optimizer.step()

File d:\Python310\lib\site-packages\rastervision\pytorch_learner\semantic_segmentation_learner.py:30, in SemanticSegmentationLearner.train_step(self, batch, batch_ind)
28 x, y = batch
29 out = self.post_forward(self.model(x))
---> 30 return {'train_loss': self.loss(out, y).long()}
...
3051 if size_average is not None or reduce is not None:
3052 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 3053 return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)

RuntimeError: expected scalar type Long but found Int

@AdeelH
Copy link
Collaborator
AdeelH commented Nov 9, 2023

This should have been fixed (#1954) in the 0.21.3 release. Can you make sure you're using the latest version of Raster Vision?

@skylning
Copy link
Author

yes ,i run the pip list and check the Raster Vision, it is 0.21.3

@AdeelH
Copy link
Collaborator
AdeelH commented Nov 10, 2023

That's strange. Please share your code.

@skylning
Copy link
Author

I run the train.ipynb,and change the train_image_uri 、train_label_uri、val_image_uri、val_label_uri as my local data path and get the error,and my torch is 2.1.0+cu121

@AdeelH
Copy link
Collaborator
AdeelH commented Nov 14, 2023

I am not able to reproduce the error using version 0.21.3 and running the code in train.ipynb. Are you able to run the notebook successfully without changing the URIs?

@chrisjkuch
Copy link

I ran into this issue as well and found that, in my dataset, adding an albumentations transform like transform=A.resize(chip_sz, chip_sz) solves the problem. Perhaps albumentations performs the necessary conversion to the right data type?

@skylning
Copy link
Author

I am not able to reproduce the error using version 0.21.3 and running the code in train.ipynb. Are you able to run the notebook successfully without changing the URIs?

Same issue without change the URLs.

@skylning
Copy link
Author

I ran into this issue as well and found that, in my dataset, adding an albumentations transform like transform=A.resize(chip_sz, chip_sz) solves the problem. Perhaps albumentations performs the necessary conversion to the right data type?

How to add transfom,can you share you code snipe?thanks

@chrisjkuch
Copy link

See this discussion for an example

@skylning
Copy link
Author
skylning commented Dec 1, 2023

I change the OS to ubuntu 22.04,and no issue happen,it works well.

@skylning skylning closed this as completed Dec 1, 2023
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