Ask Your Question

Num's profile - activity

2020-05-24 05:00:54 -0600 commented answer np.argmax returns 0 always

Omg, you are right.. Im so happy thank you!

2020-05-24 05:00:40 -0600 received badge  Supporter (source)
2020-05-24 05:00:39 -0600 marked best answer np.argmax returns 0 always

To determine the class name of the detected object, I need to get the class_id of the image. The problem is, np.argmax always returns 0 and gets the first class name. When I detect another object, it should print class_id 1 but it prints 0 and I can't get the proper label name to display.

When I look at my .txt files, I see this:

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]]
        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)

How I labeled my image: This is how I labeled the images

The result after training: This is the result that i get

In the result you can see that I dont see the label of the iphone and the rectangle is way above than I have selected. The airpods are also way bigger and samsung is at the bottom, which I didn't select like this.

2020-05-24 05:00:39 -0600 received badge  Scholar (source)
2020-05-23 04:57:06 -0600 commented answer np.argmax returns 0 always

Can you check my edit?

2020-05-22 10:57:16 -0600 edited answer np.argmax returns 0 always

@berak, I solved this problem. It was my fault, I did wrong string formatting when I started training it with darknet. I

2020-05-22 10:50:44 -0600 commented answer np.argmax returns 0 always

Check my edit

2020-05-22 10:50:36 -0600 edited question np.argmax returns 0 always

np.argmax returns 0 always To determine the class name of the detected object, I need to get the class_id of the image.

2020-05-22 10:50:36 -0600 received badge  Editor (source)
2020-05-22 09:16:34 -0600 commented question np.argmax returns 0 always

@berak, I solved this problem. It was my fault, I did wrong string formatting when I started training it with darknet. I

2020-05-22 07:52:59 -0600 received badge  Enthusiast
2020-05-16 09:26:33 -0600 commented question np.argmax returns 0 always

Yes, I have NMS included but I commented it out right now.

2020-05-16 05:28:41 -0600 commented question np.argmax returns 0 always

Any other idea maybe?

2020-05-16 03:58:08 -0600 commented question np.argmax returns 0 always

Yes, I trained my model on google colab for a few hours. When I had minimal loss, like 0.3 I stopped it with running. Wh

2020-05-16 03:57:54 -0600 commented question np.argmax returns 0 always

Yes, I trained my model on google colab for a few hours. When I had minimal loss, like 0.3 I stopped it with running. Wh

2020-05-16 03:57:44 -0600 commented question np.argmax returns 0 always

Yes, I trained my model on google colab for a few hours. When I had minimal loss, like 0.3 I stopped it with running. Wh

2020-05-16 03:55:31 -0600 commented question np.argmax returns 0 always

Yes, I trained my model on google colab for a few hours. When I had minimal loss, like 0.3 I stopped it with running. Wh

2020-05-16 03:55:05 -0600 commented question np.argmax returns 0 always

Yes, I trained my model on google colab for a few hours. When I had minimal loss, like 0.3 I stopped it with running. Wh

2020-05-16 03:54:53 -0600 commented question np.argmax returns 0 always

Yes, I trained my model on google colab for a few houres. When I had minimal loss, like 0.3 I stopped it with running. W

2020-05-15 08:54:10 -0600 asked a question np.argmax returns 0 always

np.argmax returns 0 always To determine the class name of the detected object, I need to get the class_id of the image.