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

warning in the demo : The given NumPy array is not writable #52

Open
londumas opened this issue Mar 19, 2024 · 0 comments
Open

warning in the demo : The given NumPy array is not writable #52

londumas opened this issue Mar 19, 2024 · 0 comments

Comments

@londumas
Copy link

output = to_pil_image(draw_bounding_boxes(torch.as_tensor(image).permute(2, 0, 1), boxes, labels=[label_names[cid] for cid in pred_classes.tolist()], colors=colors))

UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This means writing to this ten
sor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of thi
s program. (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:199.)
  torch.as_tensor(image).permute(2, 0, 1),
```

The solution is:
```python
output = to_pil_image(
            draw_bounding_boxes(
                torch.as_tensor(image.copy()).permute(2, 0, 1),
                boxes,
                labels=[label_names[cid] for cid in pred_classes.tolist()],
                colors=colors,
            )
        )
```
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

1 participant