NeRF从入门到放弃2:InstantNGP

2024-06-22 14:12
文章标签 入门 放弃 nerf instantngp

本文主要是介绍NeRF从入门到放弃2:InstantNGP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原始的NeRF每条光线上的点都要经过MLP的查询,才能得到其密度和颜色值,要查询的点非常多,而MLP的推理是比较耗时的。

InstantNGP将空间划分成多个层级的体素(voxels),并且在每个体素内部使用神经网络来预测feature。

而Plenoxels则干脆就不使用神经网络了,它直接在体素中存储场景的辐射亮度和密度信息。通过使用球谐函数(Spherical Harmonics)来近似每个体素内的光照分布,Plenoxels能够有效地压缩存储需求,同时保持高质量的渲染效果。这种方法避免了复杂的神经网络计算,显著提升了渲染速度。Tesla用的就是这种方法。

Direct Voxel Grid也是类似的想法。

现在比较常调用的是InstantNGP,所以我们重点看这个方法。

算法解读

在这里插入图片描述

Given a fully connected neural network 𝑚(y; Φ), we are interested in an encoding of its inputs y = enc(x; 𝜃 ) that improves the approximation quality and training speed across a wide range of applications without incurring a notable performance overhead

InstantNGP把空间划分成多个分辨率,具体查询某个点的feature时,利用hash表查询到这个点附近的四个角点,这四个角点的feature是已知的,通过三线性插值的方法,得到该点在该分辨率下的feature。

最终的feature是多个分辨率下的feature concate起来,作为最终的feature。

也就是说,原始的NeRF是输入(x,y,z),经过mlp,输出feature;而InstantNGP是输入(x,y,z),查询其4个邻域的feature(事先编码好的,所以很快),插值得到feature。

参数意义

在这里插入图片描述
在这里插入图片描述

5个参数,根据最小、最大分辨率和层数,计算出每一层的放大系数,也就是等比数列的公比(也就是b)。算出公比后每一层的分辨率就是Nmin * b的l次方,l是层的序号。

F是要编码成的向量的维度。

T表示hash表的最大容量,如果超过了这个最大容量,就会出现hash冲突。

如第一张图中编码的feature是2维,有2个层级(L),那最后的特征向量就是这两个层级的特征向量concate起来,是4维度。

代码实例

# nerfstudio/field_components/encodings.py
class HashEncoding(Encoding):"""Hash encodingArgs:num_levels: Number of feature grids.min_res: Resolution of smallest feature grid.max_res: Resolution of largest feature grid.log2_hashmap_size: Size of hash map is 2^log2_hashmap_size.features_per_level: Number of features per level.hash_init_scale: Value to initialize hash grid.implementation: Implementation of hash encoding. Fallback to torch if tcnn not available.interpolation: Interpolation override for tcnn hashgrid. Not supported for torch unless linear.n_input_dims: Number of input dimensions (typically 3 for x,y,z)"""def __init__(self,num_levels: int = 16,min_res: int = 16,max_res: int = 1024,log2_hashmap_size: int = 19,features_per_level: int = 2,hash_init_scale: float = 0.001,implementation: Literal["tcnn", "torch"] = "tcnn",interpolation: Optional[Literal["Nearest", "Linear", "Smoothstep"]] = None,n_input_dims: int = 3,) -> None:super().__init__(in_dim=3)self.num_levels = num_levelsself.min_res = min_resself.features_per_level = features_per_levelself.hash_init_scale = hash_init_scaleself.log2_hashmap_size = log2_hashmap_sizeself.hash_table_size = 2**log2_hashmap_sizeself.min_res = min_resself.hash_init_scale = hash_init_scalelevels = torch.arange(num_levels)self.growth_factor = np.exp((np.log(max_res) - np.log(min_res)) / (num_levels - 1)) if num_levels > 1 else 1.0self.register_buffer("scalings", torch.floor(min_res * self.growth_factor**levels))self.hash_offset = levels * self.hash_table_sizeself.tcnn_encoding = Noneself.hash_table = torch.empty(0)if implementation == "torch":self.build_nn_modules()elif implementation == "tcnn" and not TCNN_EXISTS:print_tcnn_speed_warning("HashEncoding")self.build_nn_modules()elif implementation == "tcnn":encoding_config = self.get_tcnn_encoding_config(num_levels=self.num_levels,features_per_level=self.features_per_level,log2_hashmap_size=self.log2_hashmap_size,min_res=self.min_res,growth_factor=self.growth_factor,interpolation=interpolation,)self.tcnn_encoding = tcnn.Encoding(n_input_dims=n_input_dims,encoding_config=encoding_config,)if self.tcnn_encoding is None:assert (interpolation is None or interpolation == "Linear"), f"interpolation '{interpolation}' is not supported for torch encoding backend"def build_nn_modules(self) -> None:"""Initialize the torch version of the hash encoding."""self.hash_table = torch.rand(size=(self.hash_table_size * self.num_levels, self.features_per_level)) * 2 - 1self.hash_table *= self.hash_init_scaleself.hash_table = nn.Parameter(self.hash_table)

这篇关于NeRF从入门到放弃2:InstantNGP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1084511

相关文章

Python中OpenCV与Matplotlib的图像操作入门指南

《Python中OpenCV与Matplotlib的图像操作入门指南》:本文主要介绍Python中OpenCV与Matplotlib的图像操作指南,本文通过实例代码给大家介绍的非常详细,对大家的学... 目录一、环境准备二、图像的基本操作1. 图像读取、显示与保存 使用OpenCV操作2. 像素级操作3.

POI从入门到实战轻松完成EasyExcel使用及Excel导入导出功能

《POI从入门到实战轻松完成EasyExcel使用及Excel导入导出功能》ApachePOI是一个流行的Java库,用于处理MicrosoftOffice格式文件,提供丰富API来创建、读取和修改O... 目录前言:Apache POIEasyPoiEasyExcel一、EasyExcel1.1、核心特性

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

数论入门整理(updating)

一、gcd lcm 基础中的基础,一般用来处理计算第一步什么的,分数化简之类。 LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } <pre name="code" class="cpp">LL lcm(LL a, LL b){LL c = gcd(a, b);return a / c * b;} 例题:

Java 创建图形用户界面(GUI)入门指南(Swing库 JFrame 类)概述

概述 基本概念 Java Swing 的架构 Java Swing 是一个为 Java 设计的 GUI 工具包,是 JAVA 基础类的一部分,基于 Java AWT 构建,提供了一系列轻量级、可定制的图形用户界面(GUI)组件。 与 AWT 相比,Swing 提供了许多比 AWT 更好的屏幕显示元素,更加灵活和可定制,具有更好的跨平台性能。 组件和容器 Java Swing 提供了许多

【IPV6从入门到起飞】5-1 IPV6+Home Assistant(搭建基本环境)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant #搭建基本环境 1 背景2 docker下载 hass3 创建容器4 浏览器访问 hass5 手机APP远程访问hass6 更多玩法 1 背景 既然电脑可以IPV6入站,手机流量可以访问IPV6网络的服务,为什么不在电脑搭建Home Assistant(hass),来控制你的设备呢?@智能家居 @万物互联

poj 2104 and hdu 2665 划分树模板入门题

题意: 给一个数组n(1e5)个数,给一个范围(fr, to, k),求这个范围中第k大的数。 解析: 划分树入门。 bing神的模板。 坑爹的地方是把-l 看成了-1........ 一直re。 代码: poj 2104: #include <iostream>#include <cstdio>#include <cstdlib>#include <al