当前位置: 首页 > news >正文

YOLOv8可视化predict预测阶段如何调整标签框大小

步骤

  • 新建Python文件
  • 全部可选参数
  • 修改标签名称大小
  • 结果展示

新建Python文件

并添加line_width参数输入合适的int数值

from ultralytics import YOLO# Load a pretrained YOLOv8n model
model = YOLO("path/to/your/model.pt")# Run inference on 'bus.jpg' with arguments
model.predict("path/to/your/image.jpg", show_labels=True, save=True, line_width=2)

全部可选参数

Inference arguments:

ArgumentTypeDefaultDescription
sourcestr'ultralytics/assets'Specifies the data source for inference. Can be an image path, video file, directory, URL, or device ID for live feeds. Supports a wide range of formats and sources, enabling flexible application across different types of input.
conffloat0.25Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives.
ioufloat0.7Intersection Over Union (IoU) threshold for Non-Maximum Suppression (NMS). Lower values result in fewer detections by eliminating overlapping boxes, useful for reducing duplicates.
imgszint or tuple640Defines the image size for inference. Can be a single integer 640 for square resizing or a (height, width) tuple. Proper sizing can improve detection accuracy and processing speed.
halfboolFalseEnables half-precision (FP16) inference, which can speed up model inference on supported GPUs with minimal impact on accuracy.
devicestrNoneSpecifies the device for inference (e.g., cpu, cuda:0 or 0). Allows users to select between CPU, a specific GPU, or other compute devices for model execution.
max_detint300Maximum number of detections allowed per image. Limits the total number of objects the model can detect in a single inference, preventing excessive outputs in dense scenes.
vid_strideint1Frame stride for video inputs. Allows skipping frames in videos to speed up processing at the cost of temporal resolution. A value of 1 processes every frame, higher values skip frames.
stream_bufferboolFalseDetermines if all frames should be buffered when processing video streams (True), or if the model should return the most recent frame (False). Useful for real-time applications.
visualizeboolFalseActivates visualization of model features during inference, providing insights into what the model is “seeing”. Useful for debugging and model interpretation.
augmentboolFalseEnables test-time augmentation (TTA) for predictions, potentially improving detection robustness at the cost of inference speed.
agnostic_nmsboolFalseEnables class-agnostic Non-Maximum Suppression (NMS), which merges overlapping boxes of different classes. Useful in multi-class detection scenarios where class overlap is common.
classeslist[int]NoneFilters predictions to a set of class IDs. Only detections belonging to the specified classes will be returned. Useful for focusing on relevant objects in multi-class detection tasks.
retina_masksboolFalseUses high-resolution segmentation masks if available in the model. This can enhance mask quality for segmentation tasks, providing finer detail.
embedlist[int]NoneSpecifies the layers from which to extract feature vectors or embeddings. Useful for downstream tasks like clustering or similarity search.

Visualization arguments:

ArgumentTypeDefaultDescription
showboolFalseIf True, displays the annotated images or videos in a window. Useful for immediate visual feedback during development or testing.
saveboolFalseEnables saving of the annotated images or videos to file. Useful for documentation, further analysis, or sharing results.
save_framesboolFalseWhen processing videos, saves individual frames as images. Useful for extracting specific frames or for detailed frame-by-frame analysis.
save_txtboolFalseSaves detection results in a text file, following the format [class] [x_center] [y_center] [width] [height] [confidence]. Useful for integration with other analysis tools.
save_confboolFalseIncludes confidence scores in the saved text files. Enhances the detail available for post-processing and analysis.
save_cropboolFalseSaves cropped images of detections. Useful for dataset augmentation, analysis, or creating focused datasets for specific objects.
show_labelsboolTrueDisplays labels for each detection in the visual output. Provides immediate understanding of detected objects.
show_confboolTrueDisplays the confidence score for each detection alongside the label. Gives insight into the model’s certainty for each detection.
show_boxesboolTrueDraws bounding boxes around detected objects. Essential for visual identification and location of objects in images or video frames.
line_widthNone or intNoneSpecifies the line width of bounding boxes. If None, the line width is automatically adjusted based on the image size. Provides visual customization for clarity.

修改标签名称大小

寻找自己文件目录下的ultralytics/ultralytics/utils/plotting.py
Ctrl+F打开查找搜索annotator

annotator = Annotator(mosaic, line_width=round(fs / 10), font_size=10, pil=True, example=names)

font_size修改到合适尺寸的数值

结果展示

修改前

在这里插入图片描述
修改后

在这里插入图片描述


http://www.mrgr.cn/news/17912.html

相关文章:

  • Web3与AI的融合:开启去中心化应用的新纪元
  • 引发new/malloc动态申请内存失败的常见原因分析与总结
  • 一文搞懂 JavaScript 模块化规范:CommonJS、AMD、ES6 Module
  • PMP核心知识点—之项目运行环境
  • 电路基础 ---- 反馈
  • TCP/IP 报文传输过程
  • 安卓13 鼠标右键作返回键,鼠标事件修改
  • 软件供应链安全管理实践之麒麟软件
  • 从英文命名理解Spring事务传播机制@Transactional解释
  • 量子运算-计算新时代的开端
  • 大模型工作交互过程
  • C++基础知识(四)
  • Python入门了解(一)
  • eureka一
  • 再获认可!海云安荣登2024中国网络安全市场100强榜单
  • 【类模板】类模板的基本范式
  • 超越卷积滤波器,HyCoT利用Transformer捕捉高光谱图像的全局依赖性 !
  • leetcode209. Minimum Size Subarray Sum
  • Spring扩展点系列-InstantiationAwareBeanPostProcessor
  • 原码 / 反码 / 补码的介绍及认知