processing_tvp.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright 2023 The Intel AIA Team Authors, and HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License=, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing=, software
  10. # distributed under the License is distributed on an "AS IS" BASIS=,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND=, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Processor class for TVP.
  16. """
  17. from ...processing_utils import ProcessingKwargs, ProcessorMixin
  18. from ...utils import auto_docstring
  19. class TvpProcessorKwargs(ProcessingKwargs, total=False):
  20. _defaults = {
  21. "text_kwargs": {
  22. "truncation": True,
  23. "padding": "max_length",
  24. "pad_to_max_length": True,
  25. "return_token_type_ids": False,
  26. },
  27. }
  28. @auto_docstring
  29. class TvpProcessor(ProcessorMixin):
  30. def __init__(self, image_processor=None, tokenizer=None, **kwargs):
  31. super().__init__(image_processor, tokenizer)
  32. self.video_processor = image_processor
  33. def post_process_video_grounding(self, logits, video_durations):
  34. """
  35. Compute the time of the video.
  36. Args:
  37. logits (`torch.Tensor`):
  38. The logits output of TvpForVideoGrounding.
  39. video_durations (`float`):
  40. The video's duration.
  41. Returns:
  42. start (`float`):
  43. The start time of the video.
  44. end (`float`):
  45. The end time of the video.
  46. """
  47. start, end = (
  48. round(logits.tolist()[0][0] * video_durations, 1),
  49. round(logits.tolist()[0][1] * video_durations, 1),
  50. )
  51. return start, end
  52. __all__ = ["TvpProcessor"]