SlowFast-入門1-動作識別-部署與測試
簡介
GitHub:
//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+//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 //download.pytorch.org/whl/torch_stable.html git clone //github.com/facebookresearch/detectron2.git pip install -e detectron2 git clone //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更多了解
然後後續的推斷測試中也沒影響,爺累了,所以先不管他。
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 | 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】文件進行修改:
-
TRAIN下的CHECKPOINT_FILE_PATH,修改成上一步中下載並上傳到雲端的pkl文件的位置。
-
TENSORBOARD、MODEL_VIS、TOPK這三行注釋掉。
-
在DEMO下,注釋掉WEBCAM,增加INPUT_VIDEO、OUTPUT_FILE,賦值的路徑、名稱可自定義。
-
在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_job File "/root/SlowFast/slowfast/utils/misc.py", line 21, in <module> from slowfast.models.batchnorm_helper import SubBatchNorm3d File "/root/SlowFast/slowfast/models/__init__.py", line 6, in <module> from .video_model_builder import ResNet, SlowFast # noqa File "/root/SlowFast/slowfast/models/video_model_builder.py", line 18, in <module> from . import head_helper, resnet_helper, stem_helper File "/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)
感謝這位部落客的這篇部落格:
【SlowFast復現】SlowFast Networks for Video Recognition復現程式碼 使用自己的影片進行demo檢測
讓我還是回去從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 //download.pytorch.org/whl/torch_stable.html
因為當時,單純升級pytorch為1.7,不同時將cuda10.2升級為11的時候,會出現Could not run 『torchvision::nms』這個問題。
幸好這個我之前遇到過解決過了。
在這篇部落格:
Could not run 『torchvision::nms『 with arguments from the 『CUDA『 backend的解決;用GPU跑Detectron2的demo
前面提到的PIL的那個問題:
Installed /root/SlowFast
Processing dependencies for slowfast==1.0
Searching for sklearn
Reading //pypi.org/simple/sklearn/
Downloading //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 install
creating /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 file
Installed /opt/conda/lib/python3.8/site-packages/sklearn-0.0-py3.8.egg
Searching for PIL
Reading //pypi.org/simple/PIL/
No local packages or working download links found for PIL
error: Could not find suitable distribution for Requirement.parse('PIL')
參考
-
^本文來源CSDN部落客「小林愛學習99」的投稿,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明 //blog.csdn.net/weixin_41793473/article/details/119177592