# Action Classification with VideoSwinTransformer
Author: Jinling xu
## 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 [VideoSwinTransformer](https://arxiv.org/abs/2106.13230)
and maps vectors with labels.
## Code Example
Use the pretrained VideoSwinTransformer model ('swin_tiny_patch244_window877_kinetics400_1k')
to classify and generate a vector for the given video path './archery.mp4' ([download](https://dl.fbaipublicfiles.com/pytorchvideo/projects/archery.mp4)).
*Write the pipeline in simplified style*:
```python
import towhee
(
towhee.glob('./archery.mp4')
.video_decode.ffmpeg()
.action_classification.video_swin_transformer(model_name='swin_tiny_patch244_window877_kinetics400_1k')
.show()
)
```
*Write a same pipeline with explicit inputs/outputs name specifications:*
```python
import towhee
(
towhee.glob['path']('./archery.mp4')
.video_decode.ffmpeg['path', 'frames']()
.action_classification.video_swin_transformer['frames', ('labels', 'scores', 'features')](model_name='swin_tiny_patch244_window877_kinetics400_1k')
.select['path', 'labels', 'scores', 'features']()
.show(formatter={'path': 'video_path'})
)
```
## Factory Constructor
Create the operator via the following factory method
***action_classification.video_swin_transformer(
model_name='swin_tiny_patch244_window877_kinetics400_1k', skip_preprocess=False, classmap=None, topk=5)***
**Parameters:**
***model_name***: *str*
The name of pre-trained model. Supported model names:
- swin_tiny_patch244_window877_kinetics400_1k
- swin_base_patch244_window877_kinetics400_1k
- swin_small_patch244_window877_kinetics400_1k
- swin_base_patch244_window877_kinetics400_22k
***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.