devit icon indicating copy to clipboard operation
devit copied to clipboard

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

Open londumas opened this issue 11 months ago • 0 comments

https://github.com/mlzxy/devit/blob/cfd0e0e28c8cdc8c0deff9b3f9dba7dcc1a08e61/demo/demo.py#L257

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,
            )
        )
```

londumas avatar Mar 19 '24 16:03 londumas