【Sketch2Pose项目环境搭建】win10+Anoconda+VScode

最近我尝试在windows上运行Sketch2Pose这个项目,但前前后后花了很久,疯狂踩坑,嗯,很崩溃,遇到很多问题。于是写这篇博客,结合原仓库Readme内容,记录一下项目环境搭建的过程。

搭建环境: win10+Anoconda+vscode。

以下命令根据适用性,在VScode终端或Git Bash中输入。在Git Bash里用的,都是Linux命令。

正式搭建

1. conda搭建pytorch虚拟环境

安装python=3.9的pytorch环境

一定要python=3.9,问就是踩坑了= =

2. 准备所需数据和模型文件

在sketch2pose目录下新建一个名为assets的文件夹,在smplx官方网站下载models_smplx_v1_1.zip,将zip文件放置于assets文件夹中。

然后Git Bash执行以下命令。

sh ./scripts/download.sh

要是有卡的下载不下来的,建议手动下载一下。

3. 安装所需包

安装requirements.txt,将最后两行的selfcontact和smplx删除之后再执行。因为直接执行的话,不管是否翻墙我都会失败。

pip install -r requirements.txt

转移到conda虚拟环境目录。

cd D:/software/Anaconda/envs/pytorch38/Lib/site-packages/

安装smplx库。

  • 正确命令
pip install git+https://github.com/vchoutas/smplx.git@5fa20519735cceda19afed0beeabd53caef711cd
  • 上述命令出错后,我尝试的方法——去GitHub仓库找到对应的版本仓库,直接进行下载。解压到Sketch2Pose根目录,然后使用以下命令
pip install -e smplx-5fa20519735cceda19afed0beeabd53caef711cd

安装selfcontact库,需要安装@08da422526419c24736c0616bca49623e442c26a这个版本。目前我看到的最新的提交就是这个版本,所以我这里采用直接安装了。如果你发现最新版本不是这个,并且直接用命令也无法安装,就按smplx库一样的方法来操作吧。

git clone https://github.com/muelea/selfcontact.git
pip install -e selfcontact

最后去anoconda虚拟环境里site-packages里检查一下,有smplx和selfcontact这两个文件夹,就证明没什么问题了。我的虚拟环境目录是D:\software\Anaconda\envs\pytorch39\Lib\site-packages

4. 执行patch文件

在代码所在总目录sketch2pose下执行Git Bash(我也不确定有没有必要一定要用管理员身份),随后手动执行三个patch,patch+待修改文件目录+diff文件位置

注意:

  1. D:/software/Anaconda/envs/pytorch38/Lib/site-packages/这是我的anonconda虚拟环境的路径,需要更改成自己的。
  2. 执行完git可能有报错说,Huck #: xxx rejected to xxx,或者什么Failed什么什么,可以点进去路径里的reject文件,看看有哪些修改被拒绝了,被拒绝的就手动更改以下文件。(这里我暂时也没找到更好的解决方案,但只是手动改改被拒绝的部分,其实也不多)
patch D:/software/Anaconda/envs/pytorch39/Lib/site-packages/selfcontact/selfcontact/selfcontact.py ./patches/selfcontact.diff
patch D:/software/Anaconda/envs/pytorch39/Lib/site-packages/smplx/smplx/body_models.py ./patches/smplx.diff
patch D:/software/Anaconda/envs/pytorch39/Lib/site-packages/torchgeometry/core/conversions.py ./patches/torchgeometry.diff

5. 第一次测试运行

带selfcontact的测试

python src/pose.py --save-path "./output" --img-path "./data/images" --use-contacts --use-natural --use-cos --use-angle-transf

不带selfcontact的测试

python src/pose.py --save-path "./output" --img-path "./data/images" --use-natural --use-cos --use-angle-transf

6. 遇到问题

这里列举一些我遇到的问题,以警示。

安装过程中,在网络上搜不到解答的问题,我是去GitHub仓库原作者询问他的,后来发现都是因为我在windows上部署环境,于是就自己更改命令,因为不熟悉所以更改后的,没有完全符合他给的Readme要求来进行安装导致的错误。(555555作者真的好好,都解答我了T T)
所以,要是有Linux机器,网络也良好的话,按作者给的方法,应该可以很轻松安装好的。

1)AttributeError: ‘SMPLXOutput’ object has no attribute ‘A’

Namespace(bone_parametrization_path='./models/smplx_parametrization/bone_to_param2.npy', c_cont2d=1, c_f=1000, c_msc=17500, c_mse=0, c_par=10, c_parallel=100, c_reg=1000, contact_model_path='./models/contact_hrn_w32_256x192.onnx', device='cuda', essentials_dir='./models/smplify-xmc-essentials', fist=None, foot_inds_path='./models/smplx_parametrization/foot_inds.npy', img_path='./data/images', parametrization_path='./models/smplx_parametrization/parametrization.npy', pose_estimation_model_path='./models/hrn_w48_384x288.onnx', save_path='./output', smpl_mean_params_path='./models/data/smpl_mean_params.npz', smpl_model_dir='./models/models/smplx', smpl_type='smplx', spin_model_path='./models/spin_model_smplx_eft_18.pt', use_angle_transf=True, use_contacts=True, use_cos=True, use_msc=False, use_natural=True)C:\Users\CICI\AppData\Roaming\Python\Python38\site-packages\torchvision\models_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and
will be removed in 0.15, please use 'weights' instead.
warnings.warn(
C:\Users\CICI\AppData\Roaming\Python\Python38\site-packages\torchvision\models_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing weights=ResNet50_Weights.IMAGENET1K_V1. You can also use
weights=ResNet50_Weights.DEFAULT to get the most up-to-date weights.
warnings.warn(msg)
D:\software\Anaconda\envs\pytorch38\lib\site-packages\selfcontact\selfcontact.py:109: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
torch.tensor(hd_operator).float())
Traceback (most recent call last):
File "src/pose.py", line 1922, in
main()
File "src/pose.py", line 1815, in main
spin_step(
File "src/pose.py", line 1374, in spin_step
) = get_pred_and_data(
File "src/pose.py", line 351, in get_pred_and_data
rotmat, betas, camera, smpl_output, zz = get_predictions(
File "src/pose.py", line 335, in get_predictions
smpl_output, rotmat = get_smpl_output(
File "src/pose.py", line 319, in get_smpl_output
smpl_output = smpl(
File "C:\Users\CICI\AppData\Roaming\Python\Python38\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "D:\python\sketch2pose\src\spin\smpl.py", line 236, in forward
A=smpl_output.A,
AttributeError: 'SMPLXOutput' object has no attribute 'A'

原因:没有正确执行patch文件,即第4步。

2)RuntimeError: einsum(): subscript l has size 26 for operand 1 which does not broadcast with previously seen size 20

Namespace(pose_estimation_model_path='./models/hrn_w48_384x288.onnx', contact_model_path='./models/contact_hrn_w32_256x192.onnx', device='cuda', spin_model_path='./models/spin_model_smplx_eft_18.pt', smpl_type='smplx', smpl_model_dir='./models/models/smplx', smpl_mean_params_path='./models/data/smpl_mean_params.npz', essentials_dir='./models/smplify-xmc-essentials', parametrization_path='./models/smplx_parametrization/parametrization.npy', bone_parametrization_path='./models/smplx_parametrization/bone_to_param2.npy', foot_inds_path='./models/smplx_parametrization/foot_inds.npy', save_path='./output', img_path='./data/images', use_contacts=True, use_msc=False, use_natural=True, use_cos=True, use_angle_transf=True, c_mse=0, c_par=10, c_f=1000, c_parallel=100, c_reg=1000, c_cont2d=1, c_msc=17500, fist=None)
D:\software\Anaconda\envs\pytorch39\lib\site-packages\torchvision\models\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
D:\software\Anaconda\envs\pytorch39\lib\site-packages\torchvision\models\_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet50_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet50_Weights.DEFAULT` to get the most up-to-date weights.
  warnings.warn(msg)
Traceback (most recent call last):
  File "d:\python\Sketch2Pose\src\pose.py", line 1922, in <module>
    main()
  File "d:\python\Sketch2Pose\src\pose.py", line 1815, in main
    spin_step(
  File "d:\python\Sketch2Pose\src\pose.py", line 1374, in spin_step
    ) = get_pred_and_data(
  File "d:\python\Sketch2Pose\src\pose.py", line 351, in get_pred_and_data
    rotmat, betas, camera, smpl_output, zz = get_predictions(
  File "d:\python\Sketch2Pose\src\pose.py", line 335, in get_predictions
    smpl_output, rotmat = get_smpl_output(
  File "d:\python\Sketch2Pose\src\pose.py", line 319, in get_smpl_output
    smpl_output = smpl(
  File "D:\software\Anaconda\envs\pytorch39\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "d:\python\Sketch2Pose\src\spin\smpl.py", line 199, in forward
    smpl_output = super(SMPLX, self).forward(*args, **kwargs)
  File "D:\software\Anaconda\envs\pytorch39\lib\site-packages\smplx\body_models.py", line 1242, in forward
    vertices, joints, A = lbs(shape_components, full_pose, self.v_template,
  File "D:\software\Anaconda\envs\pytorch39\lib\site-packages\smplx\lbs.py", line 209, in lbs
    v_shaped = v_template + blend_shapes(betas, shapedirs)
  File "D:\software\Anaconda\envs\pytorch39\lib\site-packages\smplx\lbs.py", line 295, in blend_shapes
    blend_shape = torch.einsum('bl,mkl->bmk', [betas, shape_disps])
  File "D:\software\Anaconda\envs\pytorch39\lib\site-packages\torch\functional.py", line 373, in einsum
    return einsum(equation, *_operands)
  File "D:\software\Anaconda\envs\pytorch39\lib\site-packages\torch\functional.py", line 378, in einsum
    return _VF.einsum(equation, operands)  # type: ignore[attr-defined]
RuntimeError: einsum(): subscript l has size 26 for operand 1 which does not broadcast with previously seen size 20

原因:没有安装正确版本的smplx库,要严格按照prepare.sh里的指示。

3)IndexError: tensors used as indices must be long, byte or bool tensors

@谢谢这位哥

在这里插入图片描述

4)torch.cuda.OutOfMemoryError: CUDA out of memory.

这个错误是在我运行带有selfcontact的测试时发生的,如果不带selfcontact就没有这个错误。

很奇怪,我也不知道为什么GPU不够,但明明占用率很低。

在这里插入图片描述

后来找到了解决方案,显存不够,于是我就用以下代码换了一张卡。

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"

此外,还看到了一些其他的解决方案link -> Pytorch运行错误:CUDA out of memory处理过程


至此,完美搭建项目并运行结束。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值