今天刚刚开始学习,跟着文档将代码运行了一遍,也报名了比赛。自己对代码的理解还是不够,有很多部分是看不懂的,还需要不断地去学习。
因为自己没什么深度学习的代码基础,所以很难理解代码中的细节,需要更多的去学习。不过好在有baseline能够直接一键运行,起码给出一些正向反馈。
针对YOLO这个库,是我第一次了解对于我而言有挺大的挑战的。看了训练营中的教程对YOLO有了一个简单的了解,运行它的代码对我来说并不是什么很难的事情,但是想要做一些改变看看到底能怎么提升代码的效率和评分。
我自己实际动手写了一段很简单的YOLO实例,以便于我更加深入的了解YOLO。
import cv2
import numpy as np
# 加载YOLO模型
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
# 加载类别标签
with open("coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
# 读取图像
img = cv2.imread("image.jpg")
height, width, channels = img.shape
# 创建blob并进行前向传播
blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
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] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)
x = int(center_x - w / 2)
y = int(center_y - h / 2)
boxes.append([x, y, w, h])
confidences.append(float(confidence))
class_ids.append(class_id)
# 非极大值抑制
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
# 绘制检测结果
for i in range(len(boxes)):
if i in indexes:
x, y, w, h = boxes[i]
label = str(classes[class_ids[i]])
confidence = confidences[i]
color = (0, 255, 0)
cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)
cv2.putText(img, f"{label} {confidence:.2f}", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
# 显示结果图像
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
参加这个训练营,我希望可以对人工智能的理解更深一点。之前只是单纯对人工智能有些了解,但是只会一些基本的算法,并没有涉及到具体的应用层面。
1442

被折叠的 条评论
为什么被折叠?



