php和网站建设娄底网站建设企业
- 作者: 多梦笔记
- 时间: 2026年02月17日 12:05
当前位置: 首页 > news >正文
php和网站建设,娄底网站建设企业,电子商务网站建设 实验分析,迅 网站 模板Introduction 经过前面三篇教程帖子#xff08;yolov8n在行空板上的运行#xff08;中文#xff09;#xff0c;yolov10n在行空板上的运行#xff08;中文#xff09;#xff0c;Mediapipe在行空板上的运行#xff08;中文#xff09;#xff09;的介绍#xff0c;…Introduction 经过前面三篇教程帖子yolov8n在行空板上的运行中文yolov10n在行空板上的运行中文Mediapipe在行空板上的运行中文的介绍我们对如何使用官方代码在行空板上运行物体检测的AI模型有了基本的概念并对常见的模型进行了简单的测试和对比。 在行空板上YOLO和Mediapipe图片物体检测的测试中文中我们对于行空板上使用YOLO和Mediapipe进行图片物体检测进行了测试。 进一步的本文将 对不同模型的视频物体检查进行详细的对比分析进行针对在行空板上的视频物体检测进行代码编写和优化对不同模型的帧率对比测试。 Note: 因为视频物体检测和图片物体检测用的是相同的模型所以在检测准确性上不会有区别所以检测结果的准确性可以直接参考以行空板上YOLO和Mediapipe图片物体检测的测试中文所做的测试。 yolo视频物体检测 不同onnx模型导出设置的表现对比 设置和代码 导出onnx模型的官方代码为 from ultralytics import YOLO# Load a pretrained YOLOv10n model model YOLO(yolov10n.pt)#export onnx model.export(formatonnx)yolo系列模型在使用官方代码导出onnx格式模型的时候有几个不同的选项 参数类型默认值描述imgszint or tuple640模型输入所需的图像大小。对于正方形图像可以是整数对于特定尺寸可以是元组(高度宽度)。halfboolFalse支持FP16(半精度)量化减少模型尺寸并可能加快对支持硬件的推理。dynamicboolFalse允许ONNX和TensorRT导出的动态输入大小增强处理不同图像尺寸的灵活性。simplifyboolFalse简化ONNX导出的模型图潜在地提高性能和兼容性。 其中dynamic与imgsz不兼容dynamic与half不兼容。 我们将分别对这几个选项的不同组合进行对比测试分辨率都采用640。共包括以下模型 设置代码默认model.export(format‘onnx’, imgsz640)dynamicmodel.export(format‘onnx’, dynamicTrue)simplifymodel.export(format‘onnx’, simplifyTrue, imgsz640)simplify和dynamicmodel.export(format‘onnx’, simplifyTrue, dynamicTrue)halfmodel.export(format‘onnx’, halfTrue, imgsz640)simlify和halfmodel.export(format‘onnx’, simplifyTrue, halfTrue, imgsz640) 测试结果 对不同设置的模型进行行空板USB摄像头的视频物体检测测试结果如下 模型大小simplifyhalfdynamicimgsz帧率YOLOv10n8.99MB×××6400.3029YOLOv10n8.86MB××√×0.3002YOLOv10n8.95MB√××6400.3009YOLOv10n8.95MB√×√×0.3011YOLOv10n8.99MB×√×6400.2999YOLOv10n8.95MB√√×6400.3017 分析 通过测试结果的统计可以分析得到以下特点 dynamic设置可以略微减小模型大小也会略微降低运行速度simplify也可以略微减小模型大小但极不显著也会略微降低运行速度如果simplify和dynamic同时开启不如值开启dynamic在模型尺寸上减少的明显half设置并没有速度上的提升反而有降低这是因为行空板没有半精度优化的硬件支持。 小结 如果能事先知道输入图片的尺寸就不要使用任何参数设置只用imgsz设置图片尺寸如果实现不知道图片输入的尺寸就使用dynamicTrue不要设置halfTrue和simplifyTrue 不同尺寸输入的表现对比 yolo的测试结果 模型模型大小dynamicimgsz帧率YOLOv10n8.99MB×6400.30YOLOv10n8.91MB×4480.59YOLOv10n8.87MB×3201.07YOLOv10n8.86MB×2561.70YOLOv10n8.84MB×1285.01YOLOv8n12.2MB×6400.26YOLOv8n12.1MB√4480.53YOLOv8n12.1MB√3200.99YOLOv8n12.0MB√2561.59YOLOv8n12.0MB√1284.80YOLOv8n12.0MB√649.17 分析 可以看出随着输入尺寸的减小帧率显著提高。 yolov10n的帧率比yolov8n略高10%左右同时模型大小减少25%。 小结 对于视频检测在行空板上以128的分辨率运行勉强可以使用建议选择yolov10n相较v8内存占用和速度方面都有优势。 Mediapipe视频物体检测 设置 针对Mediapipe中的三个模型我们分别测试了非量化和int8量化下的不同分辨率。 分辨率包括 640、448、320、256、128 测试结果 模型\分辨率64044832025612864efficientdet_lite00.420.420.420.420.420.43efficientdet_lite0_int80.850.850.850.850.850.86efficientdet_lite20.130.130.130.130.130.13efficientdet_lite2_int80.270.270.270.270.270.27ssd_mobilenet_v20.610.610.610.610.610.61ssd_mobilenet_v2_int80.610.610.610.610.610.62 小结 与图片的目标检测结果类似不同的分辨率对这些模型而言没有影响对于efficientdet_lite0和efficientdet_lite2int8量化可以显著提速int8量化对于ssd_mobilenet_v2没有影响 视频物体检测总结 我们在统计测试后发现了以下特点 yolo系列随着图片分辨率下调检测耗时显著减少而Mediapipe不明显。这说明在小分辨率图片检测中yolo系列有显著的速度优势det的两个模型进行int8量化之后速度显著提升几乎不会损失准确性Mediapipe的模型在较大分辨率的时候相比yolo有显著的速度优势但是准确性略低一点。在应用的时候需要在准确性和速度上进行权衡。 模型选择建议 限于视频帧率问题我们认为最多使用320分辨率使帧率达到1如果物体较近或者较大在低分辨率图片上也可以方便地提取特征这种情况下推荐使用较低分辨率而速度较快的模型如64帧率的yolov8n如果物体较远或者物体较小则需要分辨率更高才能提取到足够的特征这种情况下推荐选择yolov10n。如果需要更高分辨率的图片而且可以接收帧率较低可以采用ssd_mobilenet_v2.tflite模型。可以参考下面的流程来选取模型 附录 使用yolov10n视频检测的代码 行空板USB摄像头使用yolov10n进行物体检测的代码代码如下 import cv2 import numpy as np import onnxruntime as ort import yaml import time def preprocess(frame, input_size):#这里的resize使用nearest可以提速大约0.3-0.5帧image cv2.resize(frame, input_size,interpolationcv2.INTER_NEAREST)# 转换图片到数组image_data np.array(image).transpose(2, 0, 1) # 转换成CHWimage_data image_data.astype(np.float32)image_data / 255.0 # 归一化image_data np.expand_dims(image_data, axis0) # 增加batch维度return image_datadef postprocess(output, image, input_size, show_size, classes):for detection in output:x1, y1, x2, y2, conf , class_id detectionif conf 0.4:x1 int(x1 / input_size[0] * show_size[0])x2 int(x2 / input_size[0] * show_size[0])y1 int(y1 / input_size[1] * show_size[1])y2 int(y2 / input_size[1] * show_size[1])class_id int(class_id) cv2.rectangle(image, (x1, y1), (x2, y2), (255, 0, 0), 2) # 画框class_name classes[class_id]cv2.putText(image, class_name, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)return imagedef main():input_size (128, 128)with open(ultralytics/cfg/datasets/coco.yaml, r, encodingutf-8) as f:data yaml.safe_load(f)classes data[names]window_name FullScreen Imagecv2.namedWindow(window_name, cv2.WINDOW_NORMAL) cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)# 加载模型session ort.InferenceSession(yolov10n.onnx)input_name session.get_inputs()[0].name# 打开摄像头。cap cv2.VideoCapture(0)if not cap.isOpened():print(Cannot open camera)exit()prev_time 0while True:ret, frame cap.read()show_size [320,240]if not ret:print(Cant receive frame (stream end?). Exiting …)breakcurrent_time time.time()# 预处理图像input_tensor preprocess(frame, input_size)# 进行推理outputs session.run(None, {input_name: input_tensor})output outputs[0][0]# 后处理show_image postprocess(output, frame, input_size, show_size, classes)fps 1.0 / (current_time - prev_time)prev_time current_time # 更新前一帧的时间cv2.putText(show_image, fFPS: {fps:.2f}, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)# 显示结果cv2.imshow(window_name, show_image)if cv2.waitKey(1) ord(q):break# 释放资源cap.release()cv2.destroyAllWindows()if name main:main()使用Mediapipe视频检测的代码 行空板USB摄像头使用Mediapipe进行物体检测的代码代码如下 import numpy as np import mediapipe as mp from mediapipe.tasks import python from mediapipe.tasks.python import vision import cv2 import timeinput_size (640,640)
STEP 1: Import the necessary modules.
base_options python.BaseOptions(model_asset_pathefficientdet_lite0.tflite) options vision.ObjectDetectorOptions(base_optionsbase_options,score_threshold0.5) detector vision.ObjectDetector.create_from_options(options)# STEP 2: Create an ObjectDetector object. MARGIN 10 # pixels ROW_SIZE 10 # pixels FONT_SIZE 1 FONT_THICKNESS 1 TEXT_COLOR (255, 0, 0) # reddef visualize(image, detection_result) - np.ndarray:Draws bounding boxes on the input image and return it.Args:image: The input RGB image.detection_result: The list of all Detection entities to be visualize.Returns:Image with bounding boxes.for detection in detection_result.detections:# Draw bounding_boxbbox detection.bounding_boxstart_point bbox.origin_x, bbox.origin_yend_point bbox.origin_x bbox.width, bbox.origin_y bbox.heightcv2.rectangle(image, start_point, end_point, TEXT_COLOR, 3)# Draw label and scorecategory detection.categories[0]category_name category.category_nameprobability round(category.score, 2)result_text category_name ( str(probability) )text_location (MARGIN bbox.origin_x,MARGIN ROW_SIZE bbox.origin_y)cv2.putText(image, result_text, text_location, cv2.FONT_HERSHEY_PLAIN,FONT_SIZE, TEXT_COLOR, FONT_THICKNESS)return image# STEP 3: Initialize the video capture from the webcam. cap cv2.VideoCapture(0) prev_time 0while cap.isOpened():ret, frame cap.read()if not ret:breakframe cv2.resize(frame, input_size, interpolationcv2.INTER_NEAREST)# Convert the frame to the format required by MediaPipe.image mp.Image(image_formatmp.ImageFormat.SRGB, dataframe)# STEP 4: Detect objects in the frame.detection_result detector.detect(image)# STEP 5: Process the detection result. In this case, visualize it.annotated_frame visualize(frame, detection_result)# Calculate and display the frame ratecurrent_time time.time()fps 1 / (current_time - prev_time)prev_time current_timefps_text fFPS: {fps:.2f}print(fps_text)cv2.putText(annotated_frame, fps_text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)cv2.imshow(Object Detection, annotated_frame)# Break the loop if the user presses q.if cv2.waitKey(1) 0xFF ord(q):break# Release the resources. cap.release() cv2.destroyAllWindows()
- 上一篇: php访问网站广东省企业信用信息网
- 下一篇: php建站软件什么网站做污水处理药剂的好
相关文章
-
php访问网站广东省企业信用信息网
php访问网站广东省企业信用信息网
- 站长
- 2026年02月17日
-
php调用网站外国做爰网站
php调用网站外国做爰网站
- 站长
- 2026年02月17日
-
php钓鱼网站开发想找个人做网站
php钓鱼网站开发想找个人做网站
- 站长
- 2026年02月17日
-
php建站软件什么网站做污水处理药剂的好
php建站软件什么网站做污水处理药剂的好
- 站长
- 2026年02月17日
-
php开发网站的优势网站右边上下浮动代码
php开发网站的优势网站右边上下浮动代码
- 站长
- 2026年02月17日
-
PHP开源网站开发系统设计公司怎么接业务
PHP开源网站开发系统设计公司怎么接业务
- 站长
- 2026年02月17日
