logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

Updated 1 year ago

action-classification

Action Classification with TimeSformer

Author: Jael Gu


Description

An action classification operator generates labels of human activities (with corresponding scores) and extracts features for the input video. It transforms the video into frames and loads pre-trained models by model names. This operator has implemented pre-trained models from TimeSformer and maps vectors with labels.


Code Example

Use the pretrained TimeSformer model ('timesformer_k400_8x224') to classify and generate a vector for the given video path './archery.mp4' (download).

Write a pipeline with explicit inputs/outputs name specifications:

from towhee import pipe, ops, DataCollection

p = (
    pipe.input('path')
        .map('path', 'frames', ops.video_decode.ffmpeg())
        .map('frames', ('labels', 'scores', 'features'),
             ops.action_classification.timesformer(model_name='timesformer_k400_8x224'))
        .output('path', 'labels', 'scores', 'features')
)

DataCollection(p('./archery.mp4')).show()


Factory Constructor

Create the operator via the following factory method

action_classification.timesformer( model_name='timesformer_k400_8x224', skip_preprocess=False, classmap=None, topk=5)

Parameters:

model_name: str

​ The name of pre-trained model. Supported model names:

  • timesformer_k400_8x224

skip_preprocess: bool

​ Flag to control whether to skip UniformTemporalSubsample in video transforms, defaults to False. If set to True, the step of UniformTemporalSubsample will be skipped. In this case, the user should guarantee that all the input video frames are already reprocessed properly, and thus can be fed to model directly.

classmap: Dict[str: int]:

​ Dictionary that maps class names to one hot vectors. If not given, the operator will load the default class map dictionary.

topk: int

​ The topk labels & scores to present in result. The default value is 5.

Interface

A video classification operator generates a list of class labels and a corresponding vector in numpy.ndarray given a video input data.

Parameters:

video: List[towhee.types.VideoFrame]

​ Input video data should be a list of towhee.types.VideoFrame representing video frames in order.

Returns:

labels, scores, features: Tuple(List[str], List[float], numpy.ndarray)

  • labels: predicted class names.
  • scores: possibility scores ranking from high to low corresponding to predicted labels.
  • features: a video embedding in shape of (768,) representing features extracted by model.
Jael Gu 90d342d8a3 Remove dc2 14 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 2 years ago
file-icon README.md
2.7 KiB
download-icon
Remove dc2 1 year ago
file-icon __init__.py
692 B
download-icon
Add files 2 years ago
file-icon kinetics_400.json
10 KiB
download-icon
Add files 2 years ago
file-icon requirements.txt
52 B
download-icon
update requirements 1 year ago
file-icon result.png
15 KiB
download-icon
Update 1 year ago
file-icon timesformer.py
3.4 KiB
download-icon
Fix typo 2 years ago