目录
前言:
1--环境配置
2--测试Demo
2-1--测试命令
2-2--测试结果
3--相关报错解决
前言:
本地环境如下:
Ubuntu 20.04
Cuda 11.3
NVIDIA GeForce RTX 3060
1--环境配置
具体请参考官方提供的文档:slowfast官方安装文档,以下为博主在本地安装的过程:
① 配置 python 环境
conda create -n slowfast python=3.8
② 配置 pytorch 环境
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
③ 安装 fvcore
pip install 'git+https://github.com/facebookresearch/fvcore'
④ 安装simplejson
pip install simplejson
⑤ 安装PyAV
conda install av -c conda-forge
⑥ 安装iopath
pip install -U iopath
⑦ 安装psutil
pip install psutil
⑧ 安装OpenCV
pip install opencv-python
⑨ 安装tensorboard
pip install tensorboard
⑩ 安装moviepy
pip install moviepy
⑪ 安装PyTorchVideo
pip install pytorchvideo
⑫ 安装Detection
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2
⑬ 安装FairScale
pip install 'git+https://github.com/facebookresearch/fairscale'
⑭ 安装scipy
pip isntall scipy
⑮ 安装和编译PySlowFast
git clone https://github.com/facebookresearch/slowfast
export PYTHONPATH=/home/liujinfu/Desktop/slowfast_ljf/SlowFast/slowfast:$PYTHONPATH
cd SlowFast
python setup.py build develop
2--测试Demo
2-1--测试命令
python tools/run_net.py --cfg demo/AVA/SLOWFAST_32x2_R101_50_50.yaml
博主 SLOWFAST_32x2_R101_50_50.yaml 的内容如下:
TRAIN:
ENABLE: False
DATASET: ava
BATCH_SIZE: 16
EVAL_PERIOD: 1
CHECKPOINT_PERIOD: 1
AUTO_RESUME: True
CHECKPOINT_FILE_PATH: /home/liujinfu/Desktop/slowfast_ljf/model/SLOWFAST_32x2_R101_50_50.pkl #path to pretrain model
CHECKPOINT_TYPE: pytorch
DATA:
NUM_FRAMES: 32
SAMPLING_RATE: 2
TRAIN_JITTER_SCALES: [256, 320]
TRAIN_CROP_SIZE: 224
TEST_CROP_SIZE: 256
INPUT_CHANNEL_NUM: [3, 3]
DETECTION:
ENABLE: True
ALIGNED: False
AVA:
BGR: False
DETECTION_SCORE_THRESH: 0.8
TEST_PREDICT_BOX_LISTS: ["person_box_67091280_iou90/ava_detection_val_boxes_and_labels.csv"]
SLOWFAST:
ALPHA: 4
BETA_INV: 8
FUSION_CONV_CHANNEL_RATIO: 2
FUSION_KERNEL_SZ: 5
RESNET:
ZERO_INIT_FINAL_BN: True
WIDTH_PER_GROUP: 64
NUM_GROUPS: 1
DEPTH: 101
TRANS_FUNC: bottleneck_transform
STRIDE_1X1: False
NUM_BLOCK_TEMP_KERNEL: [[3, 3], [4, 4], [6, 6], [3, 3]]
SPATIAL_DILATIONS: [[1, 1], [1, 1], [1, 1], [2, 2]]
SPATIAL_STRIDES: [[1, 1], [2, 2], [2, 2], [1, 1]]
NONLOCAL:
LOCATION: [[[], []], [[], []], [[6, 13, 20], []], [[], []]]
GROUP: [[1, 1], [1, 1], [1, 1], [1, 1]]
INSTANTIATION: dot_product
POOL: [[[2, 2, 2], [2, 2, 2]], [[2, 2, 2], [2, 2, 2]], [[2, 2, 2], [2, 2, 2]], [[2, 2, 2], [2, 2, 2]]]
BN:
USE_PRECISE_STATS: False
NUM_BATCHES_PRECISE: 200
SOLVER:
MOMENTUM: 0.9
WEIGHT_DECAY: 1e-7
OPTIMIZING_METHOD: sgd
MODEL:
NUM_CLASSES: 80
ARCH: slowfast
MODEL_NAME: SlowFast
LOSS_FUNC: bce
DROPOUT_RATE: 0.5
HEAD_ACT: sigmoid
TEST:
ENABLE: False
DATASET: ava
BATCH_SIZE: 8
DATA_LOADER:
NUM_WORKERS: 2
PIN_MEMORY: True
NUM_GPUS: 1
NUM_SHARDS: 1
RNG_SEED: 0
OUTPUT_DIR: .
#TENSORBOARD:
#MODEL_VIS:
#TOPK: 2
DEMO:
ENABLE: True
LABEL_FILE_PATH: /home/liujinfu/Desktop/slowfast_ljf/model/ava.json
INPUT_VIDEO: "/home/liujinfu/Desktop/slowfast_ljf/input/1.avi"
OUTPUT_FILE: "/home/liujinfu/Desktop/slowfast_ljf/output/1.avi"
#WEBCAM: 0
DETECTRON2_CFG: "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml"
DETECTRON2_WEIGHTS: detectron2://COCO-Detection/faster_rcnn_R_50_FPN_3x/137849458/model_final_280758.pkl
需要修改的配置参数如下:
① CHECKPOINT_FILE_PATH:权重文件的路径(官方提供的权重文件下载:slowfast 已训练权重文件下载)
CHECKPOINT_FILE_PATH: /home/liujinfu/Desktop/slowfast_ljf/model/SLOWFAST_32x2_R101_50_50.pkl #path to pretrain model
② LABEL_FILE_PATH:标签文件,博主将其构造为 ava.json 格式,内容如下:
{"bend/bow (at the waist)": 0, "crawl": 1, "crouch/kneel": 2, "dance": 3, "fall down": 4, "get up": 5, "jump/leap": 6, "lie/sleep": 7, "martial art": 8, "run/jog": 9, "sit": 10, "stand": 11, "swim": 12, "walk": 13, "answer phone": 14, "brush teeth": 15, "carry/hold (an object)": 16, "catch (an object)": 17, "chop": 18, "climb (e.g., a mountain)": 19, "clink glass": 20, "close (e.g., a door, a box)": 21, "cook": 22, "cut": 23, "dig": 24, "dress/put on clothing": 25, "drink": 26, "drive (e.g., a car, a truck)": 27, "eat": 28, "enter": 29, "exit": 30, "extract": 31, "fishing": 32, "hit (an object)": 33, "kick (an object)": 34, "lift/pick up": 35, "listen (e.g., to music)": 36, "open (e.g., a window, a car door)": 37, "paint": 38, "play board game": 39, "play musical instrument": 40, "play with pets": 41, "point to (an object)": 42, "press": 43, "pull (an object)": 44, "push (an object)": 45, "put down": 46, "read": 47, "ride (e.g., a bike, a car, a horse)": 48, "row boat": 49, "sail boat": 50, "shoot": 51, "shovel": 52, "smoke": 53, "stir": 54, "take a photo": 55, "text on/look at a cellphone": 56, "throw": 57, "touch (an object)": 58, "turn (e.g., a screwdriver)": 59, "watch (e.g., TV)": 60, "work on a computer": 61, "write": 62, "fight/hit (a person)": 63, "give/serve (an object) to (a person)": 64, "grab (a person)": 65, "hand clap": 66, "hand shake": 67, "hand wave": 68, "hug (a person)": 69, "kick (a person)": 70, "kiss (a person)": 71, "lift (a person)": 72, "listen to (a person)": 73, "play with kids": 74, "push (another person)": 75, "sing to (e.g., self, a person, a group)": 76, "take (an object) from (a person)": 77, "talk to (e.g., self, a person, a group)": 78, "watch (a person)": 79}
③ INPUT_VIDEO:输入测试视频的路径
INPUT_VIDEO: "/home/liujinfu/Desktop/slowfast_ljf/input/1.avi"
④ OUTPUT_FILE:输出测试视频的路径
OUTPUT_FILE: "/home/liujinfu/Desktop/slowfast_ljf/output/1.avi"
2-2--测试结果
从截图可知,识别结果部分有误;
3--相关报错解决
报错 ①:error: Could not find suitable distribution for Requirement.parse('PIL');
出现在编译安装PySlowFast的过程中:python setup.py build develop;
解决方法:参考如下官方 issues,修改 setup 文件,将 PIL 修改为 Pillow;Could not find suitable distribution for Requirement.parse('PIL')
报错 ②:cannot import name 'Cal_all_gather' From 'pytorchvideo.layers.distributed';
报错的原因是未能正确安装 pytorchvideo,具体解决方法可参考如下官方 issues,从源码编译 pytorchvideo;
ImportError: cannot import name 'cat_all_gather' from 'pytorchvideo.layers.distributed'
报错 ③:no module named 'sklearn';
报错的原因是新版本不支持 sklearn,具体可见如下官方issues,解决方法是安装scikit-learn:
pip install scikit-learn
INSTALL.md is not up-to-date. Here is an updated version in my SlowFast fork
报错 ④:
报错的原因是配置文件 SLOWFAST_32x2_R101_50_50.yaml 有误,具体可参考如下官方issues:
input video for demo, but got KeyError
解决方法:将配置文件有关 Tensorboard 的模块注释掉,即:
# TENSORBOARD:
# MODEL_VIS:
# TOPK: 2文章来源:https://www.toymoban.com/news/detail-672253.html
文章来源地址https://www.toymoban.com/news/detail-672253.html
到了这里,关于行为识别SlowFast笔记--环境配置和Demo展示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!