Yolo不改包代码关闭控制台推理日志

在预测的参数列表里加上verbose=False结即可关闭控制台输出日志

model.predict(source=color_image,show=True,verbose=False)
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Python和OpenCV库实现YOLO算法的推理代码示例: ```python import cv2 import numpy as np # 加载类别标签 classes = [] with open("coco.names", "r") as f: classes = [line.strip() for line in f.readlines()] # 加载模型配置和权重 net = cv2.dnn.readNet("yolov3.cfg", "yolov3.weights") # 获取输出层 layer_names = net.getLayerNames() output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()] # 加载图像 img = cv2.imread("img.jpg") # 把图像转换为blob blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False) # 将blob输入到神经网络中 net.setInput(blob) # 进行前向传递 outs = net.forward(output_layers) # 处理输出层 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]) width = int(detection[2] * img.shape[1]) height = int(detection[3] * img.shape[0]) left = center_x - width // 2 top = center_y - height // 2 class_ids.append(class_id) confidences.append(float(confidence)) boxes.append([left, top, width, height]) # 应用非极大值抑制 indices = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) # 绘制检测结果 for i in indices: i = i[0] box = boxes[i] left = box[0] top = box[1] width = box[2] height = box[3] cv2.rectangle(img, (left, top), (left+width, top+height), (0, 255, 0), 2) label = f"{classes[class_ids[i]]}: {confidences[i]:.2f}" cv2.putText(img, label, (left, top - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 显示结果 cv2.imshow("Result", img) cv2.waitKey(0) cv2.destroyAllWindows() ``` 其中,`coco.names` 文件是类别标签文件,`yolov3.cfg` 和 `yolov3.weights` 分别是YOLOv3算法的配置文件和权重文件。将它们放在与代码同一目录下即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值