copied
Readme
Files and versions
2.3 KiB
Video Classification with TSM
Author: Xinyu Ge
Description
A video classification operator generates labels (and 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 TSM 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 the pipeline in simplified style:
- Predict labels (default):
import towhee
(
towhee.glob('./archery.mp4')
.video_decode.ffmpeg()
.video_classification.tsm(
model_name='tsm_k400_r50_seg8', topk=5)
.show()
)
Factory Constructor
Create the operator via the following factory method
video_classification.tsm( model_name='tsm_k400_r50_seg8', skip_preprocess=False, classmap=None, topk=5)
Parameters:
model_name: str
The name of pre-trained clip model.
Supported model names:
- tsm_k400_r50_seg8
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:
video: Union[str, numpy.ndarray]
Input video data using local path in string or video frames in ndarray.
Returns: (list, list)
A tuple of (labels, scores), which contains lists of predicted class names and corresponding scores.
2.3 KiB
Video Classification with TSM
Author: Xinyu Ge
Description
A video classification operator generates labels (and 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 TSM 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 the pipeline in simplified style:
- Predict labels (default):
import towhee
(
towhee.glob('./archery.mp4')
.video_decode.ffmpeg()
.video_classification.tsm(
model_name='tsm_k400_r50_seg8', topk=5)
.show()
)
Factory Constructor
Create the operator via the following factory method
video_classification.tsm( model_name='tsm_k400_r50_seg8', skip_preprocess=False, classmap=None, topk=5)
Parameters:
model_name: str
The name of pre-trained clip model.
Supported model names:
- tsm_k400_r50_seg8
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:
video: Union[str, numpy.ndarray]
Input video data using local path in string or video frames in ndarray.
Returns: (list, list)
A tuple of (labels, scores), which contains lists of predicted class names and corresponding scores.