修改YOLOv8预测结果的标签值时,报了如下错误:
image 1/1 /Users/mac10.12/Downloads/IMG_1122.PNG: 640x384 3 persons, 86.8ms
Speed: 3.1ms preprocess, 86.8ms inference, 1.4ms postprocess per image at shape (1, 3, 640, 384)
Traceback (most recent call last):
File "/Users/mac10.12/github/YOLOSHOW/bb.py", line 10, in <module>
result.boxes[0].cls[0] = 1
~~~~~~~~~~~~~~~~~~~^^^
RuntimeError: Inplace update to inference tensor outside InferenceMode is not allowed.You can make a clone to get a normal tensor before doing inplace update.See https://github.com/pytorch/rfcs/pull/17 for more details.
报错的代码如下:
from pathlib import Path
from ultralytics import YOLO # type:ignore[import-untyped]
pic = Path.home() / "Downloads" / "IMG_1122.PNG"
model = YOLO("yolov8n.pt")
result = model(pic)[0]
result.names = {0: "woman", 1: "man", 2: "child"}
result.boxes[0].cls[0] = 1
result.show()
点