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

Improve unittest coverage and minor fix #62

Merged
merged 2 commits into from
Jul 26, 2020
Merged
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
1 change: 1 addition & 0 deletions mmaction/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def inference_recognizer(model, video_path, label_path, use_frames=False):
data = dict(
frame_dir=video_path,
total_frames=len(os.listdir(video_path)),
# assuming files in ``video_path`` are all named with ``filename_tmpl`` # noqa: E501
label=-1,
filename_tmpl=filename_tmpl,
modality=modality)
Expand Down
30 changes: 26 additions & 4 deletions tests/test_models/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@

from mmaction.apis import inference_recognizer, init_recognizer

config_file = 'configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py' # noqa: E501
video_config_file = 'configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py' # noqa: E501
frame_config_file = 'configs/recognition/tsn/tsn_r50_inference_1x1x3_100e_kinetics400_rgb.py' # noqa: E501
label_path = 'demo/label_map.txt'
video_path = 'demo/demo.mp4'


def test_init_recognizer():
with pytest.raises(TypeError):
# config must be a filename or Config object
init_recognizer(dict(config_file=None))

with pytest.raises(RuntimeError):
# input data type should be consist with the dataset type
init_recognizer(frame_config_file)

with pytest.raises(RuntimeError):
# input data type should be consist with the dataset type
init_recognizer(video_config_file, use_frames=True)

if torch.cuda.is_available():
device = 'cuda:0'
else:
device = 'cpu'

model = init_recognizer(config_file, None, device)
model = init_recognizer(video_config_file, None, device)

config = mmcv.Config.fromfile(config_file)
config = mmcv.Config.fromfile(video_config_file)
config.model.backbone.pretrained = None

isinstance(model, nn.Module)
Expand All @@ -37,7 +47,19 @@ def test_inference_recognizer():
device = 'cuda:0'
else:
device = 'cpu'
model = init_recognizer(config_file, None, device)
model = init_recognizer(video_config_file, None, device)

with pytest.raises(RuntimeError):
# video path doesn't exist
inference_recognizer(model, 'missing.mp4', label_path)

with pytest.raises(RuntimeError):
# ``video_path`` should be consist with the ``use_frames``
inference_recognizer(model, video_path, label_path, use_frames=True)

with pytest.raises(RuntimeError):
# ``video_path`` should be consist with the ``use_frames``
inference_recognizer(model, 'demo/', label_path)

for ops in model.cfg.data.test.pipeline:
if ops['type'] == 'TenCrop':
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/download_annotations.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

DATA_DIR="../../../data/kinetics400/annotations"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/download_videos.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

# set up environment
conda env create -f environment.yml
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/extract_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/kinetics400/videos_train/ ../../data/kinetics400/rawframes_train/ --level 2 --flow-type tvl1 --ext mp4 --task both --new-width 340 --new-height 256
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/extract_rgb_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/kinetics400/videos_train/ ../../data/kinetics400/rawframes_train/ --level 2 --ext mp4 --task rgb --new-width 340 --new-height 256
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/extract_rgb_frames_opencv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/kinetics400/videos_train/ ../../data/kinetics400/rawframes_train/ --level 2 --ext mp4 --task rgb --new-width 340 --new-height 256 --use-opencv
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/generate_rawframes_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py kinetics400 data/kinetics400/rawframes_train/ --level 2 --format rawframes --num-split 1 --subset train --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/generate_videos_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py kinetics400 data/kinetics400/videos_train/ --level 2 --format videos --num-split 1 --subset train --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/kinetics400/rename_classnames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

# Rename classname for convenience
cd ../../../data/kinetics400/
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mit/download_data.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

DATA_DIR="../../../data/mit/"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/mit/extract_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/mit/videos/training ../../data/mit/rawframes/training/ --level 2 --flow-type tvl1 --ext mp4 --task both
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mit/extract_rgb_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/mit/videos/training ../../data/mit/rawframes/training/ --level 2 --ext mp4 --task rgb
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mit/extract_rgb_frames_opencv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/mit/videos/training ../../data/mit/rawframes/training/ --level 2 --ext mp4 --task rgb --use-opencv
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mit/generate_rawframes_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py mit data/mit/rawframes/training/ --level 2 --format rawframes --num-split 1 --subset train --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mit/generate_videos_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py mit data/mit/videos/training/ --level 2 --format videos --num-split 1 --subset train --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mmit/extract_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/mmit/videos/ ../../../data/mmit/rawframes/ --task both --level 2 --flow-type tvl1 --ext mp4
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mmit/extract_rgb_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/mmit/videos/ ../../data/mmit/rawframes/ --task rgb --level 2 --ext mp4
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mmit/extract_rgb_frames_opencv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/mmit/videos/ ../../data/mmit/rawframes/ --task rgb --level 2 --ext mp4 --use-opencv
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mmit/generate_rawframes_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py mmit data/mmit/rawframes/ --level 2 --format rawframes --num-split 1 --subset train --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/mmit/generate_videos_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py mmit data/mmit/videos/ --level 2 --format videos --num-split 1 --subset train --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv1/extract_flow.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/sthv1/rawframes/ ../../data/sthv1/rawframes/ --task flow --level 1 --flow-type tvl1 --input-frames
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv1/generate_rawframes_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py sthv1 data/sthv1/rawframes/ --num-split 1 --level 1 --subset train --format rawframe --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv2/extract_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/sthv2/videos/ ../../data/sthv2/rawframes/ --task both --level 1 --flow-type tvl1 --ext webm
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv2/extract_rgb_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/sthv2/videos/ ../../data/sthv2/rawframes/ --task rgb --level 1 --ext webm
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv2/extract_rgb_frames_opencv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/sthv2/videos/ ../../data/sthv2/rawframes/ --task rgb --level 1 --ext webm --use-opencv
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv2/generate_rawframes_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py sthv2 data/sthv2/rawframes/ --num-split 1 --level 1 --subset train --format rawframe --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/sthv2/generate_videos_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../
PYTHONPATH=. python tools/data/build_file_list.py sthv2 data/sthv2/videos/ --num-split 1 --level 1 --subset train --format videos --shuffle
Expand Down
2 changes: 1 addition & 1 deletion tools/data/thumos14/download_annotations.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

DATA_DIR="../../../data/thumos14/"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/thumos14/download_videos.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

DATA_DIR="../../../data/thumos14/"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/thumos14/extract_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/thumos14/videos/validation/ ../../data/thumos14/rawframes/validation/ --level 1 --flow-type tvl1 --ext mp4 --task both
Expand Down
2 changes: 1 addition & 1 deletion tools/data/thumos14/extract_rgb_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/thumos14/videos/validation/ ../../data/thumos14/rawframes/validation/ --level 1 --ext mp4 --task rgb
Expand Down
2 changes: 1 addition & 1 deletion tools/data/thumos14/extract_rgb_frames_opencv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/thumos14/videos/validation/ ../../data/thumos14/rawframes/validation/ --level 1 --ext mp4 --task rgb --use-opencv
Expand Down
2 changes: 1 addition & 1 deletion tools/data/thumos14/fetch_tag_proposals.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

PROP_DIR="../../../data/thumos14/proposals"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/download_annotations.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

DATA_DIR="../../../data/ucf101/annotations"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/download_videos.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

DATA_DIR="../../../data/ucf101/"

Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/extract_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/ucf101/videos/ ../../data/ucf101/rawframes/ --task both --level 2 --flow-type tvl1
Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/extract_rgb_frames.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/ucf101/videos/ ../../data/ucf101/rawframes/ --task rgb --level 2 --ext avi
Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/extract_rgb_frames_opencv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../
python build_rawframes.py ../../data/ucf101/videos/ ../../data/ucf101/rawframes/ --task rgb --level 2 --ext avi --use-opencv
Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/generate_rawframes_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../

Expand Down
2 changes: 1 addition & 1 deletion tools/data/ucf101/generate_videos_filelist.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash env
#!/usr/bin/env bash

cd ../../../

Expand Down