【记录WindowsAIpose&MotionBert论文环境复现(有大量试错步骤请谨慎操作】

记录WindowsAIpose&MotionBert论文环境复现(有大量试错步骤请谨慎操作)

注意MotionBert论文没有复现Human Mesh Recovery步骤 MotionBERT-github

AlphaPose

基本的环境创建AlphaPose-github

conda create -n alphapose python=3.7 -y

conda activate alphapose 

cd C:\Users\xxxxx\Desktop\Junior_year\AlphaPose-master

python setup.py build develop

pip install cython 

python setup.py build develop --user

在conda命令窗口当前项目目录下面运行执行了setup.py脚本中的build和develop命令报错

Windows用户安装报错:maskApi.c
c1: fatal error C1083: 无法打开源文件:../common/maskApi.c”: No such file or directory
error: Setup script exited with error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  1. 你可以不考虑这个因素,先省略这一步后面出问题再回来看看是不是这个原因)Visaul Studio Installer工具安装Windows 10/11 SDK​​ 选择SDK安装

  2. 结果查阅大量资料发现 c1: fatal error C1083: 无法打开源文件是cython版本版本问题,执行pip install cython==0.29.36命令减低版本使其存在maskApi.c库;

  3. 之后我改变了一下conda install matplotlib=3.3.4版本 在这里插入图片描述

  4. 继续conda环境进行安装conda install -c fvcore -c iopath -c conda-forge fvcore iopath

  5. Windows用户暂时不需要其他命令,接下来运行测试参考了这篇Liunx系统文章[^1] HermanYe996作者MotionBert论文解读及详细复现教程;

  6. 添加必要文件和文件夹 接着从github的项目页下载yolov3-spp.weight到AlphaPose/detector/yolo/data ,如果没有这个文件夹就创建一个;

  7. 下载预训练模型Halpe dataset (26 keypoints) FastPose预训练模型到AlphaPose/pretrained_models;

  8. 测试alphapose运行argparse命令参数

python scripts/demo_inference.py --cfg configs/halpe_26/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/halpe26_fast_res50_256x192.pth --indir examples/demo/ --save_img;

测试结果

  1. 观察infer_wild.py文件parse_args():函数参数设置理解如下内容:AlphaPose/examples/demo文件夹下的图片将被用作处理,AlphaPose/examples/res文件夹下将出现处理后的结果;
  2. 可以自己调整参数放置到喜欢的文件夹下面,如下命令是默认路径:
    官方提供的图片测试
python scripts/demo_inference.py --cfg configs/halpe_26/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/halpe26_fast_res50_256x192.pth --indir examples/demo/ --save_img;
  1. 将自己的视频导入模型进行姿态估计
python scripts/demo_inference.py --cfg configs/halpe_26/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/halpe26_fast_res50_256x192.pth --video examples/demo/test_path_video.mp4 --save_video
initialize VideoWriter
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 223/223 [02:35<00:00,  1.43it/s]
===========================> Finish Model Running.
===========================> Rendering remaining images in the queue...
===========================> If this step takes too long, you can enable the --vis_fast flag

json
(最好拍摄全身我这里只是随便演示)拍摄同学视频输出结果如下图所示:
MP4

根据自己的环境情况,安装缺失的一些库,特别注意pyyaml和pycocotools两个库的安装:

  1. 注意AttributeError: module ‘yaml’ has no attribute 'FullLoader’这一步FullLoader 属性是在pyyaml5.1及以上版本中才有的比较重要

  2. 注意​由于windows下是不能直接使用conda install 或者pip install pycocotools我们需要根据自己环境情况去到pycocotools-windows自行下载whl,进入刚刚下载的轮子所在的文件夹执行:
    (alphapose) D:\whl>pip pycocotools_windows-2.0-cp37-cp37-win_amd64.whlwhl

  3. 注意pip uninstall pyyaml命令无效ERROR: Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.所以我们要使用conda环境更新一下版本:
    conda install -c anaconda pyyaml=5.3.1

  4. 检查自己是否缺失的第三方库如下:

pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple

conda install -c conda-forge scipy

conda install -c conda-forge terminaltables

pip install -e git+https://github.com/samson-wang/cython_bbox.git#egg=cython-bbox
​这个命令是使用pip安装一个Python包,该包位于GitHub上的https://github.com/samson-wang/cython_bbox.git仓库中。
通过`-e`参数,该包将被以可编辑模式安装,即在你的本地环境中对该包进行修改后,会立即生效,而不需要重新安装。
`egg=cython-bbox`是为了指定包的名称为`cython-bbox`

MotionBert

基本的环境创建,pytorch建议用whl下载方式下载,注意不要怕自己电脑的cuda版本太高!我的cuda12.3都能用v1.13.0版本的pytorch

注意由于环境兼容性问题!我不能直接按照官方文档在命令末尾添加anaconda,而且检查相关依赖的包太久了,清理conda缓存也没什么用我就只能先普普通通的创建一个3.7的虚拟环境(最好先按照官方的命令创建环境conda create -n motionbert python=3.7 anaconda)

conda create -n motionbert python=3.7
conda activate motionbert
# CUDA 11.6
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.6 -c pytorch -c nvidia
# CUDA 11.6 whl下载方式
pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116
pip install -r requirements.txt

基环境配置完成之后可能会显示一大堆环境兼容的报错,可以查看当前环境的 conda list 报错的第三方库基本都已经在里面了所以没必要在下载那些冲突的库

Motionbert中生成3Dpose参考docs/pose3d.md文件,下载best_epoch.bin并保存到checkpoint/pose3d/FT_MB_lite_MB_ft_h36m_global_lite/文件夹目录(没有就创建一个)

我的例子是在MotionBERT目录下执行:

python infer_wild.py --vid_path C:\Users\xxxxx\Desktop\Junior_year\AlphaPose-master\examples\demo\video_resjson_26\AlphaPose_kuqi.mp4 --json_path C:\Users\xxxxx\Desktop\Junior_year\AlphaPose-master\examples\demo\video_resjson_26\alphapose-results.json --out_path output

注意Windows用户最大的问题是终端直接运行infer_wild.py文件是会报以下错误的:

    RuntimeError:
    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.
    
    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

lssuues上面有一位大佬修改了infer_wild.py文件,写了一个方法完美解决了Windows用户这个报错问题Zhou Hao Fix infer_wild.py error when running on windows #69

MotionBert结果

MotionBert结果

+  self._iterator = self._get_iterator()
MAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (930, 924) to (944, 928) to ensure video compatibility with most codecs and players. To 
prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).
[swscaler @ 0000023afe7c0f80] Warning: data is not aligned! This can lead to a speed loss
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 237/237 [00:56<00:00,  4.18it/s] 

MotionBert论文地址

https://arxiv.org/pdf/2210.06551.pdf

微调模型评估示例

python train_mesh.py --config configs/mesh/MB_ft_pw3d.yaml --evaluate checkpoint/mesh/FT_MB_release_MB_ft_pw3d/best_epoch.bin
python train.py --config configs/pose3d/MB_ft_h36m_global_lite.yaml --evaluate checkpoint/pose3d/FT_MB_lite_MB_ft_h36m_global_lite/best_epoch.bin

简单的用Flask演示模型成果

1.HTML界面部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>人体姿态识别</title>
    <style>
        body {
            font-family: 'Arial', sans-serif; /* 设置默认字体 */
            background-color: #f4f4f4; /* 页面背景色 */
            color: #333; /* 文字颜色 */
            margin: 0;
            padding: 20px;
            text-align: center; /* 使内容居中显示 */
        }
        h1 {
            color: #0056b3; /* 标题颜色 */
            font-size: 2em; /* 标题字体大小 */
        }
        p {
            font-size: 1.2em; /* 段落字体大小 */
            margin: 10px 0; /* 段落上下边距 */
        }
        .video-container {
            display: flex;
            justify-content: space-around; /* 视频间平均分布 */
            margin: 20px 0; /* 视频容器上下边距 */
            padding: 10px;
            background-color: #fff; /* 视频容器背景色 */
            border: 1px solid #ddd; /* 视频容器边框 */
            border-radius: 5px; /* 视频容器边框圆角 */
            box-shadow: 0 2px 4px rgba(0,0,0,0.1); /* 视频容器阴影 */
        }
        video {
            margin: 0 10px; /* 视频左右边距 */
            box-shadow: 0 2px 6px rgba(0,0,0,0.2); /* 视频阴影 */
        }
    </style>
</head>
<body>
    <h1>人体姿态识别</h1>
    <!-- 预测结果显示位置 -->
    <p style="color:red">预测结果为:{{ prediction }}</p> <!-- 假设这是动态内容,颜色已设置为红色 -->

    <div class="video-container">
        <video width="320" height="240" controls>
            <source src="/static/AlphaPose_shuaijiao.mp4" type="video/mp4">
        </video>
        <video width="320" height="240" controls>
            <source src="/static/X3D.mp4" type="video/mp4">
        </video>
    </div>
    <div class="video-container">
        <video width="320" height="240" controls>
            <source src="/static/shuaijiao.mp4" type="video/mp4">
        </video>
        <video width="320" height="240" controls>
            <source src="/static/mesh.mp4" type="video/mp4">
        </video>
    </div>
</body>
</html>

2.Flask, render_template获取自己大模型模型微调姿态预测结果显示

return render_template('index.html', prediction="predicted_label_name = get_predicted_label()")

  • 20
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值