【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

安装smplx库。(为什么先安这个呢,因为另一个比较麻烦)

pip install git+https://github.com/vchoutas/smplx.git

安装selfcontact库。

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

有可能也可以直接执行这个命令,说不定会成功。

pip install git+https://github.com/muelea/selfcontact.git

最后去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.py ./patches/selfcontact.diff
patch D:/software/Anaconda/envs/pytorch39/Lib/site-packages/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

6. 遇到问题

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

T T搜也没搜到,让我想想该怎么解决。。明天再更新

你可能感兴趣的:(vscode,git,python)