Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ImplicitVolume updateable #228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions configs/zero123.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ data: # threestudio/data/image.py -> SingleImageDataModuleConfig
eval_batch_size: 1
elevation_range: [-10, 80]
azimuth_range: [-180, 180]
camera_distance_range: [3.8, 3.8]
camera_distance_range: [3.8, 3.85]
Copy link
Collaborator

@voletiv voletiv Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want these changes to be permanent? Since it's 500 iters, it will be slower than the current config. Instead, maybe add another yaml file with these changes called configs/experimental/zero123_updated.yaml?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the extra steps and the hyperparam changes are worth it in terms of higher quality... @voletiv do you mind testing it out with a few of your images?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... hold on, I want to run a few more tests

fovy_range: [20.0, 20.0] # Zero123 has fixed fovy
progressive_until: 0
camera_perturb: 0.0
center_perturb: 0.0
up_perturb: 0.0
camera_perturb: 0.01
center_perturb: 0.01
up_perturb: 0.01
light_position_perturb: 1.0
light_distance_range: [7.5, 10.0]
eval_elevation_deg: ${data.default_elevation_deg}
Expand Down Expand Up @@ -58,7 +58,7 @@ system:
# use Magic3D density initialization instead
density_bias: "blob_magic3d"
density_activation: softplus
density_blob_scale: 10.
density_blob_scale: [0, 10.0, 0.0, 450] # (start_iter, start_val, end_val, end_iter)
density_blob_std: 0.5

# coarse to fine hash grid encoding
Expand Down Expand Up @@ -114,7 +114,8 @@ system:
#min_step_percent: 0.02
min_step_percent: [0, 0.4, 0.2, 200] # (start_iter, start_val, end_val, end_iter)
#max_step_percent: 0.98
max_step_percent: [0, 0.85, 0.5, 200]
max_step_percent: [0, 0.85, 0.4, 200]
max_items_eval: 1

freq:
ref_only_steps: 0
Expand Down Expand Up @@ -147,7 +148,7 @@ system:
eps: 1.e-8

trainer:
max_steps: 400
max_steps: 500
log_every_n_steps: 1
num_sanity_val_steps: 0
val_check_interval: 100
Expand Down
11 changes: 8 additions & 3 deletions threestudio/models/geometry/implicit_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
contract_to_unisphere,
)
from threestudio.models.networks import get_encoding, get_mlp
from threestudio.utils.base import Updateable
from threestudio.utils.misc import C
from threestudio.utils.ops import get_activation
from threestudio.utils.typing import *


@threestudio.register("implicit-volume")
class ImplicitVolume(BaseImplicitGeometry):
class ImplicitVolume(BaseImplicitGeometry, Updateable):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed as BaseImplicitGeometry (inherit from BaseModule) is already Updateable.

@dataclass
class Config(BaseImplicitGeometry.Config):
n_input_dims: int = 3
Expand Down Expand Up @@ -74,22 +76,25 @@ def configure(self) -> None:
self.encoding.n_output_dims, 3, self.cfg.mlp_network_config
)

def update_step(self, epoch: int, global_step: int, on_load_weights: bool = False):
self.density_blob_scale = C(self.cfg.density_blob_scale, epoch, global_step)

def get_activated_density(
self, points: Float[Tensor, "*N Di"], density: Float[Tensor, "*N 1"]
) -> Tuple[Float[Tensor, "*N 1"], Float[Tensor, "*N 1"]]:
density_bias: Union[float, Float[Tensor, "*N 1"]]
if self.cfg.density_bias == "blob_dreamfusion":
# pre-activation density bias
density_bias = (
self.cfg.density_blob_scale
self.density_blob_scale
* torch.exp(
-0.5 * (points**2).sum(dim=-1) / self.cfg.density_blob_std**2
)[..., None]
)
elif self.cfg.density_bias == "blob_magic3d":
# pre-activation density bias
density_bias = (
self.cfg.density_blob_scale
self.density_blob_scale
* (
1
- torch.sqrt((points**2).sum(dim=-1)) / self.cfg.density_blob_std
Expand Down
76 changes: 76 additions & 0 deletions threestudio/scripts/run_zero123_phase2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,79 @@ python launch.py --config configs/zero123.yaml --train --gpu 0 system.loggers.wa

# PHASE 2
python launch.py --config configs/experimental/imagecondition_zero123nerf.yaml --train --gpu 0 system.prompt_processor.prompt="A DSLR 3D photo of a cute anime schoolgirl stands proudly with her arms in the air, pink hair ( unreal engine 5 trending on Artstation Ghibli 4k )" system.weights=outputs/zero123/128_anya_front_rgba.png@20230623-145711/ckpts/last.ckpt system.freq.guidance_eval=13 system.loggers.wandb.enable=true system.loggers.wandb.project="voletiv-anya-new" data.image_path=./load/images/anya_front_rgba.png system.loggers.wandb.name="anya" data.random_camera.progressive_until=500

# test101_main_default_deepfloyd_with_hashgrid
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/dreamfusion-if.yaml --train \
system.prompt_processor.prompt="A DSLR 3D photo of a cute anime schoolgirl stands proudly with her arms in the air, pink hair ( unreal engine 5 trending on Artstation Ghibli 4k )" \
system.weights="outputs/anya_front/Phase1/ckpts/last.ckpt" \
system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-new-ph2" \
system.loggers.wandb.name="test101_main_default_deepfloyd_with_hashgrid"

# test102_main_default_sd_with_hashgrid
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/dreamfusion-sd.yaml --train \
system.prompt_processor.prompt="A DSLR 3D photo of a cute anime schoolgirl stands proudly with her arms in the air, pink hair ( unreal engine 5 trending on Artstation Ghibli 4k )" \
system.weights="outputs/anya_front/Phase1/ckpts/last.ckpt" \
system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-new-ph2" \
system.loggers.wandb.name="test102_main_default_sd_with_hashgrid"

# test103_main_default_sd_albedo_activation=scale_-11_01
# otherwise, like test102_main_default_sd_with_hashgrid
# results: outputs/dreamfusion-sd/A_DSLR_3D_photo_of_a_cute_anime_schoolgirl_stands_proudly_with_her_arms_in_the_air,_pink_hair_(_unreal_engine_5_trending_on_Artstation_Ghibli_4k_)@20230710-170705/save
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/dreamfusion-sd.yaml --train \
system.prompt_processor.prompt="A DSLR 3D photo of a cute anime schoolgirl stands proudly with her arms in the air, pink hair ( unreal engine 5 trending on Artstation Ghibli 4k )" \
system.weights="outputs/anya_front/Phase1/ckpts/last.ckpt" \
system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-new-ph2" \
system.loggers.wandb.name="test103_main_default_sd_albedo_activation=scale_-11_01"

# test104_main_default_sd_albedo_activation=scale_-11_01;guidance_scale=20
# otherwise, like test102_main_default_sd_with_hashgrid
# results: outputs/dreamfusion-sd/A_DSLR_3D_photo_of_a_cute_anime_schoolgirl_stands_proudly_with_her_arms_in_the_air,_pink_hair_(_unreal_engine_5_trending_on_Artstation_Ghibli_4k_)@20230710-171146
# Conclusion: unstable once the shading is enabled (diverged around step 1400)
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/dreamfusion-sd.yaml --train \
system.prompt_processor.prompt="A DSLR 3D photo of a cute anime schoolgirl stands proudly with her arms in the air, pink hair ( unreal engine 5 trending on Artstation Ghibli 4k )" \
system.weights="outputs/anya_front/Phase1/ckpts/last.ckpt" \
system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-new-ph2" \
system.loggers.wandb.name="test104_main_default_sd_albedo_activation=scale_-11_01;guidance_scale=20"

# test105_grid_prune=false
# otherwise, like test104
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/dreamfusion-sd.yaml --train \
system.prompt_processor.prompt="A DSLR 3D photo of a cute anime schoolgirl stands proudly with her arms in the air, pink hair ( unreal engine 5 trending on Artstation Ghibli 4k )" \
system.weights="outputs/anya_front/Phase1/ckpts/last.ckpt" \
system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-new-ph2" \
system.loggers.wandb.name="test105_grid_prune=false"




# test108_zero123_anneal_density_bias_1000steps
# Phase 1
NAME="anya_front"
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/zero123.yaml --train data.image_path=./load/images/${NAME}_rgba.png \
system.guidance.pretrained_model_name_or_path="./load/zero123/XL_20230604.ckpt" \
use_timestamp=False name=${NAME} tag="Phase1_annealed_density_bias" \
system.freq.guidance_eval=37 system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-ph1-again" system.loggers.wandb.name="test108_zero123_anneal_density_bias_1000steps"

# test109_zero123_1000steps_batch_size=[12,4,1]
# Phase 1
NAME="anya_front"
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/zero123.yaml --train data.image_path=./load/images/${NAME}_rgba.png \
system.guidance.pretrained_model_name_or_path="./load/zero123/XL_20230604.ckpt" \
use_timestamp=False name=${NAME} tag="Phase1_annealed_density_bias" \
system.freq.guidance_eval=37 system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-ph1-again" system.loggers.wandb.name="test109_zero123_1000steps_batch_size=[12,4,1]"

# test110_zero123_500steps_lots_of_changes
# Phase 1
NAME="anya_front"
srun --account mod3d --partition=g40 --gpus=1 --job-name=3s_anya \
python launch.py --config configs/zero123.yaml --train data.image_path=./load/images/${NAME}_rgba.png \
system.guidance.pretrained_model_name_or_path="./load/zero123/XL_20230604.ckpt" \
use_timestamp=False name=${NAME} tag="Phase1_annealed_density_bias" \
system.freq.guidance_eval=37 system.loggers.wandb.enable=true system.loggers.wandb.project="claforte-anya-ph1-again" system.loggers.wandb.name="test110_zero123_500steps_lots_of_changes"