LemurPwned / video-sampler

Effective frame sampling for ML applications.
https://lemurpwned.github.io/video-sampler/
MIT License
16 stars 5 forks source link

`torch`, `spacy`, `transformers`, `pysrt` should be optional dependencies #29

Closed fcakyon closed 3 weeks ago

fcakyon commented 3 weeks ago

🚀 Feature Request

torch, spacy, transformers, pysrt are hard dependencies but should be optional.

When I run this import:

from video_sampler.sampler import SamplerConfig, VideoSampler

I get this error:

Traceback (most recent call last):
  File "/home/.../test_video_sampler.py", line 1, in <module>
    from video_sampler.sampler import SamplerConfig, VideoSampler
  File "/home/.../venv/lib/python3.10/site-packages/video_sampler/__init__.py", line 6, in <module>
    from .sampler import VideoSampler, Worker
  File "/home/.../venv/lib/python3.10/site-packages/video_sampler/sampler.py", line 13, in <module>
    from .gating import create_gate
  File "/home/.../venv/lib/python3.10/site-packages/video_sampler/gating.py", line 106, in <module>
    class ClipGate:
  File "/home/.../venv/lib/python3.10/site-packages/video_sampler/gating.py", line 168, in ClipGate
    def _get_margins(self, frame_embeds: torch.Tensor):
NameError: name 'torch' is not defined

This line is the source of the error:

https://github.com/LemurPwned/video-sampler/blob/72ec1bb58790a7e7d21e9e5bc07d22cd41bf0544/video_sampler/gating.py#L168

🔈 Motivation

I am not interested in the clip gating and visualization feature, I only want to sample frames from a video using classical methods. In this case, I shouldn't need torch (huge dependency) or transformers packages installed in the env to sample frames from a video.

It can be an optional dependency only triggered when the user calls the ClipGate class or build_feature_model, parse_srt_subtitle, build_feature_model functions.

Pull Request

Opened a pull request for this: https://github.com/LemurPwned/video-sampler/pull/30

LemurPwned commented 3 weeks ago

I'll try to soft-type this, thanks!

fcakyon commented 3 weeks ago

@LemurPwned The same issue is present with spacy dependency as well.

This import: https://github.com/LemurPwned/video-sampler/blob/72ec1bb58790a7e7d21e9e5bc07d22cd41bf0544/video_sampler/language/keyword_capture.py#L6

should be moved into: https://github.com/LemurPwned/video-sampler/blob/72ec1bb58790a7e7d21e9e5bc07d22cd41bf0544/video_sampler/language/keyword_capture.py#L58

fcakyon commented 3 weeks ago

opened a pull request for it: https://github.com/LemurPwned/video-sampler/pull/30

fcakyon commented 3 weeks ago

Same issue for transformers https://github.com/LemurPwned/video-sampler/blob/72ec1bb58790a7e7d21e9e5bc07d22cd41bf0544/video_sampler/visualisation/clustering.py#L10 and pysrt dependencies https://github.com/LemurPwned/video-sampler/blob/72ec1bb58790a7e7d21e9e5bc07d22cd41bf0544/video_sampler/language/keyword_capture.py#L4