Spaces:
Runtime error
Runtime error
# -*- coding: utf-8 -*- | |
"""3D-DreamGaussian_demo.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1ll2NcJouGKXw1Qv0u7CpnOX5JMFiBfZH | |
# [DreamGaussian](https://github.com/dreamgaussian/dreamgaussian) image-to-3D demo | |
""" | |
# Commented out IPython magic to ensure Python compatibility. | |
#@title install (only run once) | |
# %rm -r dreamgaussian | |
git clone https://github.com/dreamgaussian/dreamgaussian | |
# %cd dreamgaussian | |
# install dependencies | |
pip install -q einops plyfile dearpygui huggingface_hub diffusers accelerate transformers xatlas trimesh PyMCubes pymeshlab rembg[gpu,cli] omegaconf ninja | |
# build extension from source (can be slow) | |
# !git clone --recursive https://github.com/ashawkey/diff-gaussian-rasterization | |
# !pip install -q ./diff-gaussian-rasterization | |
# !pip install -q ./simple-knn | |
# pre-built wheels (faster) | |
pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.1.whl | |
pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/simple_knn-0.0.0-cp310-cp310-linux_x86_64.1.whl | |
# nvdiffrast | |
pip install -q git+https://github.com/NVlabs/nvdiffrast | |
# kiuikit | |
pip install -q git+https://github.com/ashawkey/kiuikit | |
# %mkdir -p data | |
# Commented out IPython magic to ensure Python compatibility. | |
#@title upload image | |
import os | |
# %cd data/ | |
# %rm * # remove all old files! | |
from google.colab import files | |
uploaded = files.upload() | |
IMAGE = os.path.basename(next(iter(uploaded))) # filename | |
# %cd .. | |
# display image | |
from IPython.display import Image, display | |
display(Image(f'data/{IMAGE}', width=256, height=256)) | |
# Commented out IPython magic to ensure Python compatibility. | |
#@title preprocess image | |
# preprocess | |
# %run process.py data/{IMAGE} | |
NAME = os.path.splitext(IMAGE)[0] | |
IMAGE_PROCESSED = NAME + '_rgba.png' | |
# display processed image | |
from IPython.display import Image, display | |
display(Image(f'data/{IMAGE_PROCESSED}', width=256, height=256)) | |
"""# Settings | |
* Elevation: estimated elevation angle, default to 0 (horizontal), range from [-90, 90]. If you upload a look-down image, try a value like -30. | |
""" | |
#@markdown ####**Settings:** | |
Elevation = 0 #@param {type: 'integer'} | |
# Commented out IPython magic to ensure Python compatibility. | |
#@title training! | |
# stage 1 | |
# %run main.py --config configs/image.yaml input=data/{IMAGE_PROCESSED} save_path={NAME} elevation={Elevation} force_cuda_rast=True | |
# stage 2 | |
# %run main2.py --config configs/image.yaml input=data/{IMAGE_PROCESSED} save_path={NAME} elevation={Elevation} force_cuda_rast=True | |
# Commented out IPython magic to ensure Python compatibility. | |
#@title render a video for displaying | |
# the final mesh is saved to ./logs/NAME.obj | |
# %run -m kiui.render logs/{NAME}.obj --save_video {NAME}.mp4 --wogui --force_cuda_rast | |
from IPython.display import HTML | |
from base64 import b64encode | |
def show_video(video_path, video_width=450): | |
video_file = open(video_path, "r+b").read() | |
video_url = f"data:video/mp4;base64,{b64encode(video_file).decode()}" | |
return HTML(f"""<video width={video_width} controls><source src="{video_url}"></video>""") | |
show_video(f'{NAME}.mp4') |