记录一次成功把ssd_mobilenet移植英特尔Movidius VPU

本文详细记录了在Win10环境下使用PowellShell以管理员权限进行MovidiusVPU上SSDMobilenet模型移植的过程。通过正确配置并执行特定命令,避免了官方指南中的常见错误,成功实现了模型的优化与转换。

(23条消息)Movidius VPU移植ssd_mobilenet问题记录 - 搬砖之路的专栏 - 优快云博客
https://blog.youkuaiyun.com/bobpeter84/article/details/82685310

楼上这家好像没有移植成功。主要是命令不对。

我记录下我的方法。

首先在win10下是可以转的。

前提是 用 powellshell ,记得用管理员方式打开。

进入OpenVINO的model_optmizer目录下,同时建立文件夹为ssd,

把ssd_mobilenet_v2.config及ssd_mobilenet_v2.pb复制到ssd文件夹下,在model_optmizer目录下执行一下命令:

python mo_tf.py --input_model ssd/ssd_mobilenet_v2.pb --output=detection_boxes,detection_scores,num_detections --tensorflow_use_custom_operations_config extensions/front/tf/ssd_v2_support.json --tensorflow_object_detection_api_pipeline_config ssd/ssd_mobilenet_v2.config

不要用 我曾经一次在 英特尔 他们的 技术交流会给的 错误指南,如下

最后输出结果如下:

在树莓派小车上部署和使用 MobileNetSSD 模型进行目标检测是一项常见的嵌入式 AI 任务。以下是一个详细的教程,涵盖从环境搭建到模型部署的全过程。 ### ### 环境准备 1. **操作系统安装** 使用官方推荐的 Raspberry Pi OS(如 Raspbian Bullseye)作为系统基础。可以通过 [Raspberry Pi Imager](https://www.raspberrypi.com/software/) 工具烧录系统镜像。 2. **更新系统与安装依赖库** 安装必要的开发工具和 OpenCV 库: ```bash sudo apt update && sudo apt upgrade -y sudo apt install -y build-essential cmake git libopencv-dev python3-opencv python3-pip ``` 3. **Python 虚拟环境配置(可选)** 创建虚拟环境以避免依赖冲突: ```bash python3 -m venv mobilenetssd_env source mobilenetssd_env/bin/activate pip install opencv-python numpy ``` ### ### 下载 MobileNetSSD 模型文件 根据引用信息,可以下载所需的模型文件[^1]: - `MobileNetSSD_deploy.prototxt`:网络结构定义文件。 - `MobileNetSSD_deploy.caffemodel`:预训练权重文件。 可通过以下命令下载模型文件(假设已获取有效链接): ```bash wget https://example.com/path/to/MobileNetSSD_deploy.prototxt wget https://example.com/path/to/MobileNetSSD_deploy.caffemodel ``` 若模型托管在 GitHub 上,也可以直接克隆相关仓库[^2]: ```bash git clone https://github.com/PINTO0309/MobileNet-SSD-RealSense.git cd MobileNet-SSD-RealSense/caffemodel/MobileNetSSD/ ``` ### ### 编写目标检测脚本 使用 OpenCV 的 `dnn` 模块加载 Caffe 模型并执行推理: ```python import cv2 import numpy as np # 加载模型 net = cv2.dnn.readNetFromCaffe("MobileNetSSD_deploy.prototxt", "MobileNetSSD_deploy.caffemodel") # 类别标签(常见对象) CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"] # 颜色映射 COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3)) # 打开摄像头 cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() if not ret: break (h, w) = frame.shape[:2] blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 0.007843, (300, 300), 127.5) net.setInput(blob) detections = net.forward() # 遍历检测结果 for i in range(detections.shape[2]): confidence = detections[0, 0, i, 2] if confidence > 0.2: # 设置置信度阈值 idx = int(detections[0, 0, i, 1]) box = detections[0, 0, i, 3:7] * np.array([w, h, w, h]) (startX, startY, endX, endY) = box.astype("int") label = f"{CLASSES[idx]}: {confidence:.2f}" cv2.rectangle(frame, (startX, startY), (endX, endY), COLORS[idx], 2) y = startY - 15 if startY - 15 > 15 else startY + 15 cv2.putText(frame, label, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2) cv2.imshow("Frame", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() ``` ### ### 性能优化建议 由于树莓派资源有限,建议采取以下措施提升性能: - **降低输入分辨率**:将输入图像尺寸调整为更小(如 224x224),但需修改 prototxt 文件中的输入层设置。 - **使用 FP16 推理模式**:如果模型支持,可以在加载时启用半精度浮点数计算。 - **关闭不必要的服务**:释放 CPU 和内存资源,例如关闭桌面环境运行 headless 模式。 - **硬件加速**:尝试使用 Coral Edge TPU 或 VPU 设备进行推理加速。 ### ### 注意事项 - 确保模型文件路径正确,否则会报错“无法读取模型”。 - 若使用 USB 摄像头,请确认设备权限已设置(如 `sudo chmod 666 /dev/video0`)。 - 树莓派上运行深度学习模型时,注意散热和供电稳定性。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

往事如yan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值