Instruct-NeRF2NeRF:通过用户指令编辑 NeRF 三维场景

2023-12-21 12:52

本文主要是介绍Instruct-NeRF2NeRF:通过用户指令编辑 NeRF 三维场景,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Haque A, Tancik M, Efros A A, et al. Instruct-nerf2nerf: Editing 3d scenes with instructions[J]. arXiv preprint arXiv:2303.12789, 2023.

Instruct-NeRF2NeRF 是 ICCV 2023 Oral 论文,首次将图像编辑任务从二维提升到三维。

Instruct-NeRF2NeRF 所做的任务是根据用户指令编辑 NeRF 表示的三维场景。Instruct-NeRF2NeRF 使用预训练的 InstructPix2Pix 对 NeRF 的训练数据(即多视角视图)进行编辑,然后用编辑后的视图继续训练 NeRF,从而达到编辑三维场景的效果。为了确保编辑后的三维场景的连续性,使用 Iterative DU 的方式进行训练。

在这里插入图片描述

目录

  • 一. 研究思路
  • 二. Instruct-NeRF2NeRF 模型
  • 三. 训练方法
    • 1. 编辑 NeRF 训练图像
    • 2. 更新 NeRF 训练集
  • 四. 实验结果
  • 五. 总结
  • 六. 复现

一. 研究思路

Instruct-NeRF2NeRF 的目的是按照人为指令对 NeRF 表示的三维场景进行编辑,因此训练模型只需要编辑指令和 NeRF 场景。正如 DreamFusion 中所说,三维场景的本质就是从多个视角观测一个场景 1,因此 Instruct-NeRF2NeRF 使用 InstructPix2Pix 对 NeRF 的多视角训练数据进行编辑,编辑后的图像就可以用来优化 NeRF 的三维表示。为了方便编辑,给定场景的 NeRF 表示时还保留了其训练数据(视图、机位等信息)。

二. Instruct-NeRF2NeRF 模型

Instruct-NeRF2NeRF 在 NeRF 表示的三维场景上使用 InstructPix2Pix 进行微调:

  • 输入:NeRF 场景及其训练数据和编辑指令;
  • 输出:编辑后的 NeRF 场景;

三. 训练方法

直接对不同视角的训练数据进行编辑会导致三维场景的不连续 (inconsistent edits across viewpoints),因为不同视角的图像编辑之间相互独立:
在这里插入图片描述

于是, Instruct-NeRF2NeRF 的训练使用 迭代数据集更新 (Iterative Dataset Update, Iterative DU) 的方式,即交替编辑 NeRF 训练集图像和更新 NeRF 三维场景。

这也就是为什么不对所有训练图像编辑后从头训练 NeRF 的原因:NeRF 的训练数据可以保证三维场景的连续型,而 InstructPix2Pix 编辑后的多视角图像之间构成的三维场景很有可能不连续。

在这里插入图片描述

1. 编辑 NeRF 训练图像

编辑 NeRF 训练集图像时,将视角 v v v 下的原始图像 c I c_I cI、编辑指令 c T c_T cT、噪声 z t z_t zt 输入 InstructPix2Pix 模型。记 I i v I_{i}^{v} Iiv 表示第 i i i 轮视角 v v v 下的图像, I 0 v = c I I_{0}^{v}=c_I I0v=cI,则有随着迭代不断更新图像:
I i + 1 v ← U θ ( I i v , t ; I 0 v , c T ) I_{i+1}^{v} \leftarrow U_{\theta}(I_{i}^{v},t;I_{0}^{v},c_T) Ii+1vUθ(Iiv,t;I0v,cT)

2. 更新 NeRF 训练集

Instruct-NeRF2NeRF 的核心就是交替编辑 NeRF 训练集图像和更新 NeRF 三维场景,称为 Iterative DU。训练前对 NeRF 训练集的多视角视图指定顺序,在每一轮训练中,先更新 d d d 张图像,再采样 n n n 条射线训练 NeRF:

  1. 图像更新时,随机选取部分视图进行编辑,然后将其替换成编辑后的视图;
  2. NeRF 训练时,从新旧数据混合的训练集中采样部分视图对 NeRF 进行训练;

在这里插入图片描述

上述训练方法在训练初期可能也会出现不连续的三维场景,但随着不断迭代,会收敛到一个连续的三维场景:
在这里插入图片描述

四. 实验结果

使用 Nerfstudio 框架 2 表示三维场景,每次编辑都需要在三维场景上重新训练。训练过程可视化如下:

在这里插入图片描述

不同方法效果对比如下:
在这里插入图片描述

五. 总结

Instruct-NeRF2NeRF 通过使用预训练的 InstructPix2Pix 对 NeRF 的训练数据进行编辑,然后以 Iterative DU 的方式使用编辑后的视图继续训练 NeRF,从而实现了三维场景的编辑,保持了场景的连贯性和真实感。3

其实 Instruct-NeRF2NeRF 在处理三维场景一致性时使用了 tricks:既然已经保留了 NeRF 的所有训练数据,为什么不对所有数据编辑后再训练 NeRF?因为 NeRF 的原始训练数据可以保证三维场景的连续型,而 InstructPix2Pix 编辑后的多视角图像之间构成的三维场景很有可能不连续。因此采用迭代更新数据集的方式来训练,使得 NeRF 逐渐收敛到一个连续三维场景。

但 Instruct-NeRF2NeRF 也有一些局限性:

  • Instruct-NeRF2NeRF 一次只能在一个视图上进行编辑,因此可能出现伪影;
  • 有时 InstructPix2Pix 编辑不理想,因此 Instruct-NeRF2NeRF 的编辑也会因此出问题;
  • 即使 InstructPix2Pix 编辑成功,Instruct-NeRF2NeRF 的编辑也可能不理想;
    在这里插入图片描述

六. 复现

Instruct-NeRF2NeRF 基于 Nerfstudio:

  • 平台:AutoDL
  • 显卡:RTX 4090 24GB
  • 镜像:PyTorch 2.0.0、Python 3.8(ubuntu20.04)、Cuda 11.8
  • 源码:https://github.com/ayaanzhaque/instruct-nerf2nerf

实验记录

  1. 先按照 教程 创建 nerfstudio 环境并安装依赖包,执行到 conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit 即可;
  2. 再克隆 Instruct-NeRF2NeRF 仓库并更新组件和包;
  3. 此时执行 ns-train -h 查看安装情况会出现 TypeEror
    在这里插入图片描述
    需要先在 instruct-nerf2nerf 文件夹下安装 Nerfstudio 4 ,然后就可以成功验证:
    在这里插入图片描述
(nerfstudio) root@autodl-container-9050458ceb-3f1684be:~/instruct-nerf2nerf/nerfstudio# ns-train -h
usage: ns-train [-h]{depth-nerfacto,dnerf,gaussian-splatting,generfacto,in2n,in2n-small,in2n-tiny,instant-ngp,instant-ngp-bounded,mipnerf,nerfacto,nerfact
o-big,nerfacto-huge,neus,neus-facto,phototourism,semantic-nerfw,tensorf,vanilla-nerf,kplanes,kplanes-dynamic,lerf,lerf-big,lerf-lite,nerfplayer-nerfac
to,nerfplayer-ngp,tetra-nerf,tetra-nerf-original,volinga}Train a radiance field with nerfstudio. For real captures, we recommend using the nerfacto model.Nerfstudio allows for customizing your training and eval configs from the CLI in a powerful way, but there are some things to understand.The most demonstrative and helpful example of the CLI structure is the difference in output between the following commands:ns-train -hns-train nerfacto -h nerfstudio-datans-train nerfacto nerfstudio-data -hIn each of these examples, the -h applies to the previous subcommand (ns-train, nerfacto, and nerfstudio-data).In the first example, we get the help menu for the ns-train script. In the second example, we get the help menu for the nerfacto model. In the third 
example, we get the help menu for the nerfstudio-data dataparser.With our scripts, your arguments will apply to the preceding subcommand in your command, and thus where you put your arguments matters! Any optional 
arguments you discover from runningns-train nerfacto -h nerfstudio-dataneed to come directly after the nerfacto subcommand, since these optional arguments only belong to the nerfacto subcommand:ns-train nerfacto {nerfacto optional args} nerfstudio-data╭─ arguments ─────────────────────────────────────────────────────────────╮ ╭─ subcommands ──────────────────────────────────────────────────────────╮
│ -h, --help        show this help message and exit                       │ │ {depth-nerfacto,dnerf,gaussian-splatting,generfacto,in2n,in2n-small,i… │
╰─────────────────────────────────────────────────────────────────────────╯ │     depth-nerfacto                                                     ││                   Nerfacto with depth supervision.                     ││     dnerf         Dynamic-NeRF model. (slow)                           ││     gaussian-splatting                                                 ││                   Gaussian Splatting model                             ││     generfacto    Generative Text to NeRF model                        ││     in2n          Instruct-NeRF2NeRF primary method: uses LPIPS, IP2P  ││                   at full precision                                    ││     in2n-small    Instruct-NeRF2NeRF small method, uses LPIPs, IP2P at ││                   half precision                                       ││     in2n-tiny     Instruct-NeRF2NeRF tiny method, does not use LPIPs,  ││                   IP2P at half precision                               ││     instant-ngp   Implementation of Instant-NGP. Recommended real-time ││                   model for unbounded scenes.                          ││     instant-ngp-bounded                                                ││                   Implementation of Instant-NGP. Recommended for       ││                   bounded real and synthetic scenes                    ││     mipnerf       High quality model for bounded scenes. (slow)        ││     nerfacto      Recommended real-time model tuned for real captures. ││                   This model will be continually updated.              ││     nerfacto-big                                                       ││     nerfacto-huge                                                      ││     neus          Implementation of NeuS. (slow)                       ││     neus-facto    Implementation of NeuS-Facto. (slow)                 ││     phototourism  Uses the Phototourism data.                          ││     semantic-nerfw                                                     ││                   Predicts semantic segmentations and filters out      ││                   transient objects.                                   ││     tensorf       tensorf                                              ││     vanilla-nerf  Original NeRF model. (slow)                          ││     kplanes       [External] K-Planes model tuned to static blender    ││                   scenes                                               ││     kplanes-dynamic                                                    ││                   [External] K-Planes model tuned to dynamic DNeRF     ││                   scenes                                               ││     lerf          [External] LERF with OpenCLIP ViT-B/16, used in      ││                   paper                                                ││     lerf-big      [External] LERF with OpenCLIP ViT-L/14               ││     lerf-lite     [External] LERF with smaller network and less LERF   ││                   samples                                              ││     nerfplayer-nerfacto                                                ││                   [External] NeRFPlayer with nerfacto backbone         ││     nerfplayer-ngp                                                     ││                   [External] NeRFPlayer with instang-ngp-bounded       ││                   backbone                                             ││     tetra-nerf    [External] Tetra-NeRF. Different sampler - faster    ││                   and better                                           ││     tetra-nerf-original                                                ││                   [External] Tetra-NeRF. Official implementation from  ││                   the paper                                            ││     volinga       [External] Real-time rendering model from Volinga.   ││                   Directly exportable to NVOL format at                ││                   https://volinga.ai/                                  │╰────────────────────────────────────────────────────────────────────────╯
  1. Nerfstudio 安装完成后,就可以训练了。使用 bear 数据集进行训练:ns-train nerfacto --data data/bear
    在这里插入图片描述
    训练时可以复制网址 https://viewer.nerf.studio/versions/23-05-15-1/?websocket_url=ws://localhost:7007 监控实时效果 5。需要注意的是,在服务器上训练想要监视训练过程需要转发 6 7,监视窗口如下:
    在这里插入图片描述
  2. NeRF 场景训练完成后,就可以进行编辑:ns-train in2n --data data/bear --load-dir outputs/bear/nerfacto/2023-12-17_230904/nerfstudio_models --pipeline.prompt "Turn the bear into a polar bear" --pipeline.guidance-scale 7.5 --pipeline.image-guidance-scale 1.5。但 GPU 内存有限,加载全部模型会超限 8 9 10
    在这里插入图片描述
    作者也考虑到了这一点,因此提供了占用内存更小但效果更差的模型 in2n-smallin2n-tinyns-train in2n-small --data data/bear --load-dir outputs/bear/nerfacto/2023-12-17_230904/nerfstudio_models --pipeline.prompt "Turn the bear into a polar bear" --pipeline.guidance-scale 7.5 --pipeline.image-guidance-scale 1.5

实验结果

  1. 原始 NeRF 场景训练结果如下,3w 轮迭代大概需要 1h:
    在这里插入图片描述

  2. 为了呈现可视化效果,在训练完成后可以使用 ns-viewer --load-config outputs/bear/nerfacto/2023-12-17_230904/config.yml 加载监视页面 11;在监视页面 LOAD PATH 选择 final-path 即可,点击 RENDER 即可复制指令:ns-render camera-path --load-config outputs/bear/nerfacto/2023-12-17_230904/config.yml --camera-path-filename data/bear/camera_paths/2023-12-17_230904.json --output-path renders/bear/2023-12-17_230904.mp4。原始场景是用完整 NeRF 训练的,参数量太大超过显存容量,无法渲染成视频,截一张图以供参考:
    在这里插入图片描述

  3. 使用 in2n-small 模型编辑三维场景,迭代到 4k 次已经完全收敛,不必再继续训练(完整编辑会执行到 6w 步,没有必要),大概需要 2h:
    在这里插入图片描述

  4. 继续使用 ns-viewer 指令可视化三维场景,并使用 ns-render 指令可以渲染成视频。由于显存容量问题,无法渲染成视频,截一张图以供参考:
    在这里插入图片描述


  1. MAV3D:从文本描述中生成三维动态场景 ↩︎

  2. Tancik M, Weber E, Ng E, et al. Nerfstudio: A modular framework for neural radiance field development[C]//ACM SIGGRAPH 2023 Conference Proceedings. 2023: 1-12. ↩︎

  3. 一行字实现3D换脸!UC伯克利提出「Chat-NeRF」,说句话完成大片级渲染 ↩︎

  4. Fresh install error #72 ↩︎

  5. nerfstudio-project | nerfstudio # 2-training-your-first-model ↩︎

  6. nerfstudio | Using the viewer # training-on-a-remote-machine ↩︎

  7. AutoDL帮助文档 | VSCode远程开发 ↩︎

  8. RuntimeError: CUDA out of memory. Tried to allocate 12.50 MiB (GPU 0; 10.92 GiB total capacity; 8.57 MiB already allocated; 9.28 GiB free; 4.68 MiB cached) #16417 ↩︎

  9. How to avoid “CUDA out of memory” in PyTorch ↩︎

  10. How to avoid “CUDA out of memory” in PyTorch ↩︎

  11. nerfstudio-project | nerfstudio # Visualize existing run ↩︎

这篇关于Instruct-NeRF2NeRF:通过用户指令编辑 NeRF 三维场景的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Oracle数据库如何切换登录用户(system和sys)

《Oracle数据库如何切换登录用户(system和sys)》文章介绍了如何使用SQL*Plus工具登录Oracle数据库的system用户,包括打开登录入口、输入用户名和口令、以及切换到sys用户的... 目录打开登录入口登录system用户总结打开登录入口win+R打开运行对话框,输php入:sqlp

JavaScript中的isTrusted属性及其应用场景详解

《JavaScript中的isTrusted属性及其应用场景详解》在现代Web开发中,JavaScript是构建交互式应用的核心语言,随着前端技术的不断发展,开发者需要处理越来越多的复杂场景,例如事件... 目录引言一、问题背景二、isTrusted 属性的来源与作用1. isTrusted 的定义2. 为

Python调用另一个py文件并传递参数常见的方法及其应用场景

《Python调用另一个py文件并传递参数常见的方法及其应用场景》:本文主要介绍在Python中调用另一个py文件并传递参数的几种常见方法,包括使用import语句、exec函数、subproce... 目录前言1. 使用import语句1.1 基本用法1.2 导入特定函数1.3 处理文件路径2. 使用ex

Linux alias的三种使用场景方式

《Linuxalias的三种使用场景方式》文章介绍了Linux中`alias`命令的三种使用场景:临时别名、用户级别别名和系统级别别名,临时别名仅在当前终端有效,用户级别别名在当前用户下所有终端有效... 目录linux alias三种使用场景一次性适用于当前用户全局生效,所有用户都可调用删除总结Linux

数据库oracle用户密码过期查询及解决方案

《数据库oracle用户密码过期查询及解决方案》:本文主要介绍如何处理ORACLE数据库用户密码过期和修改密码期限的问题,包括创建用户、赋予权限、修改密码、解锁用户和设置密码期限,文中通过代码介绍... 目录前言一、创建用户、赋予权限、修改密码、解锁用户和设置期限二、查询用户密码期限和过期后的修改1.查询用

Mysql虚拟列的使用场景

《Mysql虚拟列的使用场景》MySQL虚拟列是一种在查询时动态生成的特殊列,它不占用存储空间,可以提高查询效率和数据处理便利性,本文给大家介绍Mysql虚拟列的相关知识,感兴趣的朋友一起看看吧... 目录1. 介绍mysql虚拟列1.1 定义和作用1.2 虚拟列与普通列的区别2. MySQL虚拟列的类型2

在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码

《在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码》在MyBatis的XML映射文件中,trim元素用于动态添加SQL语句的一部分,处理前缀、后缀及多余的逗号或连接符,示... 在MyBATis的XML映射文件中,<trim>元素用于动态地添加SQL语句的一部分,例如SET或W

VUE动态绑定class类的三种常用方式及适用场景详解

《VUE动态绑定class类的三种常用方式及适用场景详解》文章介绍了在实际开发中动态绑定class的三种常见情况及其解决方案,包括根据不同的返回值渲染不同的class样式、给模块添加基础样式以及根据设... 目录前言1.动态选择class样式(对象添加:情景一)2.动态添加一个class样式(字符串添加:情

java中VO PO DTO POJO BO DO对象的应用场景及使用方式

《java中VOPODTOPOJOBODO对象的应用场景及使用方式》文章介绍了Java开发中常用的几种对象类型及其应用场景,包括VO、PO、DTO、POJO、BO和DO等,并通过示例说明了它... 目录Java中VO PO DTO POJO BO DO对象的应用VO (View Object) - 视图对象

Python中异常类型ValueError使用方法与场景

《Python中异常类型ValueError使用方法与场景》:本文主要介绍Python中的ValueError异常类型,它在处理不合适的值时抛出,并提供如何有效使用ValueError的建议,文中... 目录前言什么是 ValueError?什么时候会用到 ValueError?场景 1: 转换数据类型场景