关于Yolov7测试后不会描框的解决办法!

项目场景:

关于Yolov7测试后不会描框的解决办法!


问题描述

对于输出结果的图片没有框这个问题困扰我很久,同时也搜寻了很多解决方法但都没有用,附上解决方法~

目前的情况就是,使用CPU没问题,可以正常描框,GPU就不行
在这里插入图片描述
显示是成功的,但是图片是不行的
在这里插入图片描述


解决方案:

修改detect.py代码即可

在这里插入图片描述
将原来detect.py文件中的31行half = device.type != 'cpu' # half precision only supported on CUDA注释
换成half = False,然后保存,再次运行,即可!

在这里插入图片描述

  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
yolov7中的跨取消(cross-box elimination)是一种用于去除重复检测的技术。在yolov7中,跨取消是通过计算两个边界之间的IoU(交并比)来完成的。如果两个边界之间的IoU大于一定的阈值,则将IoU较小的边界删除。这个阈值可以通过调整来控制跨取消的严格程度。 要在yolov7中实现跨取消,可以按照以下步骤进行操作: 1.在yolov7的配置文件中,找到nms_kind参数,并将其设置为diou,这将启用跨取消。 2.在配置文件中,找到nms_threshold参数,并将其设置为跨取消的IoU阈值。通常情况下,这个值可以设置为0.6或0.7。 3.运行yolov7模型进行预测时,跨取消将自动应用于检测结果中。 下面是一个示例代码,展示了如何在yolov7中使用跨取消: ```python import cv2 import numpy as np # 加载yolov7模型 net = cv2.dnn.readNet("yolov7.weights", "yolov7.cfg") # 加载类别标签 classes = [] with open("coco.names", "r") as f: classes = [line.strip() for line in f.readlines()] # 加载测试图像 img = cv2.imread("test.jpg") # 将图像转换为blob格式 blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False) # 将blob输入到yolov7模型中进行预测 net.setInput(blob) outs = net.forward(net.getUnconnectedOutLayersNames()) # 解析预测结果 class_ids = [] confidences = [] boxes = [] for out in outs: for detection in out: scores = detection[5:] class_id = np.argmax(scores) confidence = scores[class_id] if confidence > 0.5: center_x = int(detection[0] * img.shape[1]) center_y = int(detection[1] * img.shape[0]) w = int(detection[2] * img.shape[1]) h = int(detection[3] * img.shape[0]) x = center_x - w // 2 y = center_y - h // 2 class_ids.append(class_id) confidences.append(float(confidence)) boxes.append([x, y, w, h]) # 应用跨取消 indices = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.6) # 绘制检测结果 for i in indices: i = i[0] box = boxes[i] x = box[0] y = box[1] w = box[2] h = box[3] cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) cv2.putText(img, classes[class_ids[i]], (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 显示检测结果 cv2.imshow("Output", img) cv2.waitKey(0) cv2.destroyAllWindows() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一个不会射日的后羿

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

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

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

打赏作者

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

抵扣说明:

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

余额充值