Fix for the case where there are no detections #9784
Conversation
example/ssd/detect/detector.py
Outdated
@@ -43,6 +43,7 @@ class Detector(object): | |||
ctx : mx.ctx | |||
device to use, if None, use mx.cpu() as default context | |||
""" | |||
CLASS = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this convention used elsewhere? All caps, word 'CLASS', etc?
Is it used somewhere? Can you name it something that isn't a keyword else and not in caps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KLASS? constants should be in caps according to python style (pep8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL."
This is at class-level, right? Would a derivative not want to override the value?
Is this done elsewhere? I haven't seen thyis done within classes elsewhere, but maybe I'm wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is at class level, is the equivalent of a static variable (in this case constant) in C++. A variable that is owned by the class itself, instead of the instance. Since it's a constant is in caps. I don't see a problem, other than perhaps the naming. So the variable refers to which class the object belongs to. class is a reserved identifier in python as you mention, and you indicate that having a reserved word just differing by the case might not be good. I don't see a problem, in any case we could rename it to KLASS or CLS as is done usually in python. Maybe @zhreshold has additional comments anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that you mean it for class-level.
Again, question:
"Would a derivative not want to override the value?
Is this done elsewhere (all-caps constant within a class)? I haven't seen this done within classes elsewhere, but maybe I'm wrong?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use cls_index=0 as default argument when instantiating rather than class level static variable
example/ssd/detect/detector.py
Outdated
result = [] | ||
det = detections[i, :, :] | ||
for obj in det: | ||
if obj[Detector.CLASS] >= 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a class somewhere with 'CLASS" defined as something other than zero?
example/ssd/detect/detector.py
Outdated
:param detections: | ||
:return: | ||
""" | ||
print(type(detections)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove print?
example/ssd/detect/detector.py
Outdated
:return: | ||
""" | ||
print(type(detections)) | ||
assert((type(detections) is mx.nd.NDArray) or (type(detections) is np.ndarray)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use isinstance
Use cv2.cvtColor instead of np to convert from BGR 2 RGB Fix context in detector
result = [] | ||
det = detections[i, :, :] | ||
for obj in det: | ||
if obj[class_idx] >= 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about self.class_idx with default 0 in __init__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not possible, the method is static. That's why there was a class variable on the first place when the review started. Seems we are going in circles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to use member function rather than static. Is there any specific reason we can't do it? Or it just serves as better self-explained code?
Anyways, I don't bother overcomplicating such a simple class, either way LGTM and I am just trying to settle it down quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter_positive_detections doesn't need any member data, it's a pure function, reflected by @staticmethod so one knows that is not going to mutate class state. Anyway, maybe is my pedantic defensive programming from other safer programming languages, in Python seems everyone codes however they want.
Is there a class somewhere with 'class_idx" defined as something other than zero? |
@cjolivier01 no, what's your point? its intention is semantic. instead of just using a 0 index which is not clear what it contains. |
@cjolivier01 any more changes? can we merge this? |
Where do the other non-zero numbers which index into detections[] come from? |
What is in the 0th index that makes it special? What guarantees that nothing else will try to use zero? |
If it's just a standin for zero, why is it called class_idx? |
It's the output of the model: class, score, and normalized bounding box coordinates. You could have also the other indices named for better readability. That function only uses the class to filter negative detections which output -1. |
Hi, the community has passed to vote about associating the code changes with JIRA (https://lists.apache.org/thread.html/ab22cf0e35f1bce2c3bf3bec2bc5b85a9583a3fe7fd56ba1bbade55f@%3Cdev.mxnet.apache.org%3E) We have updated the guidelines for contributors in https://cwiki.apache.org/confluence/display/MXNET/Development+Process, please ensure that you have created a JIRA at https://issues.apache.org/jira/projects/MXNET/issues/ to describe your work in this pull request and include the JIRA title in your PR as [MXNET-xxxx] your title where MXNET-xxxx is the JIRA id Thanks! |
@cjolivier01 @zhreshold is this good to merge ? |
Use cv2.cvtColor instead of np to convert from BGR 2 RGB Fix context in detector
Use cv2.cvtColor instead of np to convert from BGR 2 RGB Fix context in detector
Use cv2.cvtColor instead of np to convert from BGR 2 RGB
Fix context in detector
Description
(Brief description on what this PR is about)
Checklist
Essentials
make lint
)Changes
Comments