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

TimeFrame annotations missing certain properties may cause some mmif-python functions to fail #305

Open
1192119703jzx opened this issue Aug 26, 2024 · 3 comments

Comments

@1192119703jzx
Copy link
Contributor

When I run the app-east-textdetection with an input mmif file that has view that contains timeframe annotation, it returns the following error:

Traceback (most recent call last):
  File "/home/zixinjiang/east/lib64/python3.9/site-packages/clams/restify/__init__.py", line 146, in post
    return self.json_to_response(self.cla.annotate(raw_data, **raw_params))
  File "/home/zixinjiang/east/lib64/python3.9/site-packages/clams/app/__init__.py", line 151, in annotate
    annotated = self._annotate(mmif, **refined)
  File "/home/zixinjiang/app-east-textdetection/app.py", line 46, in _annotate
    mmif = self.run_on_video(mmif, videodocument, new_view, **parameters)
  File "/home/zixinjiang/app-east-textdetection/app.py", line 105, in run_on_video
    target_frames.update(*[np.linspace(*vdh.convert_timeframe(mmif, a, 'frame'), 2, dtype=int)
  File "/home/zixinjiang/app-east-textdetection/app.py", line 105, in <listcomp>
    target_frames.update(*[np.linspace(*vdh.convert_timeframe(mmif, a, 'frame'), 2, dtype=int)
  File "/home/zixinjiang/east/lib64/python3.9/site-packages/mmif/utils/video_document_helper.py", line 224, in convert_timeframe
    in_unit = time_frame.get_property('timeUnit')
  File "/home/zixinjiang/east/lib64/python3.9/site-packages/mmif/serialize/annotation.py", line 235, in get
    raise KeyError(f"Property {prop_name} does not exist in this annotation.")
KeyError: 'Property timeUnit does not exist in this annotation.'

This kind of error also happens with the Property Document.

This is because the app code uses the function video_document_helper.convert_timeframe(mmif: Mmif, time_frame: Annotation, out_unit: str) from mmif utils package. In the implementation code of this function, there are these two lines of code:

in_unit = time_frame.get_property('timeUnit')
vd = mmif[time_frame.get_property('document')]

These two lines of code require the property 'timeUnit' and 'document' from the metadata of the timeframe annotation. However, in the implementation of certain clams apps, they don't have the code that adds the above properties to the timeframe's type matedata. For example, instead of using new_view.new_contain(AnnotationTypes.TimeFrame, timeUnit="milliseconds", document=doc.long_id), they don't use view.new_contain function or don't add these two property when using v.new_annotation(AnnotationTypes.TimeFrame) and view.new_contain. This would cause the function time_frame.get_property() to fail to get the properties 'timeUnit' and 'document', and consequentially causes the function vdh.convert_timeframe() to fail.

In short, some clams apps lack key information in the output mmif files due to old versions or neglect during development, which causes the failure in running certain mmif-python functions with the output mmif files. Standardizing the Clams app development process may be a good idea.

@clams-bot clams-bot added this to infra Aug 26, 2024
@github-project-automation github-project-automation bot moved this to Todo in infra Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

4 participants
@1192119703jzx and others