Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scores <0.5 when single class detection. #195

Open
Ludwig-Zh opened this issue Mar 6, 2020 · 3 comments
Open

Scores <0.5 when single class detection. #195

Ludwig-Zh opened this issue Mar 6, 2020 · 3 comments

Comments

@Ludwig-Zh
Copy link

Hi,

I have tried to detect a single class (car ) data in VOC format.
So I changed voc2012.names to single line to generate new tfrecord data:
"car"
And changed the flags define in train.py and detect.py like below:
" flags.DEFINE_integer('num_classes', 1, 'number of classes in the model')"
Training is ok, but when I use detect.py to inference,I got the answer like this:

"I0306 13:48:14.657661 140508698953536 detect.py:56] time: 7.611089706420898
I0306 13:48:14.658213 140508698953536 detect.py:58] detections:
I0306 13:48:14.672537 140508698953536 detect.py:62] car, 0.4999775290489197, [0.17678313 0.30110145 0.30877244 0.56212616]
I0306 13:48:14.676712 140508698953536 detect.py:62] car, 0.4999728798866272, [0.34846273 0.47863787 0.48382244 0.8014421 ]
I0306 13:48:14.681894 140508698953536 detect.py:62] car, 0.49983859062194824, [0.40488383 0.14127088 0.48221472 0.30515537]
I0306 13:48:14.686771 140508698953536 detect.py:62] car, 0.49938303232192993, [0.04897165 0.06757799 0.12495686 0.19713354]
I0306 13:48:14.691031 140508698953536 detect.py:62] car, 0.49914953112602234, [0.17951395 0.02865338 0.24622466 0.1438287 ]
"
Obviously, the bboxes are all ok, but the scores are all below 0.5, so I debug the code:
"scores = confidence * class_probs" in models.py
"confidence" is very much close to 1, but "class_probs" is below 0.5 all the way.

So I'm confused.Is there anything wrong with my test?I run this code in tensorflow==2.10 by PyCharm.Inference by pretrained coco weights is fine.

Any one can give some advise?
Thx a lot!

@zazeng
Copy link

zazeng commented Mar 9, 2020

If you are outputting 2 probabilities from your network can you try a softmax instead of sigmoid for your class_probs? Alternatively, return class_probs as logits(no activation function) from yolo_boxes and set from_logits=True in sparse_categorical_crossentropy. You will have to softmax your class output (o[2]) in yolo_nms if you choose to do the latter.

@Ludwig-Zh
Copy link
Author

If you are outputting 2 probabilities from your network can you try a softmax instead of sigmoid for your class_probs? Alternatively, return class_probs as logits(no activation function) from yolo_boxes and set from_logits=True in sparse_categorical_crossentropy. You will have to softmax your class output (o[2]) in yolo_nms if you choose to do the latter.

ye,I tried to replace tf.sigmoid by tf.nn.softmax, I think it works well for both 1-class and 2-classes detection. But I guess softmax will decrase the class scores when detect a "multi-label" target, and will make FLAG "yolo_score_threshold" undecidable.

@krxat
Copy link
Contributor

krxat commented May 22, 2020

@Ludwig-Zh Refer to #70 here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants