Commit d95cd255 authored by fengzch-das's avatar fengzch-das
Browse files

update readme

parent 79d832ca
Pipeline #2867 failed with stages
in 0 seconds
# DRTK – Differentiable Rendering Toolkit # <div align="center"><strong>DRTK – Differentiable Rendering Toolkit</strong></div>
## 简介
This package is a PyTorch library that provides functionality for differentiable rasterization. 这个软件包是一个 PyTorch 库,提供了 可微分栅格化 的功能.
It consists of five main components: ## 安装
组件支持组合
* **transform**
* **rasterize** | PyTorch版本 | fastpt版本 |DRTK版本 | DTK版本 | Python版本 | 推荐编译方式 |
* **render** | ----------- | ----------- | ----------- | ------------------------ | -----------------| ------------ |
* **interpolate** | 2.5.1 | 2.1.0 |main-3c14f46 | >= 25.04 | 3.8、3.10、3.11 | fastpt不转码 |
* **edge_grad** | 2.4.1 | 2.0.1 |main-3c14f46 | >= 25.04 | 3.8、3.10、3.11 | fastpt不转码 |
| 其他 | 其他 | 其他 | 其他 | 3.8、3.10、3.11 | hip转码 |
There are also optional components such as **msi** and **mipmap_grid_sampler**. New components may be added in the future.
+ pytorch版本大于2.4.1 && dtk版本大于25.04 推荐使用fastpt不转码编译。
A typical flow looks like this:
### 1、使用pip方式安装
**transform****rasterize****render****interpolate****CUSTOM SHADING****edge_grad** drtk whl包下载目录:[光和开发者社区](https://download.sourcefind.cn:65024/4/main),选择对应的pytorch版本和python版本下载对应drtk的whl包
```shell
where: pip install torch* (下载torch的whl包)
- **transform**: projects the vertex positions from camera space to image space pip install fastpt* --no-deps (下载fastpt的whl包)
- **rasterize**: performs rasterization, where pixels in the output image are associated with triangles source /usr/local/bin/fastpt -E
- **render**: computes depth and baricentric image pip install drtk* (下载的drtk的whl包)
- **interpolate**: interpolates arbitrary vertex attributes ```
- **CUSTOM SHADING**: user implemented shading ### 2、使用源码编译方式安装
- **edge_grad**: special module that computes gradients for the **rasterize** step, which is not differentiable on its own. For details, please see [**Rasterized Edge Gradients: Handling Discontinuities Differentiably**](https://arxiv.org/abs/2405.02508)
## Hello Triangle
The "Hello Triangle" with DRTK would look like this:
```python
import drtk
import torch as th
from torchvision.utils import save_image # to save images
# create vertex buffer of shape [1 x n_vertices x 3], here for triangle `n_vertices` == 3
v = th.as_tensor([[[0, 511, 1], [255, 0, 1], [511, 511, 1]]]).float().cuda()
# create index buffer
vi = th.as_tensor([[0, 1, 2]]).int().cuda()
# rasterize
index_img = drtk.rasterize(v, vi, height=512, width=512)
# compute baricentrics #### 编译环境准备
_, bary = drtk.render(v, vi, index_img) 提供基于fastpt不转码编译:
# we won't do shading, we'll just save the baricentrics and filter out the empty region 1. 基于光源pytorch基础镜像环境:镜像下载地址:[光合开发者社区](https://sourcefind.cn/#/image/dcu/pytorch),根据pytorch、python、dtk及系统下载对应的镜像版本。
# which is marked with `-1` in `index_img`
img = bary * (index_img != -1)
save_image(img, "render.png") 2. 基于现有python环境:安装pytorch,fastpt whl包下载目录:[光合开发者社区](https://sourcefind.cn/#/image/dcu/pytorch),根据python、dtk版本,下载对应pytorch的whl包。安装命令如下:
```shell
pip install torch* (下载torch的whl包)
pip install fastpt* --no-deps (下载fastpt的whl包, 安装顺序,先安装torch,后安装fastpt)
pip install pytest
pip install wheel
``` ```
![hello triangle](docs/source/_static/hellow_triangle.png) #### 源码编译安装
- 代码下载
## Dependencies ```shell
* PyTorch >= 2.1.0 git clone http://developer.sourcefind.cn/codes/OpenDAS/drtk.git # 根据编译需要切换分支
```
- 提供2种源码编译方式(进入drtk目录):
```
1. 设置不转码编译环境变量
source /usr/local/bin/fastpt -C
## Installing 2. 编译whl包并安装
python3 setup.py build_ext bdist_wheel
pip install dist/drtk* --no-deps
To build a wheel and install it: 3. 源码编译安装
``` python3 setup.py build_ext install --no-deps
pip install git+https://github.com/facebookresearch/DRTK.git
``` ```
#### 注意事项
+ 若使用pip install下载安装过慢,可添加pypi清华源:-i https://pypi.tuna.tsinghua.edu.cn/simple/
+ ROCM_PATH为dtk的路径,默认为/opt/dtk
+ 在pytorch2.5.1环境下编译需要支持c++17语法,打开setup.py文件,把文件中的 -std=c++14 修改为 -std=c++17
To build inplace, which is useful for package development: ## 验证
``` ```
python setup.py build_ext --inplace -j 1 python3
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import drtk
>>> drtk.__version__
'0.1.0'
>>>
``` ```
版本号与官方版本同步,查询该软件的版本号,例如0.3;
## Contributing ## Known Issue
-
See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.
## License ## 参考资料
DRTK is MIT licensed, as found in the [LICENSE](LICENSE) file. - [README_ORIGIN](README_ORIGIN.md)
- [https://github.com/facebookresearch/DRTK.git](https://github.com/facebookresearch/DRTK.git)
## Citation
```bibtex
@mish{pidhorskyi2024rasterized,
title = {Rasterized Edge Gradients: Handling Discontinuities Differentiably},
author = {Pidhorskyi, Stanislav and Simon, Tomas and Schwartz, Gabriel and Wen, He and Sheikh, Yaser and Saragih, Jason},
howpublished = {arXiv preprint},
year = {2024},
note = {arXiv:2405.02508}
}
```
# DRTK – Differentiable Rendering Toolkit
This package is a PyTorch library that provides functionality for differentiable rasterization.
It consists of five main components:
* **transform**
* **rasterize**
* **render**
* **interpolate**
* **edge_grad**
There are also optional components such as **msi** and **mipmap_grid_sampler**. New components may be added in the future.
A typical flow looks like this:
**transform****rasterize****render****interpolate****CUSTOM SHADING****edge_grad**
where:
- **transform**: projects the vertex positions from camera space to image space
- **rasterize**: performs rasterization, where pixels in the output image are associated with triangles
- **render**: computes depth and baricentric image
- **interpolate**: interpolates arbitrary vertex attributes
- **CUSTOM SHADING**: user implemented shading
- **edge_grad**: special module that computes gradients for the **rasterize** step, which is not differentiable on its own. For details, please see [**Rasterized Edge Gradients: Handling Discontinuities Differentiably**](https://arxiv.org/abs/2405.02508)
## Hello Triangle
The "Hello Triangle" with DRTK would look like this:
```python
import drtk
import torch as th
from torchvision.utils import save_image # to save images
# create vertex buffer of shape [1 x n_vertices x 3], here for triangle `n_vertices` == 3
v = th.as_tensor([[[0, 511, 1], [255, 0, 1], [511, 511, 1]]]).float().cuda()
# create index buffer
vi = th.as_tensor([[0, 1, 2]]).int().cuda()
# rasterize
index_img = drtk.rasterize(v, vi, height=512, width=512)
# compute baricentrics
_, bary = drtk.render(v, vi, index_img)
# we won't do shading, we'll just save the baricentrics and filter out the empty region
# which is marked with `-1` in `index_img`
img = bary * (index_img != -1)
save_image(img, "render.png")
```
![hello triangle](docs/source/_static/hellow_triangle.png)
## Dependencies
* PyTorch >= 2.1.0
## Installing
To build a wheel and install it:
```
pip install git+https://github.com/facebookresearch/DRTK.git
```
To build inplace, which is useful for package development:
```
python setup.py build_ext --inplace -j 1
```
## Contributing
See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.
## License
DRTK is MIT licensed, as found in the [LICENSE](LICENSE) file.
## Citation
```bibtex
@mish{pidhorskyi2024rasterized,
title = {Rasterized Edge Gradients: Handling Discontinuities Differentiably},
author = {Pidhorskyi, Stanislav and Simon, Tomas and Schwartz, Gabriel and Wen, He and Sheikh, Yaser and Saragih, Jason},
howpublished = {arXiv preprint},
year = {2024},
note = {arXiv:2405.02508}
}
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment