• Stars
    star
    277
  • Rank 148,518 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Segment-anything interactively in NeRF.

Segment-Anything NeRF

πŸŽ‰πŸŽ‰πŸŽ‰ Welcome to the Segment-Anything NeRF GitHub repository! πŸŽ‰πŸŽ‰πŸŽ‰

Segment-Anything NeRF is a novel approach for performing segmentation in a Neural Radiance Fields (NeRF) framework. Our approach renders the semantic feature of a certain view directly, eliminating the need for the forward process of the backbone of the segmentation model. By leveraging the light-weight SAM decoder, we can achieve interactive 3D-consistent segmentation at 5 FPS (rendering 512x512 image) on a V100.

interactive_seg.mp4
open_vocabulary_seg.mp4

News

[2023/4/29] Add a demo of Open-Vocabulary Segmentation in NeRF based on X-Decoder.

Key features

  • Learn 3D consistent SAM backbone features along with RGB and density, so we can bypass the ViT-Huge encoder and use ray marching to produce SAM features efficiently.
  • Online distillation with camera augmentation and caching for robust and fast training (~1 hour per scene for two stages on a V100).

NOTE: This is a work in progress, more demonstration (e.g., open-vocabulary segmentation) and a technical report is on the way!

Install

git clone https://github.com/ashawkey/Segment-Anything-NeRF.git
cd Segment-Anything-NeRF

# download SAM ckpt
mkdir pretrained && cd pretrained
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth

Install with pip

pip install -r requirements.txt

Build extension (optional)

By default, we use load to build the extension at runtime. However, this may be inconvenient sometimes. Therefore, we also provide the setup.py to build each extension:

# install all extension modules
bash scripts/install_ext.sh

# if you want to install manually, here is an example:
cd gridencoder
python setup.py build_ext --inplace # build ext only, do not install (only can be used in the parent directory)
pip install . # install to python path (you still need the gridencoder/ folder, since this only install the built extension.)

Tested environments

  • Ubuntu 22 with torch 1.12 & CUDA 11.6 on a V100.

Usage

We majorly support COLMAP dataset like Mip-NeRF 360. Please download and put them under ./data.

For custom datasets:

# prepare your video or images under /data/custom, and run colmap (assumed installed):
python scripts/colmap2nerf.py --video ./data/custom/video.mp4 --run_colmap # if use video
python scripts/colmap2nerf.py --images ./data/custom/images/ --run_colmap # if use images

First time running will take some time to compile the CUDA extensions.

### train rgb
python main.py data/garden/ --workspace trial_garden --enable_cam_center --downscale 4

### train sam features
# --with_sam: enable sam prediction
# --init_ckpt: specify the latest checkpoint from rgb training
python main.py data/garden/ --workspace trial2_garden --enable_cam_center --downscale 4 --with_sam --init_ckpt trial_garden/checkpoints/ngp.pth --iters 5000

### test sam (interactive GUI, recommended!)
# left drag & middle drag & wheel scroll: move camera
# right click: add/remove point marker
# NOTE: only square images are supported for now!
python main.py data/garden/ --workspace trial2_garden --enable_cam_center --downscale 4 --with_sam --init_ckpt trial_garden/checkpoints/ngp.pth --test --gui

# test sam (without GUI, random points query)
python main.py data/garden/ --workspace trial2_garden --enable_cam_center --downscale 4 --with_sam --init_ckpt trial_garden/checkpoints/ngp.pth --test

Please check the scripts directory for more examples on common datasets, and check main.py for all options.

Acknowledgement

  • Segment-Anything:
    @article{kirillov2023segany,
        title={Segment Anything},
        author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C. and Lo, Wan-Yen and Doll{\'a}r, Piotr and Girshick, Ross},
        journal={arXiv:2304.02643},
        year={2023}
    }
    
  • X-Decoder:
    @article{zou2022generalized,
      title={Generalized Decoding for Pixel, Image, and Language},
      author={Zou, Xueyan and Dou, Zi-Yi and Yang, Jianwei and Gan, Zhe and Li, Linjie and Li, Chunyuan and Dai, Xiyang and Behl, Harkirat and Wang, Jianfeng and Yuan, Lu and others},
      journal={arXiv preprint arXiv:2212.11270},
      year={2022}
    }
    

Citation

If you find this work useful, a citation will be appreciated via:

@misc{segment-anything-nerf,
    Author = {Jiaxiang Tang and Xiaokang Chen and Diwen Wan and Jingbo Wang and Gang Zeng},
    Year = {2023},
    Note = {https://github.com/ashawkey/Segment-Anything-NeRF},
    Title = {Segment-Anything NeRF}
}

More Repositories

1

stable-dreamfusion

Text-to-3D & Image-to-3D & Mesh Exportation with NeRF + Diffusion.
Python
7,270
star
2

torch-ngp

A pytorch CUDA extension implementation of instant-ngp (sdf and nerf), with a GUI.
Python
1,863
star
3

nerf2mesh

[ICCV2023] Delicate Textured Mesh Recovery from NeRF via Adaptive Surface Refinement
Python
743
star
4

RAD-NeRF

Real-time Neural Radiance Talking Portrait Synthesis via Audio-spatial Decomposition
Python
707
star
5

Drag3D

DragGAN meets GET3D for interactive mesh generation and editing.
Python
452
star
6

diff-gaussian-rasterization

Cuda
308
star
7

chatgpt_please_improve_my_paper_writing

a thin wrapper of chatgpt for improving paper writing.
Python
251
star
8

torch-merf

An unofficial pytorch implementation of MeRF
Python
137
star
9

dreamfields-torch

A pytorch implementation of dreamfields with modifications.
Python
134
star
10

fantasia3d.unofficial

An unofficial reproduction of Fantasia3D
Python
127
star
11

CCNeRF

[NeurIPS 2022] Compressible-composable NeRF via Rank-residual Decomposition.
Python
125
star
12

nerf_template

a simple template for practicing NeRF.
Python
125
star
13

cubvh

CUDA Mesh BVH tools.
Cuda
121
star
14

jiif

[ACM MM 2021] Joint Implicit Image Function for Guided Depth Super-Resolution
Python
90
star
15

raytracing

A CUDA Mesh RayTracer with BVH acceleration, with python bindings and a GUI.
Cuda
83
star
16

volumentations

3D volume data augmentation package inspired by albumentations
Python
78
star
17

kiuikit

A maintained, reusable and trustworthy toolkit for computer vision tasks.
Python
42
star
18

envlight

Environment light tools.
Python
38
star
19

FocalLoss.pytorch

Implementation of focal loss in pytorch for unbalanced classification.
Python
35
star
20

dimr

[ECCV 2022] Disentangled Instance Mesh Reconstruction
Python
27
star
21

NotVeryFastNeRF

an unofficial and partial implementation of FastNeRF
Jupyter Notebook
25
star
22

note

notebook archive
PowerShell
19
star
23

3d_human_poser

a naive 3d human pose editor GUI.
Python
16
star
24

vscode-mesh-viewer

A 3D mesh viewer for vscode
JavaScript
16
star
25

CCA

CCA, DCCA, DCCAE, ConvCCA
Python
14
star
26

grid_put

An operation trying to do the opposite of F.grid_sample
Python
13
star
27

index_grid_sample

Extension to `F.grid_sample` that allows using batch index per grid point.
Cuda
12
star
28

made-in-heaven-timer

create timer videos at any speed.
Python
11
star
29

q10r

A simple web questionnaire application.
Python
6
star
30

ddddsr

A python library for end-to-end image super resolution.
Python
5
star
31

lightnet

light weight convolutional neural network implementation in one c++ file.
C++
5
star
32

bsp_cvae

Python
4
star
33

learn_matmul

Cuda
3
star
34

trojan-privoxy-client

for unraid proxy.
Dockerfile
2
star
35

numpytorch

Monkey-patched numpy with pytorch syntax
Python
2
star
36

point_seg_dist

a CUDA implementation of points to lines/segments distance
C
2
star
37

pytorch_ddp_examples

Python
1
star
38

uuunet

Python
1
star
39

fbxloader

FBX file loader for python (only supports geometry currently)
Python
1
star
40

unraid_tutorial

2021εΉ΄ηš„unraid搭建教程
1
star
41

CapsNet.pytorch

reimplementation of capsule network for MNIST classification.
Python
1
star
42

Uncertainty

program to calculate uncertainty for Physics experiment.
Python
1
star
43

nonsense

NoNSeNSe frontend.
JavaScript
1
star
44

JLGCN

Joing learning of graphs and features
Python
1
star
45

live-speech-recognition

A simple sliding window based real-time speech recognition example.
Python
1
star
46

dullPLYviewer

HTML
1
star
47

MaxClique

Heuristic algorithms to solve the max clique problem.
C++
1
star
48

hawtorch

pytorch extensions for code reuse
Python
1
star