YOLO-Worldv2两分钟快速部署

本次部署使用的框架基于ultralytics, 并且已经集成最新版本的YOLOv8框架:

一键环境配置

pip install ultralytics

基础使用

  • 训练
from ultralytics import YOLOWorld
model = YOLOWorld('yolov8x-worldv2.pt')
results = model.train(data='coco8.yaml', epochs=100, imgsz=640)
results = model('path/to/bus.jpg')
  • 推理
from ultralytics import YOLOWorld
model = YOLOWorld('yolov8s-worldv2.pt')
results = model.predict('path/to/image.jpg')
results[0].show()
  • 自定义标签
    • 我们定义了保温杯,马克杯,纸杯,抽纸,笔记本,屏幕等标签。均不被包含在COCO类别定义中。
model = YOLOWorld('yolov8s-worldv2.pt')
model.set_classes(['Insulated_cup','mug','paper_cup','drawing_paper','laptop', 'screen', 'woman', 'wirless_earphone', 'Shoulder_bag'])
model.save("elephant_camel_world.pt")
  • 导出onnx
model = YOLO('cup_mug_world.pt')
model.export(format="onnx", opset=11)

实时推理

简单修改代码,使得opencv调用网络摄像头并介入yolo-world。代码如下:

from ultralytics import YOLOWorld
import cv2
import numpy as np

model = YOLOWorld('yolov8x-worldv2.pt') 
model.set_classes(['Insulated_cup','mug','paper_cup','drawing_paper','laptop', 'screen', 'woman', 'wirless_earphone', 'Shoulder_bag'])
model.save("elephant_camel_world.pt")


capture = cv2.VideoCapture(2)

# while True:
ret, frame = capture.read()
# cv2.imshow("result", frame)
# cv2.waitKey(0)

while True:
    ret, frame = capture.read()
    results = model.predict(np.array(frame))
    cv2.imshow("result", results[0].plot(False))
    cv2.waitKey(1)

具体效果如下。从图中我们可以看到,yolo-world确实可以扩展类别到一些细分、甚至是类似的其他类别。但是存在类别识别错误,以及同物体重识别的情况。
在这里插入图片描述

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
The error message you're encountering suggests that there's an issue with importing the `YOLO_WORLD_EfficientSAM` module from a Python package. The `ImportError: attempted relative import with no known parent package` typically indicates that the code is trying to use a relative import (`from . import ...`) but the current directory structure does not have a proper package structure or the parent package has not been imported correctly. Here's what you can do to resolve this: 1. **Check package structure**: Ensure that you have a `__init__.py` file in the root directory of your package, as this is required for Python to recognize it as a package. If the module you're trying to import is in a subdirectory, move it up to the same level or create the necessary levels of directories (e.g., `your_package/your_subpackage`). 2. **Use absolute imports**: Instead of using relative imports, try importing the module using an absolute path, like `from yoloworld import YOLO_WORLD_EfficientSAM`. 3. **Ensure correct import statement**: If you are within a package, make sure you're importing the package correctly before attempting to import the submodule. For example, if the package is called `yoloworld`, you might need to do `import yoloworld` first and then use `from yoloworld.YOLO_WORLD_EfficientSAM import *`. 4. **Update PYTHONPATH**: If you're working in a development environment, ensure your PYTHONPATH environment variable includes the correct path to the package location. If you provide more details about your project setup and the exact context where you're encountering this error, I could give a more tailored solution. Here are some related questions for further clarification:
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值