Download mmaction/datasets/transforms/text_transforms.py from niobures/mmaction2: direct link, hf CLI and curl.
- Browser
- Download file 935 Bytes
-
https://huggingface.co/niobures/mmaction2/resolve/main/mmaction/datasets/transforms/text_transforms.py
- Command line
-
hf download hf://niobures/mmaction2/mmaction/datasets/transforms/text_transforms.py
-
curl -L -o text_transforms.py https://huggingface.co/niobures/mmaction2/resolve/main/mmaction/datasets/transforms/text_transforms.py
935 Bytes
| # Copyright (c) OpenMMLab. All rights reserved. | |
| from typing import Dict | |
| from mmcv.transforms import BaseTransform | |
| from mmaction.registry import TRANSFORMS | |
| class CLIPTokenize(BaseTransform): | |
| """Tokenize text and convert to tensor.""" | |
| def transform(self, results: Dict) -> Dict: | |
| """The transform function of :class:`CLIPTokenize`. | |
| Args: | |
| results (dict): The result dict. | |
| Returns: | |
| dict: The result dict. | |
| """ | |
| try: | |
| import clip | |
| except ImportError: | |
| raise ImportError('Please run `pip install ' | |
| 'git+https://github.com/openai/CLIP.git` ' | |
| 'to install clip first. ') | |
| text = results['text'] | |
| text_tokenized = clip.tokenize(text)[0] | |
| results['text'] = text_tokenized | |
| return results | |