copied
Readme
Files and versions
Updated 2 years ago
action-classification
Action Classification with ActionClip
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 ActionClip and maps vectors with labels provided by datasets used for pre-training.
Code Example
Use the pretrained ActionClip model 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.actionclip(model_name='clip_vit_b16'))
.output('path', 'labels', 'scores', 'features')
)
DataCollection(p('./archery.mp4')).show()

Factory Constructor
Create the operator via the following factory method
action_classification.actionclip(model_name='clip_vit_b16', skip_preprocess=False, classmap=None, topk=5)
Parameters:
model_name: str
The name of pre-trained clip model.
Supported model names:
- clip_vit_b16
- clip_vit_b32
skip_preprocess: bool
Flag to control whether to skip video transforms, defaults to False. If set to True, the step to transform videos 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:
frames: List[VideoFrame]
Video frames in towhee.types.video_frame.VideoFrame.
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 (num_features,) representing features extracted by model.
| 11 Commits | ||
---|---|---|---|
|
3 years ago | ||
|
1.3 KiB
|
3 years ago | |
|
2.7 KiB
|
2 years ago | |
|
689 B
|
3 years ago | |
|
4.6 KiB
|
3 years ago | |
|
12 MiB
|
3 years ago | |
|
12 MiB
|
3 years ago | |
|
10 KiB
|
3 years ago | |
|
59 B
|
3 years ago | |
|
14 KiB
|
2 years ago |