Giter VIP home page Giter VIP logo

text2tex's Introduction

Text2Tex: Text-driven Texture Synthesis via Diffusion Models

Introduction

We present Text2Tex, a novel method for generating high-quality textures for 3D meshes from the given text prompts. Our method incorporates inpainting into a pre-trained depth-aware image diffusion model to progressively synthesize high resolution partial textures from multiple viewpoints. To avoid accumulating inconsistent and stretched artifacts across views, we dynamically segment the rendered view into a generation mask, which represents the generation status of each visible texel. This partitioned view representation guides the depth-aware inpainting model to generate and update partial textures for the corresponding regions. Furthermore, we propose an automatic view sequence generation scheme to determine the next best view for updating the partial texture. Extensive experiments demonstrate that our method significantly outperforms the existing text-driven approaches and GAN-based methods.

Please also check out the project website here.

For additional detail, please see the Text2Tex paper:
"Text2Tex: Text-driven Texture Synthesis via Diffusion Models"
by Dave Zhenyu Chen, Yawar Siddiqui, Hsin-Ying Lee, Sergey Tulyakov, and Matthias Nießner
from Technical University of Munich and Snap Research.

Setup

The code is tested on Ubuntu 20.04 LTS with PyTorch 1.12.1 CUDA 11.3 installed. Please follow the following steps to install PyTorch first. To run our method, you should at least have a NVIDIA GPU with 12 GB RAM (NVIDIA GeForce 2080 Ti works for us).

# create and activate the conda environment
conda create -n text2tex python=3.9.15
conda activate text2tex

# install PyTorch 1.12.1
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch

Then, install PyTorch3D:

# install runtime dependencies for PyTorch3D
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
conda install -c bottler nvidiacub

# install PyTorch3D
conda install pytorch3d -c pytorch3d

Install xformers to accelerate transformers:

# please don't use pip to install it, as it only supports PyTorch>=2.0
conda install xformers -c xformers

Install the necessary packages listed out in requirements.txt:

pip install -r requirements.txt

To use the ControlNet Depth2img model, please download control_sd15_depth.pth from the hugging face page, and put it under models/ControlNet/models/.

Usage

Try the demo / sanity check

To make sure everything is set up and configured correctly, you can run the following script to generate texture for a backpack.

./bash/run.sh

The generation and refinement should take around 500 sec and 360 sec, respectively. Once the synthesis completes, you should be able to see all generated assets under outputs/backpack/42-p36-h20-1.0-0.3-0.1. Load the final mesh outputs/backpack/42-p36-h20-1.0-0.3-0.1/update/mesh/19.obj in MeshLab, you should be able to see this (so something similar):

Try your own mesh

For the best quality of texture synthesis, there are some necessary pre-processing steps for running our method on your own mesh:

  1. Y-axis is up.
  2. The mesh should face towards +Z.
  3. The mesh bounding box should be origin-aligned (note simply averaging the vertices coordinates could be problematic).
  4. The max length of the mesh bounding box should be around 1.

We provide scripts/normalize_mesh.py and scripts/rotate_mesh.py to make the mesh preprocessing easy for you.

If you already have a normalized mesh but haven't parameterized it yet, please use scripts/parameterize_mesh.py to generate the UV map. Now, you don't have to parameterize your mesh by yourself thanks to xatlas.

NOTE: we expect the mesh to be triangulated.

A mesh ready for next steps should look like this:

Then, you can generate your own texture via:

python scripts/generate_texture.py \
    --input_dir <path-to-mesh> \
    --output_dir outputs/<run-name> \
    --obj_name <mesh-name> \
    --obj_file <mesh-name>.obj \
    --prompt <your-prompt> \
    --add_view_to_prompt \
    --ddim_steps 50 \
    --new_strength 1 \
    --update_strength 0.3 \
    --view_threshold 0.1 \
    --blend 0 \
    --dist 1 \
    --num_viewpoints 36 \
    --viewpoint_mode predefined \
    --use_principle \
    --update_steps 20 \
    --update_mode heuristic \
    --seed 42 \
    --post_process \
    --device 2080 \
    --use_objaverse # assume the mesh is normalized with y-axis as up

If you want some high-res textures, you can set --device to a6000 for 3k resolution. To play around other parameters, please check scripts/generate_texture.py, or simply run python scripts/generate_texture.py -h.

Benchmark on Objaverse subset

To generate textures for the Objaverse objects we used in the paper, please run the following script to download and pre-process those meshes:

python scripts/download_objaverse_subset.py

All pre-processed meshes will be downloaded to data/objaverse/.

Citation

If you found our work helpful, please kindly cite this papers:

@article{chen2023text2tex,
    title={Text2Tex: Text-driven Texture Synthesis via Diffusion Models},
    author={Chen, Dave Zhenyu and Siddiqui, Yawar and Lee, Hsin-Ying and Tulyakov, Sergey and Nie{\ss}ner, Matthias},
    journal={arXiv preprint arXiv:2303.11396},
    year={2023},
}

Acknowledgement

We would like to thank lllyasviel/ControlNet for providing such a great and powerful codebase for diffusion models.

License

Text2Tex is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Copyright (c) 2023 Dave Zhenyu Chen, Yawar Siddiqui, Hsin-Ying Lee, Sergey Tulyakov, and Matthias Nießner

text2tex's People

Contributors

daveredrum avatar mukosame 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  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  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

text2tex's Issues

An error has occurred. ssl & connectionpool during => initializing Inpainting...

image
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/urllib3/util/retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/stabilityai/stable-diffusion-2-inpainting (Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1129)')))

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/data/Text2Tex/scripts/generate_texture.py", line 612, in
inpainting = get_inpainting(DEVICE)
File "/data/Text2Tex/./lib/diffusion_helper.py", line 33, in get_inpainting
model = StableDiffusionInpaintPipeline.from_pretrained(
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 882, in from_pretrained
cached_folder = cls.download(
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 1185, in download
info = model_info(
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/huggingface_hub/hf_api.py", line 2084, in model_info
r = get_session().get(path, headers=headers, timeout=timeout, params=params)
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/requests/sessions.py", line 542, in get
return self.request('GET', url, **kwargs)
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/huggingface_hub/utils/_http.py", line 67, in send
return super().send(request, *args, **kwargs)
File "/root/anaconda3/envs/pytorch3d/lib/python3.9/site-packages/requests/adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/stabilityai/stable-diffusion-2-inpainting (Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1129)')))"), '(Request ID: c0855d4e-9eba-4345-ad1d-28676d7be853)')

golden Porsche

Hi, Thanks for your great work. I tried to reproduce the example of the golden Porsche in the paper, but the results are not consistent with the paper. Could you please tell me which parameters should be adjusted?
image

Customized views

Hello! Thanks for the great work.
Now I am trying to conduct mesh texturing with customized views. I am wondering how to alter the "sectors" in the code, since some of the views are hard to describe with a sector prompt. Can I directly delete it?
I have read your novel work of "SceneTex" with self-setting views. And inside the paper you have conducted comparison with this work, could you share how to alter the sectors part?

Thanks!

text driven

Hello, I am very interested in your research.I want to know, if there is no text prompt, can a mesh alone generate texture? Or what happens if the given text doesn't match the mesh? For example, the mesh is a car and the text prompt is a red apple.

Bag: FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] No such file or directory:

=> initializing input arguments...
=> OUTPUT_DIR: outputs/backpack/42-p36-h20-1.0-0.3-0.1
=> loading target mesh...
=> initializing ControlNet Depth...
ControlLDM: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
Traceback (most recent call last):
  File "/home/dubaiprince/Projects/Text2Tex/scripts/generate_texture.py", line 225, in <module>
    controlnet, ddim_sampler = get_controlnet_depth()
  File "/home/dubaiprince/Projects/Text2Tex/./lib/diffusion_helper.py", line 25, in get_controlnet_depth
    model, ddim_sampler = init_model()
  File "/home/dubaiprince/Projects/Text2Tex/./models/ControlNet/gradio_depth2image.py", line 28, in init_model
    state_dict = load_state_dict(BASE_DIR+'/models/control_sd15_depth.pth')
  File "/home/dubaiprince/Projects/Text2Tex/models/ControlNet/cldm/model.py", line 18, in load_state_dict
    state_dict = get_state_dict(torch.load(ckpt_path, map_location=torch.device(location)))
  File "/home/dubaiprince/miniconda3/envs/text2tex/lib/python3.9/site-packages/torch/serialization.py", line 699, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/dubaiprince/miniconda3/envs/text2tex/lib/python3.9/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/dubaiprince/miniconda3/envs/text2tex/lib/python3.9/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))

perhaps you need to complete the controlnet pth downloading process.

Benchmark against TEXTurePaper

Hey I am curious how this performs (and which hardware you are using) for a mix of different models, and also against TEXTurePaper

项目开源

哈喽,首先对您这研究项目非常感兴趣,请问本项目什么时候可以开源呢?

Release

Now that the paper is accepted to ICCV (congratulations) will the code be released?

Installation Error on Dependence 'mathutils'

Hi, dear developer:
I met such a error when installing 'mathutils' package used in your code:

      src/generic/py_capi_utils.c:1626: warning: ignoring #pragma warning  [-Wunknown-pragmas]
       1626 | #  pragma warning(push)
            |
      src/generic/py_capi_utils.c:1718: warning: ignoring #pragma warning  [-Wunknown-pragmas]
       1718 | #  pragma warning(pop)
            |
      gcc -pthread -B /data/fanpeng/miniconda3/envs/text2tex/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /data/fanpeng/miniconda3/envs/text2tex/include -I/data/fanpeng/miniconda3/envs/text2tex/include -fPIC -O2 -isystem /data/fanpeng/miniconda3/envs/text2tex/include -fPIC -DMATH_STANDALONE -DWITH_ASSERT_ABORT -Isrc/stubs -Isrc/blenlib -Isrc/makesdna -I/data/fanpeng/miniconda3/envs/text2tex/include/python3.9 -c src/mathutils/mathutils.c -o build/temp.linux-x86_64-cpython-39/src/mathutils/mathutils.o -funsigned-char -Wno-sign-compare -Wno-strict-aliasing -std=gnu99
      src/mathutils/mathutils.c: In function ‘mathutils_array_hash’:
      src/mathutils/mathutils.c:79:24: error: incompatible type for argument 1 of ‘_Py_HashDouble’
         79 |     y = _Py_HashDouble(NULL, (double)(array[i++]));
            |                        ^~~~
            |                        |
            |                        void *
      In file included from /data/fanpeng/miniconda3/envs/text2tex/include/python3.9/Python.h:87,
                       from src/mathutils/mathutils.c:7:
      /data/fanpeng/miniconda3/envs/text2tex/include/python3.9/pyhash.h:10:38: note: expected ‘double’ but argument is of type ‘void *’
         10 | PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
            |                                      ^~~~~~
      src/mathutils/mathutils.c:79:9: error: too many arguments to function ‘_Py_HashDouble’
         79 |     y = _Py_HashDouble(NULL, (double)(array[i++]));
            |         ^~~~~~~~~~~~~~
      In file included from /data/fanpeng/miniconda3/envs/text2tex/include/python3.9/Python.h:87,
                       from src/mathutils/mathutils.c:7:
      /data/fanpeng/miniconda3/envs/text2tex/include/python3.9/pyhash.h:10:23: note: declared here
         10 | PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
            |                       ^~~~~~~~~~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mathutils
  Running setup.py clean for mathutils
Failed to build mathutils
ERROR: Could not build wheels for mathutils, which is required to install pyproject.toml-based projects

The mathutils repo doesn't provide any information about it, will you please share whether you have met similar error and how to fix it.

training script?

Is there a training script provided? I have a batch of my own data that I want to train

Poor results on own meshes.

Hi,

For some reason, the results on meshes other than those provided in the examples seem significantly poorer. Are there any key properties of meshes which help / hinder the success of the method?

No mtl file provided

Thank you for excellent work! I want to generate texture for a simple chair and I have OBJ mesh (I put it into ./data/chair/mesh.obj) but no mtl file.
I run:

python scripts/generate_texture.py \
    --input_dir data/chair/ \
    --output_dir outputs/chair \
    --obj_name mesh \
    --obj_file mesh.obj \
    --prompt "wooden chair" \
    --add_view_to_prompt \
    --ddim_steps 50 \
    --new_strength 1 \
    --update_strength 0.3 \
    --view_threshold 0.1 \
    --blend 0 \
    --dist 1 \
    --num_viewpoints 36 \
    --viewpoint_mode predefined \
    --use_principle \
    --update_steps 20 \
    --update_mode heuristic \
    --seed 42 \
    --post_process \
    --device "2080" \
    --use_objaverse

then I get this error:

=> initializing input arguments...
=> OUTPUT_DIR: outputs/chair/42-p36-h20-1.0-0.3-0.1
=> loading target mesh...
/home/zhoujie/anaconda3/envs/text2tex/lib/python3.9/site-packages/pytorch3d/io/obj_io.py:544: UserWarning: No mtl file provided
  warnings.warn("No mtl file provided")
Traceback (most recent call last):
  File "/home/zhoujie/Projects_08/Text2Tex/scripts/generate_texture.py", line 202, in <module>
    verts_uvs=new_verts_uvs[None, ...]
TypeError: 'NoneType' object is not subscriptable

Can you tell me how to prepare the mtl file?

post-process

At the end of the generate_texture.py, there is a post-process operation, i want to know what's the use of it.

`

    #  post-process
    if args.post_process:
        del controlnet
        del ddim_sampler

        inpainting = get_inpainting(DEVICE)
        post_texture = apply_inpainting_postprocess(inpainting, 
            init_texture, 1-exist_texture[None, :, :, None], "", args.uv_size, args.uv_size, DEVICE)

        save_backproject_obj(
            mesh_dir, "{}_post.obj".format(view_idx),
            mesh_scale * mesh.verts_packed() + mesh_center if args.use_unnormalized else mesh.verts_packed(),
            faces.verts_idx, new_verts_uvs, faces.textures_idx, post_texture, 
            DEVICE
        )

`

poor result

Hello,

I tried to run the pipe on my mesh but the result is quite poor. Do I miss something? It seems the UV mapping could be the problem.

I uploaded the mesh and generated result here.

0_after
0_before
1_after
1_before

View inconsistency in the results

Hi! Thanks for releasing the code. Great Work!

I was trying to texturize my own mesh after normalization and required pre-processing, however, I'm getting view-inconsistent results (refer to images below). Can I tweak any hypermeters to achieve the desired results? Increasing the number of viewpoints doesn't help.


Prompt: "a dress made of blue denim"



Mesh in the paper

Hi,
Thanks for your great work, could you please provide all the meshes used in the paper?

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.