Skip to content

Fix/Copying tensor#18

Merged
adaamko merged 2 commits into
KRLabsOrg:mainfrom
lebe1:fix/tensor-copy
May 5, 2025
Merged

Fix/Copying tensor#18
adaamko merged 2 commits into
KRLabsOrg:mainfrom
lebe1:fix/tensor-copy

Conversation

@lebe1
Copy link
Copy Markdown
Contributor

@lebe1 lebe1 commented Apr 30, 2025

Misbehaviour
After installing the package via pip install -e . on a clean python environment and running the notebook detection.ipynb, I get the following UserWarning /Users/kovacs/projects/LettuceDetect/lettucedetect/models/inference.py:84: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor). labels = torch.tensor(labels, device=self.device)

First I improved this line of code labels = torch.tensor(labels, device=self.device)
as suggested but finally removed the line since I did not understand the reason to copy a tensor into the same tensor variable again, seen here.

@adaamko adaamko self-requested a review May 5, 2025 10:31
@adaamko adaamko merged commit 2513f5c into KRLabsOrg:main May 5, 2025
1 check passed
@lebe1 lebe1 deleted the fix/tensor-copy branch May 13, 2025 08:10
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

Successfully merging this pull request may close these issues.

2 participants