PaddleVide Quick Start

August 4, 2022 · View on GitHub

English | 简体中文

PaddleVide Quick Start

1. Installation

1.1 Install PaddlePaddle

  • If you have CUDA 9 or CUDA 10 installed on your machine, please run the following command to install

    python3.7 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
    
  • If you have no available GPU on your machine, please run the following command to install the CPU version

    python3.7 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
    

For more software version requirements, please refer to the instructions in Installation Document for operation.

1.2 Install PaddleVideo Whl Package

  • option1: use pypi(recommand)
pip3.7 install ppvideo==2.3.0
  • option2: build and install locally
python3.7 setup.py bdist_wheel
python3.7 -m pip install dist/ppvideo-2.3.0-py3-none-any.whl

2. Easy-to-Use

2.1 Use by Command Line

Run shell command:

ppvideo --model_name='ppTSM_v2' --use_gpu=False --video_file='data/example.avi'
  • This command use PP-TSM_v2 model to infer data/example.avi file in CPU.

  • The length of the example video is about 10s. When inference, the video is first divided into 16 segments according to the time axis, then extract one frame from each segment. Finally all frames are combined and feeded into the network.

Results:

Current video file: data/example.avi
        top-1 classes: [5]
        top-1 scores: [1.]
        top-1 label names: ['archery']

As you can see, use PP-TSM_v2 trained on Kinetics-400 to predict data/example.avi video,top1 prediction class_id is 5, scores is 1.0, class name is archery.

2.2 Use by Python Code

Run python code:

from ppvideo import PaddleVideo
clas = PaddleVideo(model_name='ppTSM_v2', use_gpu=False)
video_file='data/example.avi'
clas.predict(video_file)
  • This code use PP-TSM_v2 model to infer data/example.avi file in CPU.

Results:

Current video file: data/example.avi
        top-1 classes: [5]
        top-1 scores: [1.]
        top-1 label names: ['archery']

As you can see, use PP-TSM_v2 trained on Kinetics-400 to predict data/example.avi video,top1 prediction class_id is 5, scores is 1.0, class name is archery.

3. Arguments description

nametypedescription
model_namestroptional, model name, 'ppTSM' or 'ppTSM_v2'. If None, please specify the path of your inference model by args model_file and params_file.
video_filestrrequired, Video file path, supported format: single video file path, or folder containing multiple videos.
use_gpuboolwhether to use GPU,default True。
num_segintThe number of segments used in the TSM model, which is also the number of frames extracted from the video. 8 for ppTSM, 16 for ppTSM_v2, default 16.
short_sizeintshort size of frame, default 256.
target_sizeinttarget size of frame, default 224.
model_filestroptional,inference model(.pdmodel)path.
params_filestroptional, inference modle(.pdiparams) path.
batch_sizeintBatch size, default 1.
use_fp16boolwhether to use float16,default False.
use_tensorrtboolwhether to use Tensorrt, default False.
gpu_memintuse GPU memory, default 8000.
enable_mkldnnboolwhether to use MKLDNN, default False.
top_kinttop_k, default 1.
label_name_pathstrThis file consists the relation of class_id and class_name. Default use data/k400/Kinetics-400_label_list.txt of Kinetics-400. You can replace it with your own label file.

command example1:

ppvideo --model_name='ppTSM_v2' --num_seg=16 --video_file="data/mp4" --batch_size=2  --top_k=5

Results:

Current video file: data/mp4/example3.avi
        top-5 classes: [  5 345 311 159 327]
        top-5 scores: [1.0000000e+00 1.0152016e-11 8.2871061e-14 6.7713670e-14 5.0752070e-14]
        top-5 label names: ['archery', 'sword_fighting', 'skipping_rope', 'hula_hooping', 'spray_painting']
Current video file: data/mp4/example2.avi
        top-5 classes: [  5 345 311 159 327]
        top-5 scores: [1.0000000e+00 1.0152016e-11 8.2871061e-14 6.7713670e-14 5.0752070e-14]
        top-5 label names: ['archery', 'sword_fighting', 'skipping_rope', 'hula_hooping', 'spray_painting']
Current video file: data/mp4/example.avi
        top-5 classes: [  5 345 311 159 327]
        top-5 scores: [1.0000000e+00 1.0152016e-11 8.2871061e-14 6.7713670e-14 5.0752070e-14]
        top-5 label names: ['archery', 'sword_fighting', 'skipping_rope', 'hula_hooping', 'spray_painting']
Current video file: data/mp4/example1.avi
        top-5 classes: [  5 345 311 159 327]
        top-5 scores: [1.0000000e+00 1.0152016e-11 8.2871061e-14 6.7713670e-14 5.0752070e-14]
        top-5 label names: ['archery', 'sword_fighting', 'skipping_rope', 'hula_hooping', 'spray_painting']

command example1:

ppvideo --model_name='ppTSM' --num_seg=8 --video_file="data/mp4" --batch_size=2  --top_k=5

4. QA

  1. opecv-python Installation maybe slow, you can try:
python3.7 -m pip install opencv-python==4.2.0.32 -i https://pypi.doubanio.com/simple