我正在尝试使用 YoloV4 和 Darknet 在 python 中检测图像中的对象。问题是它没有检测到图像中的任何物体。这是我的代码:
configPath = "./cfg/yolov4.cfg"
weightPath = "./yolov4.weights"
metaPath = "./cfg/coco.data"
netMain = darknet.load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1)
metaMain = darknet.load_meta(metaPath.encode("ascii"))
altNames = None
try:
with open(metaPath) as metaFH:
metaContents = metaFH.read()
import re
match = re.search("names *= *(.*)$", metaContents, re.IGNORECASE | re.MULTILINE)
if match:
result = match.group(1)
else:
result = None
try:
if os.path.exists(result):
with open(result) as namesFH:
namesList = namesFH.read().strip().split("\n")
altNames = [x.strip() for x in namesList]
except TypeError:
pass
except Exception:
pass
frame_width = darknet.network_width(netMain)
frame_height = darknet.network_height(netMain)
frame = cv2.imread("b.jpg")
darknet_image = darknet.make_image(frame_width, frame_height, 3)
darknet.copy_image_from_bytes(darknet_image, frame.tobytes())
detections = darknet.detect_image(netMain, metaMain, darknet_image, thresh=0.25)
print(detections) #returns []
程序打印“[]”。图像(“b.jpg”)为 764x756。