Comments (5)
Are you sure you processed all previous cells and they completed successfully?
Like this, cell 6:
from PIL import Image
from ultralytics import YOLO
DET_MODEL_NAME = "yolov8n"
det_model = YOLO(models_dir / f"{DET_MODEL_NAME}.pt")
label_map = det_model.model.names
res = det_model(IMAGE_PATH)
Image.fromarray(res[0].plot()[:, :, ::-1])
With
det_model.predictor.inference = infer
AttributeError: 'NoneType' object has no attribute 'inference'
It sounds like det_model.predictor
is not yet/not anymore initialized because of NoneType
.
from openvino_notebooks.
import cv2
import torch
import numpy as np
import openvino as ov
from PIL import Image
from ultralytics.models.yolo.detect import DetectionPredictor
from ultralytics.utils import ASSETS
class RunIntelModel:
def __init__(self) -> None:
# openvino official tutorial and the official issue of yolov8 provided guidelines and the original code base can not correspond to, here according to the library source code logic to make changes
# Set up the cfg file first (call it according to the comment part of /ultralytics/models/yolo/detect/predict.py).
# Use the setup_model method in ultralytics/engine/predictor.py to initialise the model, otherwise the model property in __init__ is None
# None value can not change model.pt property, not change the property will lead to letterbox output and openvino fixed input size discrepancy, resulting in openvino can not reason about the issue
self.args = dict(model='hand.pt', source=ASSETS, imgsz=(640,640), save=True)
self.predictor = DetectionPredictor(overrides=self.args)
self.predictor.setup_model("hand.pt")
self.predictor.model.pt = False
self.det_model_path = "hand_openvino_model/hand.xml"
self.openvino_model = self.setup_model()
self.predictor.inference = self.infer
def setup_model(self):
core = ov.Core()
det_ov_model = core.read_model(self.det_model_path)
ov_config = {}
det_ov_model.reshape({0: [1, 3, 640, 640]})
ov_config = {"GPU_DISABLE_WINOGRAD_CONVOLUTION": "YES"}
det_compiled_model = core.compile_model(det_ov_model, "GPU.1", ov_config)
return det_compiled_model
def infer(self, *args):
print(args[0].shape)
result = self.openvino_model(args)
return torch.from_numpy(result[0])
def predict(self, raw_img):
res = self.predictor(raw_img)
if res[0].boxes.shape[0] > 0:
return res[0].boxes.conf[0], res[0].boxes.xywh
else:
return 0, [0, 0, 0, 0]
def __call__(self, img):
return self.predict(raw_img=img)
from openvino_notebooks.
Above is my solution
from openvino_notebooks.
Are you sure you processed all previous cells and they completed successfully? Like this, cell 6:
from PIL import Image from ultralytics import YOLO DET_MODEL_NAME = "yolov8n" det_model = YOLO(models_dir / f"{DET_MODEL_NAME}.pt") label_map = det_model.model.names res = det_model(IMAGE_PATH) Image.fromarray(res[0].plot()[:, :, ::-1])
With
det_model.predictor.inference = infer AttributeError: 'NoneType' object has no attribute 'inference'
It sounds like
det_model.predictor
is not yet/not anymore initialized because ofNoneType
.
you are right
from openvino_notebooks.
@yangtianyu92 hi
trying to use your example:
class RunIntelModel:
def __init__(self) -> None:
# openvino official tutorial and the official issue of yolov8 provided guidelines and the original code base can not correspond to, here according to the library source code logic to make changes
# Set up the cfg file first (call it according to the comment part of /ultralytics/models/yolo/detect/predict.py).
# Use the setup_model method in ultralytics/engine/predictor.py to initialise the model, otherwise the model property in __init__ is None
# None value can not change model.pt property, not change the property will lead to letterbox output and openvino fixed input size discrepancy, resulting in openvino can not reason about the issue
self.args = dict(model="models/yolov8n_openvino_model/yolov8n.bin", source=ASSETS, imgsz=(640,640), save=True)
self.predictor = DetectionPredictor(overrides=self.args)
self.predictor.setup_model("models/yolov8n_openvino_model/yolov8n.bin")
self.predictor.model.pt = False
self.det_model_path = "models/yolov8n_openvino_model/yolov8n.xml"
self.openvino_model = self.setup_model()
self.predictor.inference = self.infer
def setup_model(self):
core = ov.Core()
det_ov_model = core.read_model(self.det_model_path)
ov_config = {}
det_ov_model.reshape({0: [1, 3, 640, 640]})
ov_config = {"GPU_DISABLE_WINOGRAD_CONVOLUTION": "YES"}
det_compiled_model = core.compile_model(det_ov_model, "GPU", ov_config)
return det_compiled_model
def infer(self, *args):
print(args[0].shape)
result = self.openvino_model(args)
return torch.from_numpy(result[0])
def predict(self, raw_img):
res = self.predictor(raw_img)
if res[0].boxes.shape[0] > 0:
return res[0].boxes.conf[0], res[0].boxes.xywh
else:
return 0, [0, 0, 0, 0]
def __call__(self, img):
return self.predict(raw_img=img)
r=RunIntelModel()
r.setup_model()
IMAGE_PATH=cv2.imread('coco_bike.jpg')
r.predict(IMAGE_PATH)
but got this:
fp16 &= pt or jit or onnx or xml or engine or nn_module or triton # FP16
TypeError: unsupported operand type(s) for &=: 'bool' and 'str'
may be .bin type is not accepted ?
from openvino_notebooks.
Related Issues (20)
- Opconversion Failure for gemma-7b_INT4 HOT 3
- [235-controlnet] Fail to prepare a dataset for quantization HOT 2
- [Notebook Hello Segmentation] segmented image result is not displaying expected image HOT 2
- load model with GPU error HOT 9
- how to run chatglm3 by NPU HOT 1
- llm-chatbot can't run on Ultra7 155H NPU HOT 2
- How to clear cache of installed packages? HOT 3
- Getting error when using Docker installation method HOT 3
- Permission Error HOT 3
- Can't test on single image with model yolov8 HOT 1
- Error building openvino notebooks on Ubuntu HOT 3
- Installed openvino notebook using docker. But check_install.py failed HOT 8
- Is LLama3 model (int4) compiled for NPU compatible to connect Langchain based RAG system HOT 2
- Unable to compile Llama3 8B model for NPU using Openvino (we have latest NPU drivers - April 2024 version) HOT 2
- [Issue]: KeyError: "phi3 is not supported yet for transformers. HOT 1
- Pip install intel-extension-for-pytorch does not work. HOT 2
- LLM-chatbot llama3 model issue HOT 1
- setuptools version error
- [GH Pages] Any buttons on notebook cards will open its document anyway instead of doing it's expected action
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openvino_notebooks.