Skip to content

Commit

Permalink
Tweaking the parameter for the label mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
marcverhagen committed May 2, 2024
1 parent 57e3eec commit 3f8e1fa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
36 changes: 28 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,32 @@ def _configure_postbin(self):
Note that the labels cannot have colons in them, but historically we did have
colons in the SWT annotation for subtypes of "slate". Syntactically, we cannot
have mappings like S:H:slate. This here assumes the mapping is S_H:slate and
have mappings like S:H:slate. This here assumes the mapping is S-H:slate and
that the underscore is replaced with a colon. This is not good if we intend
there to be and underscore.
there to be a dash.
"""
if self.parameters['map']:
postbin = invert_mappings(self.parameters['map'])
else:
postbin = invert_mappings(self.configs['labelMapping'])
# TODO: this is ugly, but I do not know a better way yet. The default value
# of the map parameter in metadata.py is an empty list. If the user sets those
# parameters during invocation (for example "?map=S:slate&map=B:bar") then in
# the user parameters we have ['S:slate', 'B:bar'] for map and in the refined
# parameters we get {'S': 'slate', 'B': 'bar'}. If the user adds no map
# parameters then there is no map value in the user parameters and the value
# is [] in the refined parameters (which is a bit inconsistent).
# Two experiments:
# 1. What if I set the default to a list like ['S:slate', 'B:bar']?
# Then the map value in refined parameters is that same list, which means
# that I have to turn it into a dictionary before I hand it off.
# 2. What if I set the default to a dictionary like {'S': 'slate', 'B': 'bar'}?
# Then the map value in the refined parameters is a list with one element,
# which is the wanted dictionary as a string: ["{'S': 'slate', 'B': 'bar'}"]
if type(self.parameters['map']) is list:
newmap = {}
for kv in self.parameters['map']:
k, v = kv.split(':')
newmap[k] = v
self.parameters['map'] = newmap
self.configs['map'] = newmap
postbin = invert_mappings(self.parameters['map'])
self.configs['postbin'] = postbin

def _extract_images(self, video):
Expand Down Expand Up @@ -179,6 +197,8 @@ def _add_stitcher_results_to_view(self, timeframes: list, view: View):


def invert_mappings(mappings: dict) -> dict:
print('-'*80)
print(mappings)
inverted_mappings = {}
for in_label, out_label in mappings.items():
in_label = restore_colon(in_label)
Expand All @@ -187,8 +207,8 @@ def invert_mappings(mappings: dict) -> dict:


def restore_colon(label_in: str) -> str:
"""Replace an underscore with a colon."""
return label_in.replace('_', ':')
"""Replace a dash with a colon."""
return label_in.replace('-', ':')


def open_video(video):
Expand Down
11 changes: 7 additions & 4 deletions metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ def appmetadata() -> AppMetadata:
name='useStitcher', type='boolean', default=preconf['useStitcher'],
description='Use the stitcher after classifying the TimePoints')
metadata.add_parameter(
name='map', type='map', default=[],
# TODO: do we want to use the old default labelMap from the configuration here or
# do we truly want an empty mapping and use the pass-through, as hinted at in the
# description (which is now not in sync with the code).
name='map', type='map', default=preconf['labelMap'],
description=(
'Mapping of a label in the input annotations to a new label. Must be formatted as '
'"IN_LABEL:OUT_LABEL" (with a colon). To pass multiple mappings, use this parameter '
'IN_LABEL:OUT_LABEL (with a colon). To pass multiple mappings, use this parameter '
'multiple times. By default, all the input labels are passed as is, including any '
'"negative" labels (with default value being no remapping at all). However, when '
'negative labels (with default value being no remapping at all). However, when '
'at least one label is remapped, all the other "unset" labels are discarded as '
'a negative label("-").'))
'a negative label.'))

return metadata

Expand Down
31 changes: 9 additions & 22 deletions modeling/config/classifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,12 @@ staticFrames: [bars, slate, chyron]
# Set to False to turn off the stitcher
useStitcher: True

# Default label mapping
labelMapping:
B: bars
S: slate
S:H: slate
S:C: slate
S:D: slate
S:G: slate
W: other_opening
L: other_opening
O: other_opening
M: other_opening
I: chyron
N: chyron
Y: chyron
C: credit
R: credit
E: other_text
K: other_text
G: other_text
T: other_text
F: other_text
# This was the most frequent label mapping the previous configuration file,
# which had default mappings for each model.
labelMap: [
"B:bars",
"S:slate", "S-H:slate", "S-C:slate", "S-D:slate", "S-G:slate",
"W:other_opening", "L:other_opening", "O:other_opening", "M:other_opening",
"I:chyron", "N:chyron", "Y:chyron",
"C:credit", "R:credit",
"E:other_text", "K:other_text", "G:other_text", "T:other_text", "F:other_text" ]

0 comments on commit 3f8e1fa

Please sign in to comment.