-
Notifications
You must be signed in to change notification settings - Fork 111
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,25 @@ func NewLabelFilter(labels map[string]interface{}) Postprocessor { | |
} | ||
} | ||
|
||
// 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return in | ||
} | ||
|
||
for oldL, newL := range labels { | ||
for i, d := range in { | ||
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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. |
||
if strings.HasPrefix(strings.ToLower(d.Label()), strings.ToLower(oldL)) { | ||
in[i] = NewDetection(*d.BoundingBox(), d.Score(), newL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". |
||
} | ||
} | ||
} | ||
|
||
return in | ||
} | ||
} | ||
|
||
// SortByArea returns a function that sorts the list of detections by area (largest first). | ||
func SortByArea() Postprocessor { | ||
return func(in []Detection) []Detection { | ||
|
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.
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"
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.
Okay done.