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

PyTorchYolo and PyTorchObjectDetector modify the original numpy array #2262

Closed
f4str opened this issue Aug 30, 2023 · 1 comment
Closed

PyTorchYolo and PyTorchObjectDetector modify the original numpy array #2262

f4str opened this issue Aug 30, 2023 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@f4str
Copy link
Collaborator

f4str commented Aug 30, 2023

Describe the bug
The PyTorchYolo and PyTorchObjectDetectorobject detection estimators modify the original numpy array. This occurs because the torch.from_numpy and in-place torch methods are being used which will re-use the memory from the original numpy array.

To Reproduce
Create a PyTorchYolo model with the clip_values set to (0, 255). Create any numpy image and pass it to the model via the predict method. The original numpy array will be modified.

The following snippets show a simplified version of what is happening:

x = np.array([1])
y = torch.from_numpy(x)
y += 1

print(x)  # [2]
print(y)  # [2]
x = np.array([1])
y = torch.from_numpy(x)
y = y + 1

print(x)  # [1]
print(y)  # [2]
x = np.array([1])
y = torch.tensor(x)
y += 1

print(x)  # [1]
print(y)  # [2]

Expected behavior
The original numpy array should not be modified. This can be fixed by either making a copy or not using in-place operations. One unknown point is how much of the inputs should be copied (i.e., only images or both images and labels).

Screenshots
N/A

System information (please complete the following information):

  • OS
  • Python version
  • ART version or commit number
  • TensorFlow / Keras / PyTorch / MXNet version
@beat-buesser beat-buesser added the bug Something isn't working label Aug 30, 2023
@beat-buesser beat-buesser added this to the ART 1.15.2 milestone Aug 30, 2023
@beat-buesser
Copy link
Collaborator

Hi @f4str Thank you for opening this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants