Is there a way to edit a result object in YOLOv8? (pytorch)

494 views Asked by At

I tried to edit a property from a result type that I get from the ` model.track` function from YOLO

enter image description here

code:

    for result in model.track(source=source, show=False, stream=True, verbose=False):
    frame = result.orig_img
    
    # result.boxes.id[0] = 0 # Code Crash
    print('After', result.boxes.id)

And I got this error:

  • 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.

I Read the forum that the error linked me but it was no help.

I tried making another result object and copy every value from it besides the id (the property that I am trying to edit) and it was also a no go

Using the del keyword is also a no go.

I've read in the torch docs (after looking up how to change tensors) about an Inference Mode option in which I can edit the object but I still haven't managed to use this info to my advantage

The tensor in question:

enter image description here

After tensor([1., 2., 3., 4., 5., 6.])
1

There are 1 answers

2
liran bratt On

I managed to solve the problem by using the update function inside the results class. to update the results obj

https://github.com/ultralytics/ultralytics/blob/main/ultralytics/engine/results.py