赞
踩
对于二维图像背后的三维世界建模,哪一种三维表示最合适?现在常见的表示方法有点云、体素和网格,其中多边形网格具有良好的紧致性和几何性质。但是使用神经网络直接由多边形网格生成图像比较困难,因为光栅化的过程阻止了反向传播。
因此,本项目所参考的Repo的原作者提出了一个近似的梯度栅格化,使渲染集成到神经网络。使用这个渲染器,可以执行带有轮廓图像监督的单图像三维网格重建,并且该系统比现有的基于体素的方法更好。
利用此类可微分的多边形网格光栅化与渲染,才有机会在元宇宙三维世界中进行视觉上的物体生成。
neural-renderer-paddle。欢迎来点Star哦!
安装笔者预先准备好的包文件,完成环境配置
# 安装命令
# git clone https://github.com/AgentMaker/neural-renderer-paddle
%pip install neural-renderer-paddle/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Processing ./neural-renderer-paddle Collecting scikit-image~=0.19.0 (from neural-renderer-paddle==1.1.3.3) [?25l Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ae/3d/b2662293ff78c5a500098fb1edb23ffa7c3dcd39da8bfdf0e74a8f2a1bdb/scikit_image-0.19.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (55.4MB) [K |████████████████████████████████| 55.4MB 588kB/s eta 0:00:01 [?25hRequirement already satisfied: paddlepaddle-gpu~=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from neural-renderer-paddle==1.1.3.3) (2.2.1.post101) Requirement already satisfied: pillow!=7.1.0,!=7.1.1,!=8.3.0,>=6.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (7.1.2) Collecting PyWavelets>=1.1.1 (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) [?25l Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a1/9c/564511b6e1c4e1d835ed2d146670436036960d09339a8fa2921fe42dad08/PyWavelets-1.2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (6.1MB) [K |████████████████████████████████| 6.2MB 11.4MB/s eta 0:00:01 [?25hRequirement already satisfied: numpy>=1.17.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (1.20.3) Requirement already satisfied: packaging>=20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (20.9) Requirement already satisfied: scipy>=1.4.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (1.6.3) Collecting tifffile>=2019.7.26 (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) [?25l Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/38/85ae5ed77598ca90558c17a2f79ddaba33173b31cf8d8f545d34d9134f0d/tifffile-2021.11.2-py3-none-any.whl (178kB) [K |████████████████████████████████| 184kB 5.1MB/s eta 0:00:01 [?25hRequirement already satisfied: networkx>=2.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (2.4) Requirement already satisfied: imageio>=2.4.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (2.6.1) Requirement already satisfied: decorator in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (4.4.2) Requirement already satisfied: protobuf>=3.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (3.14.0) Requirement already satisfied: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (1.15.0) Requirement already satisfied: astor in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (0.8.1) Requirement already satisfied: requests>=2.20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (2.22.0) Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from packaging>=20.0->scikit-image~=0.19.0->neural-renderer-paddle==1.1.3.3) (2.4.2) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (1.25.6) Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (2.8) Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (2019.9.11) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu~=2.2.0->neural-renderer-paddle==1.1.3.3) (3.0.4) Building wheels for collected packages: neural-renderer-paddle Building wheel for neural-renderer-paddle (setup.py) ... [?25ldone [?25h Created wheel for neural-renderer-paddle: filename=neural_renderer_paddle-1.1.3.3-cp37-none-any.whl size=31171 sha256=376d0112f2cc63893da40226f8029f38c40bfb1a3ff64e36d3553fe610f89820 Stored in directory: /home/aistudio/.cache/pip/wheels/7d/a9/a3/fdbdc97716f908818b827591eecb4f42348bf721f3089d8201 Successfully built neural-renderer-paddle Installing collected packages: PyWavelets, tifffile, scikit-image, neural-renderer-paddle Successfully installed PyWavelets-1.2.0 neural-renderer-paddle-1.1.3.3 scikit-image-0.19.0 tifffile-2021.11.2 Note: you may need to restart the kernel to use updated packages.
%cd ~/neural-renderer-paddle/examples/
/home/aistudio/neural-renderer-paddle/examples
import warnings
warnings.filterwarnings("ignore")
from example1 import main as example1
from example2 import main as example2
from example3 import main as example3
from example4 import main as example4
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working from collections import MutableMapping /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working from collections import Iterable, Mapping /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working from collections import Sized Compiling user custom op, it will cost a few seconds..... cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working return (isinstance(seq, collections.Sequence) and Compiling user custom op, it will cost a few seconds..... cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working return (isinstance(seq, collections.Sequence) and W1211 11:00:06.778892 400 custom_operator.cc:522] Operator (load_textures)has been registered. Compiling user custom op, it will cost a few seconds..... cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working return (isinstance(seq, collections.Sequence) and W1211 11:00:13.350206 400 custom_operator.cc:522] Operator (backward_depth_map)has been registered. W1211 11:00:13.350270 400 custom_operator.cc:522] Operator (forward_texture_sampling)has been registered. W1211 11:00:13.350276 400 custom_operator.cc:522] Operator (backward_pixel_map)has been registered. W1211 11:00:13.350281 400 custom_operator.cc:522] Operator (load_textures)has been registered. W1211 11:00:13.350286 400 custom_operator.cc:522] Operator (forward_face_index_map)has been registered. W1211 11:00:13.350289 400 custom_operator.cc:522] Operator (backward_textures)has been registered.
example1()
W1211 11:07:30.223091 400 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W1211 11:07:30.228544 400 device_context.cc:465] device: 0, cuDNN Version: 7.6.
Drawing: 0%| | 0/90 [00:00<?, ?it/s]/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
Drawing: 100%|██████████| 90/90 [00:02<00:00, 30.09it/s]
# 显示渲染结果
from IPython.display import display, Image
display(Image('data/example1.gif'))
<IPython.core.display.Image object>
example2()
Optimizing: 0%| | 0/300 [00:00<?, ?it/s]/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
Optimizing: 100%|██████████| 300/300 [00:17<00:00, 16.71it/s]
Drawing: 100%|██████████| 90/90 [00:02<00:00, 32.14it/s]
from IPython.display import display, Image
print('拟合过程:')
display(Image('data/example2_optimization.gif'))
print('拟合结果:')
display(Image('data/example2_result.gif'))
拟合过程:
<IPython.core.display.Image object>
拟合结果:
<IPython.core.display.Image object>
example3()
Optimizing: 0%| | 0/300 [00:00<?, ?it/s]/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
Optimizing: 100%|██████████| 300/300 [00:17<00:00, 17.55it/s]
Drawing: 100%|██████████| 90/90 [00:05<00:00, 13.89it/s]
from IPython.display import display, Image
print('纹理参考图片:')
display(Image('data/example3_ref.png'))
print('纹理拟合结果:')
display(Image('data/example3_result.gif'))
纹理参考图片:
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nl9xZa6Z-1639748993706)(output_17_1.png)]](https://img-blog.csdnimg.cn/34460af47e4f446da9514d298e124608.png)
纹理拟合结果:
<IPython.core.display.Image object>
example4()
0%| | 0/1000 [00:00<?, ?it/s]/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
Optimizing (loss 69.2500): 15%|█▍ | 148/1000 [00:07<00:49, 17.35it/s]
from IPython.display import display, Image
print('初始视角:')
display(Image('data/example4_init.png'))
print('欲拟合的未知视角:')
display(Image('data/example4_ref.png'))
print('拟合过程:')
display(Image('data/example4_result.gif'))
初始视角:
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0XJlFFY6-1639748993707)(output_20_1.png)]](https://img-blog.csdnimg.cn/befd5dabf5e64b0188b8f8610dbe1640.png)
欲拟合的未知视角:
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eXi61JSG-1639748993708)(output_20_3.png)]](https://img-blog.csdnimg.cn/6f37552975fa45cdb364e72d45d9db9e.png)
拟合过程:
<IPython.core.display.Image object>
Neural 3D Mesh Renderer 可谓是开启了深度学习的新时代,在它出现之后,图形学也逐渐走进了深度学习的世界。
元宇宙的世界,就如同是游戏的世界,进行了一个概念的拓展。所以AI在未来元宇宙的布局中肯定是必不可少的。
可微渲染结合参数化三维人脸模型FLAME可以实现AI智能捏脸,若需要更进一步,使用SMPL-X,则有可能进行全身的AI建模。
而要实现这些,本篇项目便是大的基础。不过因为是基础,仍需要很多的建设,本项目还很难实现制作元宇宙虚拟形象的功能。大家可以期待笔者未来在此类项目中的投入。
最后,欢迎给我们团队的neural-renderer-paddle仓库点个Star。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。