Switch to unified view

a b/docs/feature_extraction.md
1
# Feature Extraction
2
3
We provide easy to use scripts for feature extraction.
4
5
## Clip-level Feature Extraction
6
7
Clip-level feature extraction extract deep feature from a video clip, which usually lasts several to tens of seconds. The extracted feature is an n-dim vector for each clip. When performing multi-view feature extraction, e.g. n clips x m crops, the extracted feature will be the average of the n * m views.
8
9
Before applying clip-level feature extraction, you need to prepare a video list (which include all videos that you want to extract feature from). For example, the video list for videos in UCF101 will look like:
10
11
```
12
ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c01.avi
13
ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c02.avi
14
ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c03.avi
15
ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c04.avi
16
ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c05.avi
17
...
18
YoYo/v_YoYo_g25_c01.avi
19
YoYo/v_YoYo_g25_c02.avi
20
YoYo/v_YoYo_g25_c03.avi
21
YoYo/v_YoYo_g25_c04.avi
22
YoYo/v_YoYo_g25_c05.avi
23
```
24
25
Assume the root of UCF101 videos is `data/ucf101/videos` and the name of the video list is `ucf101.txt`, to extract clip-level feature of UCF101 videos with Kinetics-400 pretrained TSN, you can use the following script:
26
27
```shell
28
python tools/misc/clip_feature_extraction.py \
29
configs/recognition/tsn/tsn_r50_clip_feature_extraction_1x1x3_rgb.py \
30
https://download.openmmlab.com/mmaction/recognition/tsn/tsn_r50_320p_1x1x3_100e_kinetics400_rgb/tsn_r50_320p_1x1x3_100e_kinetics400_rgb_20200702-cc665e2a.pth \
31
--video-list ucf101.txt \
32
--video-root data/ucf101/videos \
33
--out ucf101_feature.pkl
34
```
35
36
and the extracted feature will be stored in `ucf101_feature.pkl`
37
38
You can also use distributed clip-level feature extraction. Below is an example for a node with 8 gpus.
39
40
```shell
41
bash tools/misc/dist_clip_feature_extraction.sh \
42
configs/recognition/tsn/tsn_r50_clip_feature_extraction_1x1x3_rgb.py \
43
https://download.openmmlab.com/mmaction/recognition/tsn/tsn_r50_320p_1x1x3_100e_kinetics400_rgb/tsn_r50_320p_1x1x3_100e_kinetics400_rgb_20200702-cc665e2a.pth \
44
8 \
45
--video-list ucf101.txt \
46
--video-root data/ucf101/videos \
47
--out ucf101_feature.pkl
48
```
49
50
To extract clip-level feature of UCF101 videos with Kinetics-400 pretrained SlowOnly, you can use the following script:
51
52
```shell
53
python tools/misc/clip_feature_extraction.py \
54
configs/recognition/slowonly/slowonly_r50_clip_feature_extraction_4x16x1_rgb.py \
55
https://download.openmmlab.com/mmaction/recognition/slowonly/slowonly_r50_video_320p_4x16x1_256e_kinetics400_rgb/slowonly_r50_video_320p_4x16x1_256e_kinetics400_rgb_20201014-c9cdc656.pth \
56
--video-list ucf101.txt \
57
--video-root data/ucf101/videos \
58
--out ucf101_feature.pkl
59
```
60
61
The two config files demonstrates what a minimal config file for feature extraction looks like. You can also use other existing config files for feature extraction, as long as they use videos rather than raw frames for training and testing:
62
63
```shell
64
python tools/misc/clip_feature_extraction.py \
65
configs/recognition/slowonly/slowonly_r50_video_4x16x1_256e_kinetics400_rgb.py \
66
https://download.openmmlab.com/mmaction/recognition/slowonly/slowonly_r50_video_320p_4x16x1_256e_kinetics400_rgb/slowonly_r50_video_320p_4x16x1_256e_kinetics400_rgb_20201014-c9cdc656.pth \
67
--video-list ucf101.txt \
68
--video-root data/ucf101/videos \
69
--out ucf101_feature.pkl
70
```