Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix feature extraction script #2672

Open
wants to merge 1 commit into
base: dev-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tools/data/activitynet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,28 @@ After finetuning TSN on ActivityNet, you can use it to extract both RGB and Flow

```shell
python ../../misc/clip_feature_extraction.py tsn_extract_rgb_feat_config.py \
/path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_tarin_feat.pkl \
/path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_tarin_feat \
--video-list ../../../data/ActivityNet/anet_train_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode

python ../../misc/clip_feature_extraction.py tsn_extract_rgb_feat_config.py \
path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_val_feat.pkl \
path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_val_feat \
--video-list ../../../data/ActivityNet/anet_val_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode

python ../../misc/clip_feature_extraction.py tsn_extract_flow_feat_config.py \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_tarin_feat.pkl \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_tarin_feat \
--video-list ../../../data/ActivityNet/anet_train_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode

python ../../misc/clip_feature_extraction.py tsn_extract_flow_feat_config.py \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_val_feat.pkl \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_val_feat \
--video-list ../../../data/ActivityNet/anet_val_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode
```

After feature extraction, you can use our post processing scripts to concat RGB and Flow feature, generate the `100-t X 400-d` feature for Action Detection.
Expand Down
16 changes: 8 additions & 8 deletions tools/data/activitynet/README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ python generate_rawframes_filelist.py

```shell
python ../../misc/clip_feature_extraction.py tsn_extract_rgb_feat_config.py \
/path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_tarin_feat.pkl \
/path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_tarin_feat \
--video-list ../../../data/ActivityNet/anet_train_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode

python ../../misc/clip_feature_extraction.py tsn_extract_rgb_feat_config.py \
path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_val_feat.pkl \
path/to/rgb_checkpoint.pth ../../../data/ActivityNet/rgb_val_feat \
--video-list ../../../data/ActivityNet/anet_val_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode

python ../../misc/clip_feature_extraction.py tsn_extract_flow_feat_config.py \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_tarin_feat.pkl \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_tarin_feat \
--video-list ../../../data/ActivityNet/anet_train_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode

python ../../misc/clip_feature_extraction.py tsn_extract_flow_feat_config.py \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_val_feat.pkl \
/path/to/flow_checkpoint.pth ../../../data/ActivityNet/flow_val_feat \
--video-list ../../../data/ActivityNet/anet_val_video.txt \
--video-root ../../../data/ActivityNet/rawframes \
--dump-score
--dump-score --long-video-mode
```

在提取完特征后,用户可以使用后处理脚本整合 RGB 特征和光流特征,生成 `100-t X 400-d` 维度的特征用于时序动作检测。
Expand Down
4 changes: 2 additions & 2 deletions tools/data/activitynet/tsn_extract_flow_feat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

# dataset settings
dataset_type = 'RawframeDataset'
data_root_val = 'data/kinetics400/rawframes_val'
ann_file_val = 'data/kinetics400/kinetics400_val_list_rawframes.txt'
data_root_val = 'data/activitynet/rawframes_val'
ann_file_val = 'data/activitynet/activitynet_val_list_rawframes.txt'

file_client_args = dict(io_backend='disk')

Expand Down
4 changes: 2 additions & 2 deletions tools/data/activitynet/tsn_extract_rgb_feat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# dataset settings
dataset_type = 'RawframeDataset'
data_root_val = 'data/kinetics400/rawframes_val'
ann_file_val = 'data/kinetics400/kinetics400_val_list_rawframes.txt'
data_root_val = 'data/activitynet/rawframes_val'
ann_file_val = 'data/activitynet/activitynet_val_list_rawframes.txt'

file_client_args = dict(io_backend='disk')

Expand Down
4 changes: 2 additions & 2 deletions tools/data/activitynet/tsn_extract_video_feat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# dataset settings
dataset_type = 'VideoDataset'
data_root_val = 'data/kinetics400/videos_val'
ann_file_val = 'data/kinetics400/kinetics400_val_list_videos.txt'
data_root_val = 'data/activitynet/videos_val'
ann_file_val = 'data/activitynet/activitynet_val_list_videos.txt'

file_client_args = dict(io_backend='disk')

Expand Down
2 changes: 1 addition & 1 deletion tools/data/hacs/write_feature_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
for feature, video in zip(features, video_list):
video_id = video.split()[0].split('/')[1]
csv_file = video_id.replace('mp4', 'csv')
feat = feature['pred_scores']['item'].numpy()
feat = feature['pred_score'].numpy()
feat = feat.tolist()
csv_path = f'{feature_dir}/{csv_file}'
with open(csv_path, 'w') as f:
Expand Down
10 changes: 5 additions & 5 deletions tools/misc/clip_feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from mmengine import dump, list_from_file, load
from mmengine.config import Config, DictAction
from mmengine.dist.utils import is_main_process
from mmengine.runner import Runner


Expand Down Expand Up @@ -133,8 +134,7 @@ def merge_args(cfg, args):
for idx, transform in enumerate(test_pipeline):
if transform.type == 'SampleFrames':
test_pipeline[idx]['twice_sample'] = False
# if transform.type in ['ThreeCrop', 'TenCrop']:
if transform.type == 'TenCrop':
if transform.type in ['ThreeCrop', 'TenCrop']:
test_pipeline[idx].type = 'CenterCrop'

# -------------------- pipeline settings --------------------
Expand Down Expand Up @@ -231,7 +231,7 @@ def preprocess(self, inputs, data_samples, training=False):
def split_feats(args):
total_feats = load(args.dump)
if args.dump_score:
total_feats = [sample['pred_scores']['item'] for sample in total_feats]
total_feats = [sample['pred_score'] for sample in total_feats]

video_list = list_from_file(args.video_list)
video_list = [line.split(' ')[0] for line in video_list]
Expand All @@ -258,8 +258,8 @@ def main():

# start testing
runner.test()

split_feats(args)
if is_main_process():
split_feats(args)


if __name__ == '__main__':
Expand Down
5 changes: 3 additions & 2 deletions tools/misc/dist_clip_feature_extraction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
CONFIG=$1
CHECKPOINT=$2
GPUS=$3
OUTPUT_DIR=$4
PORT=${PORT:-29500}

PYTHONPATH="$(dirname $0)/../..":$PYTHONPATH \
# Arguments starting from the forth one are captured by ${@:4}
python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \
$(dirname "$0")/clip_feature_extraction.py $CONFIG $CHECKPOINT \
--launcher pytorch ${@:4}
$(dirname "$0")/clip_feature_extraction.py $CONFIG $CHECKPOINT $OUTPUT_DIR \
--launcher pytorch ${@:5}
Loading