GithubHelp home page GithubHelp logo

threedle / 3d-paintbrush Goto Github PK

View Code? Open in Web Editor NEW
51.0 9.0 5.0 38.29 MB

Local text-driven editing of 3D shapes with Cascaded Score Distillation

Home Page: https://threedle.github.io/3d-paintbrush/

License: MIT License

Shell 0.01% Python 1.90% Jupyter Notebook 98.09%
computer-graphics computer-vision deep-learning differentiable-rendering diffusion-models generative-ai machine-learning meshes neural-fields python

3d-paintbrush's Introduction

๐ŸŽจ๐Ÿ–Œ๏ธ 3D Paintbrush [CVPR 2024]

Dale Decatur, Itai Lang, Kfir Aberman, Rana Hanocka

Abstract

In this work we develop 3D Paintbrush, a technique for automatically texturing local semantic regions on meshes via text descriptions. Our method is designed to operate directly on meshes, producing texture maps which seamlessly integrate into standard graphics pipelines. We opt to simultaneously produce a localization map (to specify the edit region) and a texture map which conforms to it. This synergistic approach improves the quality of both the localization and the stylization. To enhance the details and resolution of the textured area, we leverage multiple stages of a cascaded diffusion model to supervise our local editing technique with generative priors learned from images at different resolutions. Our technique, referred to as Cascaded Score Distillation (CSD), simultaneously distills scores at multiple resolutions in a cascaded fashion, enabling control over both the granularity and global understanding of the supervision. We demonstrate the effectiveness of 3D Paintbrush to locally texture a variety of shapes within different semantic regions.

CSD Demo Notebook

To see a demo of the Cascaded Score Distillation (CSD) loss, check out this notebook applying CSD to image generation and image editing. CSD enables us to supervise our optimization with multiple cascaded stages of the diffusion model instead of just the base stage used in standard SDS. We distill scores across multiple stages of a cascaded diffusion model simultaneously in order to leverage both the global awareness of the first stage and the higher level of detail contained in later stages.

Getting Started

Requirements

  • 48 GB GPU
  • CUDA 11.3
  • Python 3.10

If you have less than 48 GB of GPU memory, you can still run the code, see the section on memory optimization for more details.

Setup environemnt

First create the conda environment:

conda create -n "3d-paintbrush" python=3.10

and activate it with:

conda activate 3d-paintbrush

Next install the required packages by running the install script. Make sure to run this script with access to a GPU.

bash ./install_environment.sh

Login to Hugging Face (to use DeepFloyd IF w/ Diffusers)

Instructions from DeepFloyd IF:

  1. If you do not already have one, create a Hugging Face account
  2. Accept the license on the model card of DeepFloyd/IF-I-XL-v1.0
  3. Log in to Hugging face locally. First install huggingface_hub
pip install huggingface_hub --upgrade

run the login function in a python shell

from huggingface_hub import login

login()

and enter your Hugging Face Hub access token.

Reproduce paper results

(Optional) From Pre-trained

To use our pre-trained models download both the trained_models and inverse_map_cache folders from here and add them under the data folder to create the following directory structure:

โ”œโ”€โ”€ data
โ”‚   โ”œโ”€โ”€ inverse_map_cache
โ”‚   โ”œโ”€โ”€ trained_models
โ”‚   โ”œโ”€โ”€ hand.obj
...
โ”‚   โ”œโ”€โ”€ spot.obj

To run the pre-trained models, use the commands below. Results will be saved at results/[name-of-mesh]/[name-of-edit]/renders/infernce.png.

Spot:

python src/main.py --config_path demo/spot/gold_chain_necklace.yaml --log.inference true --log.model_path ./data/trained_models/spot/gold_chain_necklace.pth
python src/main.py --config_path demo/spot/heart-shaped_sunglasses.yaml --log.inference true --log.model_path ./data/trained_models/spot/heart-shaped_sunglasses.pth
python src/main.py --config_path demo/spot/colorful_crochet_hat.yaml --log.inference true --log.model_path ./data/trained_models/spot/colorful_crochet_hat.pth

Person:

python src/main.py --config_path demo/person/tie-dye_apron.yaml --log.inference true --log.model_path ./data/trained_models/person/tie-dye_apron.pth
python src/main.py --config_path demo/person/colorful_polo_shirt.yaml --log.inference true --log.model_path ./data/trained_models/person/colorful_polo_shirt.pth
python src/main.py --config_path demo/person/superman_chest_emblem.yaml --log.inference true --log.model_path ./data/trained_models/person/superman_chest_emblem.pth

Lego Minfigure:

python src/main.py --config_path demo/lego_minifig/barcelona_jersey.yaml --log.inference true --log.model_path ./data/trained_models/lego_minifig/barcelona_jersey.pth
python src/main.py --config_path demo/lego_minifig/blue_denim_overalls.yaml --log.inference true --log.model_path ./data/trained_models/lego_minifig/blue_denim_overalls.pth
python src/main.py --config_path demo/lego_minifig/red_bow_tie.yaml --log.inference true --log.model_path ./data/trained_models/lego_minifig/red_bow_tie.pth

Hand:

python src/main.py --config_path demo/hand/fancy_gold_watch.yaml --log.inference true --log.model_path ./data/trained_models/hand/fancy_gold_watch.pth

From Scratch

To reproduce results from the paper from scratch, just pass a predefined demo config file. Results will be saved at results/[name-of-mesh]/[name-of-edit].

Spot:

python src/main.py --config_path demo/spot/gold_chain_necklace.yaml
python src/main.py --config_path demo/spot/heart-shaped_sunglasses.yaml
python src/main.py --config_path demo/spot/colorful_crochet_hat.yaml

Person:

python src/main.py --config_path demo/person/tie-dye_apron.yaml
python src/main.py --config_path demo/person/colorful_polo.yaml
python src/main.py --config_path demo/person/superman_chest_emblem.yaml

Lego Minifigure:

python src/main.py --config_path demo/lego_minifig/barcelona_jersey.yaml
python src/main.py --config_path demo/lego_minifig/blue_denim_overalls.yaml
python src/main.py --config_path demo/lego_minifig/red_bow_tie.yaml

Hand:

python src/main.py --config_path demo/hand/fancy_gold_watch.yaml

Run your own examples

To run your own examples you can create your own config files and pass those as done in the prior section. Additionally, you can instead pass values for any of the fields in src/configs/train_config as command line arguments. For example, to run the hand example without passing a config file, you may call:

python src/main.py --log.exp_dir results/hand/fancy_gold_watch --mesh.path ./data/spot.obj --guidance.object_name "hand" --guidance.style "fancy gold" --guidance.edit "watch"

Memory Optimization

If you do not have access to a 48 GB GPU, you can...

  1. Enable CPU offloading by setting the flag cpu_offload to True in src/configs/guidance_config.py. This will significanly reduce memory usage, but comes at the cost of speed.
  2. Use a smaller batch size by changing the batch_size parameter either with the command line argument --optim.batch_size or in a custom config file. While this reduces memory usage, it can affect the accuracy.
  3. Sample a subset of surface points each iteration (set sample_points to True and adjust mlp_batch_size). While this reduces memory usage, it can affect the accuracy.
  4. Turn off batched score distillation calls (set batched_sd to False). This will reduce memory usage, but comes at the cost of speed.

Acknowledgements

Our codebase is based on Latent-NeRF/Latent-Paint and our CSD guidance code is structured in the format of ThreeStudio's guidance modules. We thank these authors for their amazing work.

Citation

If you find this code helpful for your research, please cite our paper 3D Paintbrush: Local Stylization of 3D Shapes with Cascaded Score Distillation.

@article{decatur2023paintbrush,
    author = {Decatur, Dale and Lang, Itai and Aberman, Kfir and Hanocka, Rana},
    title  = {3D Paintbrush: Local Stylization of 3D Shapes with Cascaded Score Distillation},
    journal = {arXiv},
    year = {2023}
}

3d-paintbrush's People

Contributors

ddecatur avatar ranahanocka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

3d-paintbrush's Issues

Inquiry Regarding Code Release Date

Really cool and impressive work, I love it very, very much (especially the CSD part) !
I noticed that the code for this project has not yet been released, and I was wondering if you have an estimated timeline for its availability. Thank you (:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.