SlowFast-入门1-动作识别-部署与测试

2023-10-24 12:11

本文主要是介绍SlowFast-入门1-动作识别-部署与测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

SlowFast-部署与测试

目录

  • SlowFast-部署与测试
    • 简介
    • 安装部署
    • 测试
      • 准备pkl文件并上传
      • 上传ava.json文件
      • 准备yaml文件
      • 准备素材
      • 运行
    • 运行结果
    • 后记——不重要的痛苦的过程

SlowFast系列:
SlowFast-入门1-动作识别-部署与测试
Slowfast-入门2-学论文【SlowFast Networks for Video Recognition】

简介

GitHub:
https://github.com/facebookresearch/SlowFast
官方给的运行示例图是这样的。
特点是:识别的动作为原子动作;每个人同一时刻可能被识别出多个动作。
在这里插入图片描述

安装部署

部署平台:极链AI云

部署机器:Tesla V100
部署环境:Pytorch 1.6.0, Python 3.7, CUDA 10.2
这里注意!!!!!!!!
选择Pytorch框架版本可以为1.6.0的机器,这样才能选择到3.7的Python。
由于Detectron2需要Pytorch>=1.7,所以之后会需要再升Pytorch的版本。
但一定要选择Python为3.7!!!!!!!!
要先保证Python为3.7!!!!!!!!在这里插入图片描述

安装过程:

pip install 'git+https://github.com/facebookresearch/fvcore'
pip install simplejson
conda install av -c conda-forge
y
pip install -U iopath
pip install psutil
pip install moviepy
pip install tensorboard
pip install pytorchvideo
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
git clone https://github.com/facebookresearch/detectron2.git
pip install -e detectron2
git clone https://github.com/facebookresearch/SlowFast.git
cd SlowFast
python setup.py build develop

安装结束后,成功安装好了fvcore、detectron2、slowfast。
有提示以下错误。
error: Could not find suitable distribution for Requirement.parse(‘PIL’)
但是我看安装教程中,没有特意提到这个PIL库,而且用pip list查看的时候,已经有Pillow库了。
Pillow、PIL更多了解
然后后续的推断测试中也没影响,爷累了,所以先不管他。

安装完后,再用pip list查看:

fvcore                             0.1.5
detectron2                         0.5                 /root/detectron2
sklearn                            0.0
slowfast                           1.0                 /root/SlowFast
torch                              1.7.1+cu110
torchaudio                         0.7.2
torchvision                        0.8.2+cu110

测试

基本安装部署了,接下来要怎么用呢。
Getting Started with PySlowFast
This document provides a brief intro of launching jobs in PySlowFast for training and testing. Before launching any job, make sure you have properly installed the PySlowFast following the instruction in README.md and you have prepared the dataset following DATASET.md with the correct format.

准备pkl文件并上传

看了一下DATASET.md里的介绍,有Kinetics(132GB)、AVA(好像是500GB+)、Charades、Something-Something V2。
下载、处理,都很艰难。
博主试过按照AVA的准备方法准备。下载、裁剪、提取帧、下载标注文件(这个还好)。原始视频19GB多的,整套流程下来电脑跑了两天多,昼夜不停的跑。
【以后有机会再写对这个部分AVA数据集的处理训练方法】

所以,先用人家官方给的,玩玩。在MODEL_ZOO.md,下载了如下的模型。
(这个表的解释,之后在解读论文的时候,可能再解释解释)
下载下来的文件名为:【SLOWFAST_32x2_R101_50_50.pkl】
下载后上传到云端。我是上传到/root/SlowFast路径。
在这里插入图片描述

上传ava.json文件

制作ava.json文件内容如下,记录了80个动作类别。
上传至/root/SlowFast/demo/AVA路径下。

{"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}

准备yaml文件

在/root/SlowFast/demo/AVA路径下,对【SLOWFAST_32x2_R101_50_50.yaml】文件进行修改:

  1. TRAIN下的CHECKPOINT_FILE_PATH,修改成上一步中下载并上传到云端的pkl文件的位置。
  2. TENSORBOARD、MODEL_VIS、TOPK这三行注释掉。
  3. 在DEMO下,注释掉WEBCAM,增加INPUT_VIDEO、OUTPUT_FILE,赋值的路径、名称可自定义。
  4. 在DEMO下,LABEL_FILE_PATH写ava.json的位置。
    在这里插入图片描述

在这里插入图片描述

准备素材

准备mp4的测试素材文件,上传到对应的文件夹。
我在/root/SlowFast路径下,创建了Video_Input、Video_Output文件夹。
在Video_Input文件夹下放了个命名为1.mp4的素材。

运行

在/root/SlowFast路径下,执行:

python tools/run_net.py --cfg demo/AVA/SLOWFAST_32x2_R101_50_50.yaml

在这里插入图片描述

运行结果

这次运行了三个视频片段。
第一个视频片段来源于《初来乍到》美剧。
第二、三个视频是成龙的打戏,下载自b站。虽然有一个视频有点糊,但是能识别出martial art就很感人。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

后记——不重要的痛苦的过程

一开始我在这样的环境里配置:
Pytorch 1.7.0, Python 3.8.8, CUDA 11.0
与上面步骤是一样的(这个不需要升pytorch的那句),
最后安装slowfast的时候,也会出现PIL的问题
但是重点不是这个
运行推断的时候会出现:

Traceback (most recent call last):File "tools/run_net.py", line 6, in <module>from slowfast.utils.misc import launch_jobFile "/root/SlowFast/slowfast/utils/misc.py", line 21, in <module>from slowfast.models.batchnorm_helper import SubBatchNorm3dFile "/root/SlowFast/slowfast/models/__init__.py", line 6, in <module>from .video_model_builder import ResNet, SlowFast  # noqaFile "/root/SlowFast/slowfast/models/video_model_builder.py", line 18, in <module>from . import head_helper, resnet_helper, stem_helperFile "/root/SlowFast/slowfast/models/head_helper.py", line 8, in <module>from detectron2.layers import ROIAlign
ImportError: cannot import name 'ROIAlign' from 'detectron2.layers' (unknown location)

感谢这位博主的这篇博客:
https://blog.csdn.net/WhiffeYF/article/details/113527759
让我还是回去从Python3.7开始配,即使安装detectron2的时候,要先将Pytorch升级为1.7.0,但是就不会出现这个难搞的错误了。

还有升级为Pytorch1.7的时候,用的是这句:

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

因为当时,单纯升级pytorch为1.7,不同时将cuda10.2升级为11的时候,会出现Could not run ‘torchvision::nms’这个问题。
幸好这个我之前遇到过解决过了。
在这篇博客:
https://blog.csdn.net/weixin_41793473/article/details/118574493?spm=1001.2014.3001.5501

前面提到的PIL的那个问题:

Installed /root/SlowFast
Processing dependencies for slowfast==1.0
Searching for sklearn
Reading https://pypi.org/simple/sklearn/
Downloading https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz#sha256=e23001573aa194b834122d2b9562459bf5ae494a2d59ca6b8aa22c85a44c0e31
Best match: sklearn 0.0
Processing sklearn-0.0.tar.gz
Writing /tmp/easy_install-bhbw6vsc/sklearn-0.0/setup.cfg
Running sklearn-0.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-bhbw6vsc/sklearn-0.0/egg-dist-tmp-2gs9d87i
file wheel-platform-tag-is-broken-on-empty-wheels-see-issue-141.py (for module wheel-platform-tag-is-broken-on-empty-wheels-see-issue-141) not found
file wheel-platform-tag-is-broken-on-empty-wheels-see-issue-141.py (for module wheel-platform-tag-is-broken-on-empty-wheels-see-issue-141) not found
file wheel-platform-tag-is-broken-on-empty-wheels-see-issue-141.py (for module wheel-platform-tag-is-broken-on-empty-wheels-see-issue-141) not found
warning: install_lib: 'build/lib' does not exist -- no Python modules to installcreating /opt/conda/lib/python3.8/site-packages/sklearn-0.0-py3.8.egg
Extracting sklearn-0.0-py3.8.egg to /opt/conda/lib/python3.8/site-packages
Adding sklearn 0.0 to easy-install.pth fileInstalled /opt/conda/lib/python3.8/site-packages/sklearn-0.0-py3.8.egg
Searching for PIL
Reading https://pypi.org/simple/PIL/
No local packages or working download links found for PIL
error: Could not find suitable distribution for Requirement.parse('PIL')

这篇关于SlowFast-入门1-动作识别-部署与测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/275089

相关文章

从入门到精通详解Python虚拟环境完全指南

《从入门到精通详解Python虚拟环境完全指南》Python虚拟环境是一个独立的Python运行环境,它允许你为不同的项目创建隔离的Python环境,下面小编就来和大家详细介绍一下吧... 目录什么是python虚拟环境一、使用venv创建和管理虚拟环境1.1 创建虚拟环境1.2 激活虚拟环境1.3 验证虚

redis-sentinel基础概念及部署流程

《redis-sentinel基础概念及部署流程》RedisSentinel是Redis的高可用解决方案,通过监控主从节点、自动故障转移、通知机制及配置提供,实现集群故障恢复与服务持续可用,核心组件包... 目录一. 引言二. 核心功能三. 核心组件四. 故障转移流程五. 服务部署六. sentinel部署

Java List 使用举例(从入门到精通)

《JavaList使用举例(从入门到精通)》本文系统讲解JavaList,涵盖基础概念、核心特性、常用实现(如ArrayList、LinkedList)及性能对比,介绍创建、操作、遍历方法,结合实... 目录一、List 基础概念1.1 什么是 List?1.2 List 的核心特性1.3 List 家族成

Linux部署中的文件大小写问题的解决方案

《Linux部署中的文件大小写问题的解决方案》在本地开发环境(Windows/macOS)一切正常,但部署到Linux服务器后出现模块加载错误,核心原因是Linux文件系统严格区分大小写,所以本文给大... 目录问题背景解决方案配置要求问题背景在本地开发环境(Windows/MACOS)一切正常,但部署到

c++日志库log4cplus快速入门小结

《c++日志库log4cplus快速入门小结》文章浏览阅读1.1w次,点赞9次,收藏44次。本文介绍Log4cplus,一种适用于C++的线程安全日志记录API,提供灵活的日志管理和配置控制。文章涵盖... 目录简介日志等级配置文件使用关于初始化使用示例总结参考资料简介log4j 用于Java,log4c

史上最全MybatisPlus从入门到精通

《史上最全MybatisPlus从入门到精通》MyBatis-Plus是MyBatis增强工具,简化开发并提升效率,支持自动映射表名/字段与实体类,提供条件构造器、多种查询方式(等值/范围/模糊/分页... 目录1.简介2.基础篇2.1.通用mapper接口操作2.2.通用service接口操作3.进阶篇3

Python自定义异常的全面指南(入门到实践)

《Python自定义异常的全面指南(入门到实践)》想象你正在开发一个银行系统,用户转账时余额不足,如果直接抛出ValueError,调用方很难区分是金额格式错误还是余额不足,这正是Python自定义异... 目录引言:为什么需要自定义异常一、异常基础:先搞懂python的异常体系1.1 异常是什么?1.2

Python实现Word转PDF全攻略(从入门到实战)

《Python实现Word转PDF全攻略(从入门到实战)》在数字化办公场景中,Word文档的跨平台兼容性始终是个难题,而PDF格式凭借所见即所得的特性,已成为文档分发和归档的标准格式,下面小编就来和大... 目录一、为什么需要python处理Word转PDF?二、主流转换方案对比三、五套实战方案详解方案1:

基于Python Playwright进行前端性能测试的脚本实现

《基于PythonPlaywright进行前端性能测试的脚本实现》在当今Web应用开发中,性能优化是提升用户体验的关键因素之一,本文将介绍如何使用Playwright构建一个自动化性能测试工具,希望... 目录引言工具概述整体架构核心实现解析1. 浏览器初始化2. 性能数据收集3. 资源分析4. 关键性能指

使用IDEA部署Docker应用指南分享

《使用IDEA部署Docker应用指南分享》本文介绍了使用IDEA部署Docker应用的四步流程:创建Dockerfile、配置IDEADocker连接、设置运行调试环境、构建运行镜像,并强调需准备本... 目录一、创建 dockerfile 配置文件二、配置 IDEA 的 Docker 连接三、配置 Do