TTTTiankun 2023-10-28 14:46 采纳率: 0%
浏览 10
已结题

在ubuntu上利用openvino部署Yolov5模型出错

img

为什么在Ubuntu 上利用openvino2023.1.0部署yolov5模型时会出现这样的报错,使用的是用摄像头获得信息,训练的模型可以在val.py中完成验证,求帮助。

  • 写回答

14条回答 默认 最新

  • CrMylive. Python领域新星创作者 2023-10-28 16:35
    关注
    获得0.60元问题酬金

    结合GPT给出回答如下请题主参考
    首先,建议您提供更具体的错误信息,以便我们更好地帮助您解决问题。以下是可能会发生的问题和对应的解决方案:

    1. 缺少模型文件或权重文件

    可能会出现以下错误:

    Error: Can't read model
    

    或者

    Error: Can't read weights
    

    这通常是由于缺少模型文件或权重文件导致的。请确保 openvino 的模型和权重文件已正确下载,并且路径正确。

    1. 模型输出维度不匹配

    可能会出现以下错误:

    RuntimeError: Unexpected input shape! Expected: 1 255 20 20, but got: 1 125 20 20 for layer: yolo_1
    

    这通常是由于模型输出维度不匹配导致的。请检查模型输入的大小和格式是否正确。

    1. OpenCV 版本不兼容

    可能会出现以下错误:

    ImportError: libopencv_imgcodecs.so.4.5: cannot open shared object file: No such file or directory
    

    或者

    ImportError: libtbb.so.2: cannot open shared object file: No such file or directory
    

    这通常是由于 OpenCV 版本不兼容导致的。请检查您的 OpenCV 版本是否与 OpenVINO 版本兼容。

    1. 缺少依赖项

    可能会出现以下错误:

    ImportError: libinference_engine.so: cannot open shared object file: No such file or directory
    

    或者

    ImportError: libprotobuf.so.15: cannot open shared object file: No such file or directory
    

    这通常是由于缺少依赖项导致的。请确保您已正确安装并配置了 OpenVINO 的依赖项。

    以下是一个基本示例,演示了如何在 Ubuntu 上使用 OpenVINO 部署 YOLOv5 模型:

    import cv2
    import numpy as np
    from openvino.inference_engine import IECore
    
    # Define the path to the model and weights files.
    model_xml = 'path/to/model.xml'
    model_bin = 'path/to/model.bin'
    
    # Define the input and output layer names.
    input_layer = 'images'
    output_layer = ['output']
    
    # Create an instance of the IECore.
    ie = IECore()
    
    # Read in the model and weights.
    net = ie.read_network(model=model_xml, weights=model_bin)
    
    # Get information about the model's input and output layers.
    input_info = net.input_info[input_layer]
    output_info = net.outputs[output_layer[0]]
    
    # Define the input and output shapes for the network.
    input_shape = input_info.input_data.shape
    output_shape = output_info.shape
    
    # Create a plugin for the CPU device.
    plugin = ie.get_plugin(device='CPU')
    
    # Load the model into the plugin.
    executable_network = plugin.load(network=net)
    
    # Create a function to preprocess the input image.
    def prepare_input(image: np.ndarray) -> np.ndarray:
        # Resize the image to match the input shape of the network.
        image = cv2.resize(image, (input_shape[3], input_shape[2]))
        # Change the image from HWC format to CHW format.
        image = image.transpose((2, 0, 1))
        # Add another dimension to the input array to match the network input shape.
        image = np.expand_dims(image, axis=0)
        # Convert the input array to the correct data type.
        image = image.astype(np.float32)
        return image
    
    cap = cv2.VideoCapture(0)
    
    while True:
        # Read in an image from the camera.
        ret, image = cap.read()
    
        # Preprocess the image.
        input_data = prepare_input(image)
    
        # Run inference on the image.
        output = executable_network.infer(inputs={input_layer: input_data})
    
        # Postprocess the output.
        # TODO: Implement postprocessing of output data.
    
        # Display the output.
        cv2.imshow('Output', image)
    
        # Wait for a key press.
        if cv2.waitKey(1) == ord('q'):
            break
    
    评论

报告相同问题?

问题事件

  • 系统已结题 11月5日
  • 创建了问题 10月28日

悬赏问题

  • ¥15 Windows Script Host 无法找到脚本文件"C:\ProgramData\Player800\Cotrl.vbs”
  • ¥15 matlab自定义损失函数
  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图