perler commited on
Commit
0adea73
1 Parent(s): f77687d

other files from TEXTure

Browse files
Files changed (9) hide show
  1. Dockerfile +59 -0
  2. gitignore +164 -0
  3. gitmodules +3 -0
  4. model.py +94 -0
  5. patch +34 -0
  6. pre-commit-config.yaml +36 -0
  7. requirements.txt +16 -0
  8. style.css +3 -0
  9. style.yapf +5 -0
Dockerfile ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04
2
+ ENV DEBIAN_FRONTEND=noninteractive
3
+ RUN apt-get update && \
4
+ apt-get upgrade -y && \
5
+ apt-get install -y --no-install-recommends \
6
+ git \
7
+ wget \
8
+ curl \
9
+ zip \
10
+ # ffmpeg \
11
+ ffmpeg \
12
+ x264 \
13
+ # python build dependencies \
14
+ build-essential \
15
+ libssl-dev \
16
+ zlib1g-dev \
17
+ libbz2-dev \
18
+ libreadline-dev \
19
+ libsqlite3-dev \
20
+ libncursesw5-dev \
21
+ xz-utils \
22
+ tk-dev \
23
+ libxml2-dev \
24
+ libxmlsec1-dev \
25
+ libffi-dev \
26
+ liblzma-dev && \
27
+ apt-get clean && \
28
+ rm -rf /var/lib/apt/lists/*
29
+
30
+ RUN useradd -m -u 1000 user
31
+ USER user
32
+ ENV HOME=/home/user \
33
+ PATH=/home/user/.local/bin:${PATH}
34
+ WORKDIR ${HOME}/app
35
+
36
+ RUN curl https://pyenv.run | bash
37
+ ENV PATH=${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:${PATH}
38
+ ARG PYTHON_VERSION=3.9.16
39
+ RUN pyenv install ${PYTHON_VERSION} && \
40
+ pyenv global ${PYTHON_VERSION} && \
41
+ pyenv rehash && \
42
+ pip install --no-cache-dir -U pip setuptools wheel
43
+
44
+ RUN pip install --no-cache-dir -U torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
45
+ COPY --chown=1000 requirements.txt /tmp
46
+ RUN pip install --no-cache-dir -r /tmp/requirements.txt
47
+ RUN pip install --no-cache-dir -U kaolin==0.13.0 -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-1.12.1_cu113.html
48
+ RUN pip install --no-cache-dir -U gradio==3.34.0
49
+
50
+ COPY --chown=1000 . ${HOME}/app
51
+ RUN cd TEXTurePaper && patch -p1 < ../patch
52
+ ENV PYTHONPATH=${HOME}/app \
53
+ PYTHONUNBUFFERED=1 \
54
+ GRADIO_ALLOW_FLAGGING=never \
55
+ GRADIO_NUM_PORTS=1 \
56
+ GRADIO_SERVER_NAME=0.0.0.0 \
57
+ GRADIO_THEME=huggingface \
58
+ SYSTEM=spaces
59
+ CMD ["python", "app.py"]
gitignore ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cache/
2
+ experiments/
3
+ *.zip
4
+
5
+ # Byte-compiled / optimized / DLL files
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+ cover/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ .pybuilder/
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ # For a library or package, you might want to ignore these files since the code is
91
+ # intended to run in multiple environments; otherwise, check them in:
92
+ # .python-version
93
+
94
+ # pipenv
95
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
97
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
98
+ # install all needed dependencies.
99
+ #Pipfile.lock
100
+
101
+ # poetry
102
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
104
+ # commonly ignored for libraries.
105
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106
+ #poetry.lock
107
+
108
+ # pdm
109
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110
+ #pdm.lock
111
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112
+ # in version control.
113
+ # https://pdm.fming.dev/#use-with-ide
114
+ .pdm.toml
115
+
116
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117
+ __pypackages__/
118
+
119
+ # Celery stuff
120
+ celerybeat-schedule
121
+ celerybeat.pid
122
+
123
+ # SageMath parsed files
124
+ *.sage.py
125
+
126
+ # Environments
127
+ .env
128
+ .venv
129
+ env/
130
+ venv/
131
+ ENV/
132
+ env.bak/
133
+ venv.bak/
134
+
135
+ # Spyder project settings
136
+ .spyderproject
137
+ .spyproject
138
+
139
+ # Rope project settings
140
+ .ropeproject
141
+
142
+ # mkdocs documentation
143
+ /site
144
+
145
+ # mypy
146
+ .mypy_cache/
147
+ .dmypy.json
148
+ dmypy.json
149
+
150
+ # Pyre type checker
151
+ .pyre/
152
+
153
+ # pytype static type analyzer
154
+ .pytype/
155
+
156
+ # Cython debug symbols
157
+ cython_debug/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ #.idea/
gitmodules ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [submodule "TEXTurePaper"]
2
+ path = TEXTurePaper
3
+ url = https://github.com/TEXTurePaper/TEXTurePaper
model.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import datetime
4
+ import pathlib
5
+ import shlex
6
+ import subprocess
7
+ import sys
8
+ from typing import Generator, Optional
9
+
10
+ import gradio as gr
11
+ import trimesh
12
+
13
+ sys.path.append('TEXTurePaper')
14
+
15
+ from src.configs.train_config import GuideConfig, LogConfig, TrainConfig
16
+ from src.training.trainer import TEXTure
17
+
18
+
19
+ class Model:
20
+ def __init__(self):
21
+ self.max_num_faces = 100000
22
+
23
+ def load_config(self, shape_path: str, text: str, seed: int,
24
+ guidance_scale: float) -> TrainConfig:
25
+ text += ', {} view'
26
+
27
+ log = LogConfig(exp_name=self.gen_exp_name())
28
+ guide = GuideConfig(text=text)
29
+ guide.background_img = 'TEXTurePaper/textures/brick_wall.png'
30
+ guide.shape_path = 'TEXTurePaper/shapes/spot_triangulated.obj'
31
+ config = TrainConfig(log=log, guide=guide)
32
+
33
+ config.guide.shape_path = shape_path
34
+ config.optim.seed = seed
35
+ config.guide.guidance_scale = guidance_scale
36
+ return config
37
+
38
+ def gen_exp_name(self) -> str:
39
+ now = datetime.datetime.now()
40
+ return now.strftime('%Y-%m-%d-%H-%M-%S')
41
+
42
+ def check_num_faces(self, path: str) -> bool:
43
+ with open(path) as f:
44
+ lines = [line for line in f.readlines() if line.startswith('f')]
45
+ return len(lines) <= self.max_num_faces
46
+
47
+ def zip_results(self, exp_dir: pathlib.Path) -> str:
48
+ mesh_dir = exp_dir / 'mesh'
49
+ out_path = f'{exp_dir.name}.zip'
50
+ subprocess.run(shlex.split(f'zip -r {out_path} {mesh_dir}'))
51
+ return out_path
52
+
53
+ def run(
54
+ self, shape_path: str, text: str, seed: int, guidance_scale: float
55
+ ) -> Generator[tuple[list[str], Optional[str], Optional[str], str], None,
56
+ None]:
57
+ if not shape_path.endswith('.obj'):
58
+ raise gr.Error('The input file is not .obj file.')
59
+ if not self.check_num_faces(shape_path):
60
+ raise gr.Error('The number of faces is over 100,000.')
61
+
62
+ config = self.load_config(shape_path, text, seed, guidance_scale)
63
+ trainer = TEXTure(config)
64
+
65
+ trainer.mesh_model.train()
66
+
67
+ total_steps = len(trainer.dataloaders['train'])
68
+ for step, data in enumerate(trainer.dataloaders['train'], start=1):
69
+ trainer.paint_step += 1
70
+ trainer.paint_viewpoint(data)
71
+ trainer.evaluate(trainer.dataloaders['val'],
72
+ trainer.eval_renders_path)
73
+ trainer.mesh_model.train()
74
+
75
+ sample_image_dir = config.log.exp_dir / 'vis' / 'eval'
76
+ sample_image_paths = sorted(
77
+ sample_image_dir.glob(f'step_{trainer.paint_step:05d}_*.jpg'))
78
+ sample_image_paths = [
79
+ path.as_posix() for path in sample_image_paths
80
+ ]
81
+ yield sample_image_paths, None, None, f'{step}/{total_steps}'
82
+
83
+ trainer.mesh_model.change_default_to_median()
84
+
85
+ save_dir = trainer.exp_path / 'mesh'
86
+ save_dir.mkdir(exist_ok=True, parents=True)
87
+ trainer.mesh_model.export_mesh(save_dir)
88
+ model_path = save_dir / 'mesh.obj'
89
+ mesh = trimesh.load(model_path)
90
+ mesh_path = save_dir / 'mesh.glb'
91
+ mesh.export(mesh_path, file_type='glb')
92
+
93
+ zip_path = self.zip_results(config.log.exp_dir)
94
+ yield sample_image_paths, mesh_path.as_posix(), zip_path, 'Done!'
patch ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/src/models/textured_mesh.py b/src/models/textured_mesh.py
2
+ index 75ffb6d..40d30e6 100644
3
+ --- a/src/models/textured_mesh.py
4
+ +++ b/src/models/textured_mesh.py
5
+ @@ -122,7 +122,7 @@ class TexturedMeshModel(nn.Module):
6
+
7
+ self.renderer = Renderer(device=self.device, dim=(render_grid_size, render_grid_size),
8
+ interpolation_mode=self.opt.texture_interpolation_mode)
9
+ - self.env_sphere, self.mesh = self.init_meshes()
10
+ + self.env_sphere, self.mesh = self.init_meshes(opt.shape_path)
11
+ self.default_color = [0.8, 0.1, 0.8]
12
+ self.background_sphere_colors, self.texture_img = self.init_paint()
13
+ self.meta_texture_img = nn.Parameter(torch.zeros_like(self.texture_img))
14
+ diff --git a/src/stable_diffusion_depth.py b/src/stable_diffusion_depth.py
15
+ index 610d2de..e172080 100644
16
+ --- a/src/stable_diffusion_depth.py
17
+ +++ b/src/stable_diffusion_depth.py
18
+ @@ -1,3 +1,5 @@
19
+ +import os
20
+ +
21
+ from diffusers import AutoencoderKL, UNet2DConditionModel, PNDMScheduler
22
+ from huggingface_hub import hf_hub_download
23
+ from transformers import CLIPTextModel, CLIPTokenizer, logging
24
+ @@ -24,9 +26,7 @@ class StableDiffusion(nn.Module):
25
+ super().__init__()
26
+
27
+ try:
28
+ - with open('./TOKEN', 'r') as f:
29
+ - self.token = f.read().replace('\n', '') # remove the last \n!
30
+ - logger.info(f'loaded hugging face access token from ./TOKEN!')
31
+ + self.token = os.getenv('HF_TOKEN')
32
+ except FileNotFoundError as e:
33
+ self.token = True
34
+ logger.warning(
pre-commit-config.yaml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ exclude: patch
2
+ repos:
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ rev: v4.2.0
5
+ hooks:
6
+ - id: check-executables-have-shebangs
7
+ - id: check-json
8
+ - id: check-merge-conflict
9
+ - id: check-shebang-scripts-are-executable
10
+ - id: check-toml
11
+ - id: check-yaml
12
+ - id: double-quote-string-fixer
13
+ - id: end-of-file-fixer
14
+ - id: mixed-line-ending
15
+ args: ['--fix=lf']
16
+ - id: requirements-txt-fixer
17
+ - id: trailing-whitespace
18
+ - repo: https://github.com/myint/docformatter
19
+ rev: v1.4
20
+ hooks:
21
+ - id: docformatter
22
+ args: ['--in-place']
23
+ - repo: https://github.com/pycqa/isort
24
+ rev: 5.12.0
25
+ hooks:
26
+ - id: isort
27
+ - repo: https://github.com/pre-commit/mirrors-mypy
28
+ rev: v0.991
29
+ hooks:
30
+ - id: mypy
31
+ args: ['--ignore-missing-imports']
32
+ - repo: https://github.com/google/yapf
33
+ rev: v0.32.0
34
+ hooks:
35
+ - id: yapf
36
+ args: ['--parallel', '--in-place']
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==0.19.0
2
+ diffusers==0.16.1
3
+ einops==0.6.1
4
+ huggingface-hub==0.15.1
5
+ imageio[ffmpeg,pyav]==2.28.1
6
+ loguru==0.7.0
7
+ matplotlib==3.7.1
8
+ ninja==1.11.1
9
+ opencv-python-headless==4.7.0.72
10
+ pyrallis==0.3.1
11
+ torch==1.12.1
12
+ torchvision==0.13.1
13
+ tqdm==4.65.0
14
+ transformers==4.29.1
15
+ trimesh==3.21.6
16
+ xatlas==0.0.7
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ }
style.yapf ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [style]
2
+ based_on_style = pep8
3
+ blank_line_before_nested_class_or_def = false
4
+ spaces_before_comment = 2
5
+ split_before_logical_operator = true