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

RSDK-6381 - Add optional label renaming to detection transform camera #3538

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kharijarrett
Copy link
Member

No description provided.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Feb 5, 2024
@kharijarrett kharijarrett requested a review from bhaney February 12, 2024 19:05
Copy link
Member

@bhaney bhaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few changes I'd like you to do, as well as some extra things:

  1. Can you also create the post-processor for classifiers. It's essentially the same code, and it would extremely frustrating for someone switching between using a classifier and a detector if sometimes the relabeling worked, and sometimes not.
  2. Can you add tests to both the classifier and detector re-label function
  3. Can you confirm that it works on detectors by trying it out manually

DetectorName string `json:"detector_name"`
ConfidenceThreshold float64 `json:"confidence_threshold"`
ValidLabels []string `json:"valid_labels"`
LabelRenamer map[string]string `json:"label_renamer,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by making the field an agent noun, it makes it seem to me like the config requires a function- I would prefer a name like "rename_labels"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay done.

// NewLabelRenamer renames the labels in the input map from the key to the value.
func NewLabelRenamer(labels map[string]string) Postprocessor {
return func(in []Detection) []Detection {
if len(labels) < 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned today that you can call len() on a nil map and it will not panic - thanks for this

for oldL, newL := range labels {
for i, d := range in {
if strings.HasPrefix(strings.ToLower(d.Label()), strings.ToLower(oldL)) {
in[i] = NewDetection(*d.BoundingBox(), d.Score(), newL)
Copy link
Member

@bhaney bhaney Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also modifies the input slice that was fed into the function, and I don't think you want to do that. You should make a new output slice and put the NewDetections in that, and then return "out".

Comment on lines +61 to +62
for oldL, newL := range labels {
for i, d := range in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike the fact that you have to iterate over the entire map every time, but I understand due to the prefix matching that you have to. I suggest an alternative though, because I think ALWAYS mapping to a prefix can cause problems (e.g. if my detector knows about "car" or "carrot" or "carnations" it will catch all of them even if I just wanted to replace "car")

The alternative:

  • if there is a * at the end of the key in the label map, then you do a prefix match
  • fi there is no * at the end of the key in the label map, you do an exact match

When first defining NewLabelRenamer, you split the map into two maps, the exact matcher map, and the prefix matcher map. Then you don't have to iterate over all of the labels all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants