内容介绍
本文主要介绍如何在自己的PC电脑上搭建官方pytorch stacked hourglass 运行环境。
官方stacked hourglass 地址:https://github.com/princeton-vl/pytorch_stacked_hourglass
参考网址
论文地址:https://arxiv.org/abs/1711.06753v4
论文翻译:https://tongtianta.site/paper/4646
MPII数据集下载:http://human-pose.mpi-inf.mpg.de/#download
评估方法参考:http://human-pose.mpi-inf.mpg.de/#evaluation
论文介绍:https://blog.csdn.net/guo1988kui/article/details/84589540
Github上stacked hourglass实现汇总:https://paperswithcode.com/paper/stacked-hourglass-networks-for-human-pose
搭建步骤
基础依赖:
- Python 3 (code has been tested on Python 3.6)
- PyTorch (code tested with 1.0)
- CUDA and cuDNN
- Python packages (not exhaustive): opencv-python, tqdm, cffi, h5py, scipy (tested with 1.1.0)
代码结构:
data/
: data loading and data augmentation codemodels/
: network architecture definitionstask/
: task-specific functions and training configurationutils/
: image processing code and miscellaneous helper functionstrain.py
: code for model trainingtest.py
: code for model evaluation- exp/:自己手动创建,用于存放pt文件
拉取官方代码:
git clone git@github.com:princeton-vl/pytorch_stacked_hourglass.git
下载数据集
http://human-pose.mpi-inf.mpg.de/#download
下载完之后解压,将解压后的文件夹 放在 data/MPII/ 路径下。
如果你想自己重新训练网络,请参考官方README。我下面主要讲如何用官方训练好的 pt文件来进行本地运行测试
下载官方提供的pt文件:
2HG pretrained model:http://www-personal.umich.edu/~cnris/original_2hg/checkpoint.pt
8HG pretrained model:http://www-personal.umich.edu/~cnris/original_8hg/checkpoint.pt
①在 项目的直接目录下新建文件夹: exp/, 然后在exp/ 下新建文件夹 2hg,把2hg的权重放在这里;
同理,把8hg的权重放在 8hg/ 文件夹里。 注意:要把权重文件的名字改为 checkpoint.pt
②把 data\MPII\ref.py 中 annot_dir 和 img_dir 改成自己本地相应的路径。
运行
以8hg的权重运行:
在项目的直接目录下,运行以下命令:
python test.py -c 8hg
如果运行过程中,出现以下错误:
from scipy.misc import imread中出现ImportError:No module named 'imread'
解决方法:
pip install scipy==1.1.0
pip install pillow==6.0.0
以2hg的权重运行:
在项目的直接目录下,运行以下命令:
python test.py -c 2hg
如果报以下错误: missing key(s) in state_dict:
File "C:\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 769, in load_state_dict
self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Trainer:
Missing key(s) in state_dict: "model.module.hgs.2.0.up1.bn1.weight", "model.module.hgs.2.0.up1.bn1.bias", "model.module.hgs.2.0.up1.bn1.running_mean", "model.module.hgs.2.0.up1.bn1.running_var", "model.module.hgs.2.
解决方法:打开 task\pose.py文件,修改 __config__ 中 nstack对应的值为 2 .
正确运行的结果如下图: