openvinotoolkit / openvino_notebooks

šŸ“š Jupyter notebook tutorials for OpenVINOā„¢
Apache License 2.0
2.34k stars 798 forks source link

Issue running Yolov8 segmentation example #2175

Closed baumshl closed 2 months ago

baumshl commented 3 months ago

Hi,

I'm trying to replicate the sample provided here basically I'm getting on my end for the following lines of code (which is trying to avoid running the regular Yolo model and use the OpenVino inference results instead):

seg_model.predictor.inference = infer seg_model.predictor.model.pt = False

I'm getting the following errors:

seg_model.predictor.inference = infer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AttributeError: 'NoneType' object has no attribute 'inference'

And also: seg_model.predictor.model.pt = False ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'model'

When I'm running the code colab everything seems to run fine.

Here's the full code: import numpy as np import cv2 from openvino.runtime import Core from PIL import Image import torch from ultralytics import YOLO

Paths to the IR model files

ir_model_path = "yolov8n-seg.xml"

Initialize the OpenVINO runtime core

core = Core()

Read the model

model = core.read_model(model=ir_model_path) compiled_model = core.compile_model(model=model, device_name="GPU")

Define path to the image file

source = "download1.jpeg"

def infer(*args): result = compiled_model(args) return torch.from_numpy(result[0]), torch.from_numpy(result[1])

seg_model = YOLO("yolov8n-seg.pt") label_map = seg_model.model.names

seg_model.predictor.inference = infer

seg_model.predictor.model.pt = False

res = seg_model(source) Image.fromarray(res[0].plot()[:, :, ::-1])

Thank you!

Wan-Intel commented 3 months ago

I'm able to run the sample successfully in Google Colab as shown in the following screenshot: google colab

May I know which Operating System and Python version are you using on your machine?

eaidova commented 2 months ago

@baumshl which ultralytics version do you have? Please make sure that it is the same like specified in requirements of notebook (the first code cell).

From may experience, Ultralytcs API rapidly changing every minor release and does not preserve backward compatibility, so written code can be noncompatible with your used version.

I have suspicious that in your version predictor is not initialized by default and you need to add this code to create it first. https://github.com/ultralytics/ultralytics/blob/main/ultralytics/engine/model.py#L433

Wan-Intel commented 2 months ago

baumshl Just wanted to follow up and see if the issue has been resolved.

Wan-Intel commented 2 months ago

Closing issue, feel free to re-open or restart a new issue if additional assistance is needed.