Python np.argmax始终返回0

Python np.argmax始终返回0,python,opencv,yolo,Python,Opencv,Yolo,要确定检测到的对象的类名,我需要获取图像的class_id。问题是,np.argmax始终返回0并获取第一个类名。当我检测到另一个对象时,它应该打印class_id 1,但它打印0,并且我无法获得要显示的正确标签名称 当我查看.txt文件时,我看到: 0 0.170103 0.449807 0.319588 0.521236 1 0.266791 0.148936 0.496269 0.287234 2 0.265464 0.422780 0.510309 0.420849 我有一个类似

要确定检测到的对象的类名,我需要获取图像的class_id。问题是,np.argmax始终返回0并获取第一个类名。当我检测到另一个对象时,它应该打印class_id 1,但它打印0,并且我无法获得要显示的正确标签名称

当我查看.txt文件时,我看到:


0 0.170103 0.449807 0.319588 0.521236

1 0.266791 0.148936 0.496269 0.287234

2 0.265464 0.422780 0.510309 0.420849

我有一个类似的问题你有解决方案吗?我有一个类似的问题你有解决方案吗?
def detect_img(self, img):
    blob = cv2.dnn.blobFromImage(img, 0.00392 ,(416,416), (0,0,0), True, crop=False)
    input_img = self.net.setInput(blob)
    output = self.net.forward(self.output)

    height, width, channel = img.shape
    boxes = []
    trusts = []
    class_ids = []

    for out in output:
        for detect in out:
            total_scores = detect[5:]
            class_id = np.argmax(total_scores)
            print(np.argmax(detect))
            trust_factor = total_scores[class_id]
            if trust_factor > 0.2:
                x_center = int(detect[0] * width)
                y_center = int(detect[1] * height)
                w = int(detect[2] * width)
                h = int(detect[3] * height)
                x = int(x_center - w / 2)
                y = int(x_center - h / 2)
                boxes.append([x,y,w,h])
                trusts.append(float(trust_factor))
                class_ids.append(class_id)

    for index in range(len(boxes)):
        # if index in indexes:
        x,y,w,h = boxes[index]
        label = self.classes[class_ids[index]]
        # always self.classes[0], self.classes=['samsung','iphone'] so result is always samsung
        trust = round(trusts[index], 2)
        text = f"{label}, Trust: {trust}"
        cv2.rectangle(img, (x,y), (x + w, y + h), (0,255,0), 2)
        cv2.putText(img, text, (x - 20, y + 40), cv2.FONT_HERSHEY_PLAIN, 1, (0,0,255), 2)