**
SlowFast的辛酸复现过程
**
1.使用工具
Unbuntu 18.04 + CUDA10. 2 + Pycharm
2.环境配置
2.1 搭建运行环境
官方地址:git clone https://github.com/facebookresearch/slowfast
从官方地址Git下来的版本是最新的代码,该版本也一直会有人在维护,但是我在复现最新版本的代码过程中出现了各种版本不匹配的问题(比如av、torch)。在受尽百般折磨后找到了一个之前版本 的代码:git clone https://gitee.com/qiang_sun/SlowFast.git
,在这要感谢(https://blog.csdn.net/qq_28949847/article/details/117252208
)的无私分享。ok,我们可以先将代码clone 下来,保存到指定位置,然后使用pycharm打开该项目,随后创建环境,创建Conda环境如下:
注意,由于是低版本slowfast(要求Python >=1.6),所以我们使用Python 3.7,环境创建好后在终端输入命令 conda activate oldSlowFast(这是你自己创建的环境名称) 进入虚拟环境进行配置。环境配置跟着INSTALL.md的要求进行配置。
值得注意的是如果配置过程中不指定安装包的版本会导致编译出错,接下来我会给出需要注意版本的几个包:
1、torch==1.8.0
2、torchvision == 0.9.0
3、av == 8.0.3
基本环境配置完成后继续执行以下步骤,build Slowfast.
2.2环境配置中可能出现的问题
1、torch 下载缓慢
解决办法:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple + 对应安装包名称
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch==1.8.0
2、ModuleNotFoundError: No module named ‘torch.ao‘!
解决办法:(https://img-blog.csdnimg.cn/28e73334fedf4a86b18f5119e85fa31b.png
2.3 更改配置文件
1、新建测试视频文件夹以及输出文件夹
在Vinput里面放入测试视频,并命名为test.mp4
2、ava.json
在 Slowfast/demo/AVA 目录下创建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}
3、修改SLOWFAST_32x2_R101_50_50.yaml
修改在 Slowfast/demo/AVA 目录下的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/slowfast/configs/AVA/c2/SLOWFAST_32x2_R101_50_50.pkl' #注意更改为自己的路径
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/Slowfast/demo/AVA/ava.json"
INPUT_VIDEO: "/home/Slowfast/Vinput/test.mp4"
OUTPUT_FILE: "/home/Slowfast/Voutput/testout.mp4"
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
4、下载模型
下载行为识别模型到指定文件夹下
下载地址:link
5、运行 run_net.py
python tools/run_net.py --cfg demo/AVA/SLOWFAST_32x2_R101_50_50.yaml
输出结果:
3.总结
在复现过程中遇到了很多问题,历经千辛万苦终于成功(本人比较菜)。第一次写博客记录自己正在做的事情,一是为了帮助自己加深记忆,二是希望写出来能够帮助部分正在奔跑的人,由于本人水平有限,有写得不到位的地方还望海涵。
参考
[1]:https://blog.csdn.net/WhiffeYF/article/details/113527759