Skip to content

Commit

Permalink
[Docs] Highlight loading checkpoints directly from url (#339)
Browse files Browse the repository at this point in the history
* highlight function to load checkpoint from url

* highlight function to load checkpoint from url
  • Loading branch information
dreamerlin authored Nov 11, 2020
1 parent 79aa496 commit 303b62b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
38 changes: 29 additions & 9 deletions demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Optional arguments:

Examples:

Assume that you are located at `$MMACTION2` and have already downloaded the checkpoints to the directory `checkpoints/`
Assume that you are located at `$MMACTION2` and have already downloaded the checkpoints to the directory `checkpoints/`,
or use checkpoint url from `configs/` to directly load corresponding checkpoint, which will be automatically saved in `$HOME/.cahe/torch/checkpoints`.

1. Recognize a video file as input by using a TSN model on cuda by default.

Expand All @@ -38,15 +39,24 @@ Assume that you are located at `$MMACTION2` and have already downloaded the chec
demo/demo.mp4 demo/label_map.txt
```

2. Recognize a list of rawframes as input by using a TSN model on cpu.
2. Recognize a video file as input by using a TSN model on cuda by default, loading checkpoint from url.

```shell
# The demo.mp4 and label_map.txt are both from Kinetics-400
python demo/demo.py configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py \
https://download.openmmlab.com/mmaction/recognition/tsn/tsn_r50_1x1x3_100e_kinetics400_rgb/tsn_r50_1x1x3_100e_kinetics400_rgb_20200614-e508be42.pth \
demo/demo.mp4 demo/label_map.txt
```

3. Recognize a list of rawframes as input by using a TSN model on cpu.

```shell
python demo/demo.py configs/recognition/tsn/tsn_r50_inference_1x1x3_100e_kinetics400_rgb.py \
checkpoints/tsn_r50_1x1x3_100e_kinetics400_rgb_20200614-e508be42.pth \
PATH_TO_FRAMES/ LABEL_FILE --use-frames --device cpu
```

3. Recognize a video file as input by using a TSN model and then generate an mp4 file.
4. Recognize a video file as input by using a TSN model and then generate an mp4 file.

```shell
# The demo.mp4 and label_map.txt are both from Kinetics-400
Expand All @@ -55,15 +65,15 @@ Assume that you are located at `$MMACTION2` and have already downloaded the chec
demo/demo.mp4 demo/label_map.txt --out-filename demo/demo_out.mp4
```

4. Recognize a list of rawframes as input by using a TSN model and then generate a gif file.
5. Recognize a list of rawframes as input by using a TSN model and then generate a gif file.

```shell
python demo/demo.py configs/recognition/tsn/tsn_r50_inference_1x1x3_100e_kinetics400_rgb.py \
checkpoints/tsn_r50_1x1x3_100e_kinetics400_rgb_20200614-e508be42.pth \
PATH_TO_FRAMES/ LABEL_FILE --use-frames --out-filename demo/demo_out.gif
```

5. Recognize a video file as input by using a TSN model, then generate an mp4 file with a given resolution and resize algorithm.
6. Recognize a video file as input by using a TSN model, then generate an mp4 file with a given resolution and resize algorithm.

```shell
# The demo.mp4 and label_map.txt are both from Kinetics-400
Expand All @@ -83,7 +93,7 @@ Assume that you are located at `$MMACTION2` and have already downloaded the chec
--out-filename demo/demo_out.mp4
```

6. Recognize a video file as input by using a TSN model, then generate an mp4 file with a label in a red color and 10px fontsize.
7. Recognize a video file as input by using a TSN model, then generate an mp4 file with a label in a red color and 10px fontsize.

```shell
# The demo.mp4 and label_map.txt are both from Kinetics-400
Expand All @@ -93,7 +103,7 @@ Assume that you are located at `$MMACTION2` and have already downloaded the chec
--out-filename demo/demo_out.mp4
```

7. Recognize a list of rawframes as input by using a TSN model and then generate an mp4 file with 24 fps.
8. Recognize a list of rawframes as input by using a TSN model and then generate an mp4 file with 24 fps.

```shell
python demo/demo.py configs/recognition/tsn/tsn_r50_inference_1x1x3_100e_kinetics400_rgb.py \
Expand All @@ -119,7 +129,8 @@ Optional arguments:

Examples:

Assume that you are located at `$MMACTION2` and have already downloaded the checkpoints to the directory `checkpoints/`
Assume that you are located at `$MMACTION2` and have already downloaded the checkpoints to the directory `checkpoints/`,
or use checkpoint url from `configs/` to directly load corresponding checkpoint, which will be automatically saved in `$HOME/.cahe/torch/checkpoints`.

1. Recognize the action from web camera as input by using a TSN model on cpu, averaging the score per 5 times
and outputting result labels with score higher than 0.2.
Expand All @@ -130,7 +141,16 @@ Assume that you are located at `$MMACTION2` and have already downloaded the chec
--threshold 0.2 --device cpu
```

2. Recognize the action from web camera as input by using a I3D model on gpu by default, averaging the score per 5 times
2. Recognize the action from web camera as input by using a TSN model on cpu, averaging the score per 5 times
and outputting result labels with score higher than 0.2, loading checkpoint from url.

```shell
python demo/webcam_demo.py configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py \
https://download.openmmlab.com/mmaction/recognition/tsn/tsn_r50_1x1x3_100e_kinetics400_rgb/tsn_r50_1x1x3_100e_kinetics400_rgb_20200614-e508be42.pth \
demo/label_map.txt --average-size 5 --threshold 0.2 --device cpu
```

3. Recognize the action from web camera as input by using a I3D model on gpu by default, averaging the score per 5 times
and outputting result labels with score higher than 0.2.

```shell
Expand Down
4 changes: 2 additions & 2 deletions demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def parse_args():
parser = argparse.ArgumentParser(description='MMAction2 demo')
parser.add_argument('config', help='test config file path')
parser.add_argument('checkpoint', help='checkpoint file')
parser.add_argument('checkpoint', help='checkpoint file/url')
parser.add_argument('video', help='video file/url or rawframes directory')
parser.add_argument('label', help='label file')
parser.add_argument(
Expand Down Expand Up @@ -128,7 +128,7 @@ def main():
args = parse_args()
# assign the desired device.
device = torch.device(args.device)
# build the recognizer from a config file and checkpoint file
# build the recognizer from a config file and checkpoint file/url
model = init_recognizer(
args.config,
args.checkpoint,
Expand Down
2 changes: 1 addition & 1 deletion mmaction/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def init_recognizer(config,
Args:
config (str | :obj:`mmcv.Config`): Config file path or the config
object.
checkpoint (str | None, optional): Checkpoint path. If left as None,
checkpoint (str | None, optional): Checkpoint path/url. If set to None,
the model will not load any weights. Default: None.
device (str | :obj:`torch.device`): The desired device of returned
tensor. Default: 'cuda:0'.
Expand Down

0 comments on commit 303b62b

Please sign in to comment.