Skip to content

Commit

Permalink
Merge pull request #75 from clamsproject/develop
Browse files Browse the repository at this point in the history
Releasing 4.0
  • Loading branch information
marcverhagen authored Feb 27, 2024
2 parents 573077a + 448142e commit 710f527
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
12 changes: 1 addition & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,14 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
timeframe_annotation = new_view.new_annotation(AnnotationTypes.TimeFrame)
timeframe_annotation.add_property("label", tf.label),
timeframe_annotation.add_property('classification', {tf.label: tf.score})
#timeframe_annotation.add_property("score", tf.score)
#timeframe_annotation.add_property("scores", tf.scores)
timepoint_annotations = []
for prediction in tf.targets:
timepoint_annotation = new_view.new_annotation(AnnotationTypes.TimePoint)
prediction.annotation = timepoint_annotation
scores = [prediction.score_for_label(lbl) for lbl in prediction.labels]
label = self._label_with_highest_score(prediction.labels, scores)
classification = {l:s for l, s in zip(prediction.labels, scores)}
classification = self._transform(classification, bins)
label = max(classification, key=classification.get)
timepoint_annotation.add_property('timePoint', prediction.timepoint)
timepoint_annotation.add_property('label', label)
timepoint_annotation.add_property('classification', classification)
Expand Down Expand Up @@ -107,14 +105,6 @@ def _export_parameters(self, parameters: dict):
elif parameter == "minFrameCount":
self.stitcher.min_frame_count = value

@staticmethod
def _label_with_highest_score(labels: list, scores: list) -> str:
"""Return the label associated with the highest scores. The score for
labels[i] is scores[i]."""
# TODO: now the NEG scores are included, perhaps not do that
sorted_scores = list(sorted(zip(scores, labels), reverse=True))
return sorted_scores[0][1]

@staticmethod
def _transform(classification: dict, bins: dict):
"""Take the raw classification and turn it into a classification of user
Expand Down
8 changes: 3 additions & 5 deletions metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ def appmetadata() -> AppMetadata:
url="https://github.com/clamsproject/app-swt-detection"
)

labels = ['bars', 'slate', 'chyron', 'credits', 'NEG']
metadata.add_input(DocumentTypes.VideoDocument, required=True)
metadata.add_output(AnnotationTypes.TimeFrame, timeUnit='milliseconds', frameType='bars')
metadata.add_output(AnnotationTypes.TimeFrame, timeUnit='milliseconds', frameType='slate')
metadata.add_output(AnnotationTypes.TimeFrame, timeUnit='milliseconds', frameType='chyron')
metadata.add_output(AnnotationTypes.TimeFrame, timeUnit='milliseconds', frameType='credits')
metadata.add_output(AnnotationTypes.TimePoint, timeUnit='milliseconds')
metadata.add_output(AnnotationTypes.TimeFrame, timeUnit='milliseconds', labelset=labels)
metadata.add_output(AnnotationTypes.TimePoint, timeUnit='milliseconds', labelset=labels)

# TODO: defaults are the same as in modeling/config/classifier.yml, which is possibly
# not a great idea, should perhaps read defaults from the configuration file. There is
Expand Down

0 comments on commit 710f527

Please sign in to comment.