Skip to content

Commit

Permalink
(fix): Bar init lag
Browse files Browse the repository at this point in the history
(adjust): Moving resize cameras logic
  • Loading branch information
AsherJingkongChen committed Dec 10, 2024
1 parent d486b96 commit 184346b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crates/gausplat-renderer
2 changes: 1 addition & 1 deletion examples/gausplat-scepter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn main() -> Result<(), Report> {
use ModelCommand::*;

init()?;
log::info!(target: "gausplat::scepter::main", "init");
log::info!(target: "gausplat::scepter::main", "start");

let args = GausplatArguments::parse()?;
let args = match &args.model {
Expand Down
17 changes: 16 additions & 1 deletion examples/gausplat-scepter/src/runner/gaussian_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use gausplat::trainer::{
metric::{MeanStructuralSimilarity, Metric, Psnr},
train::gaussian_3d::{Tensor, WgpuDevice},
};
use rayon::slice::ParallelSliceMut;
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut};

/// ## Returns
///
Expand Down Expand Up @@ -160,3 +160,18 @@ pub fn get_mssim_and_psnr(

Ok((mssim_mean, psnr_mean))
}

/// Resize `cameras` to proper sizes.
pub fn resize_cameras(cameras: &mut Cameras) -> Result<(), Report> {
const IMAGE_SIZE_MIN: u32 = 320;
const IMAGE_SIZE_MAX: u32 = IMAGE_SIZE_MIN * 5;

cameras.par_values_mut().try_for_each(|camera| {
let size_source = camera.size_max();
let size_target = size_source.clamp(IMAGE_SIZE_MIN, IMAGE_SIZE_MAX);
if size_source != size_target {
camera.resize_max(size_target)?;
}
Ok(())
})
}
3 changes: 3 additions & 0 deletions examples/gausplat-scepter/src/runner/gaussian_3d/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ impl RenderRunner {
let should_show_progress = !bar.disable && size != 0;

bar.reset(Some(size));
if should_show_progress {
bar.refresh()?;
}

let result = cameras
.into_values()
Expand Down
22 changes: 6 additions & 16 deletions examples/gausplat-scepter/src/runner/gaussian_3d/train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use gausplat::trainer::{
Autodiff, AutodiffModule, Gaussian3dTrainer, RefinerConfig, SEED,
},
};
use rayon::iter::ParallelIterator;
use std::{
fmt, fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -86,9 +85,6 @@ impl TrainRunner {

impl Runner for TrainRunner {
fn run(mut self) -> Result<(), Report> {
const IMAGE_SIZE_MIN: u32 = 320;
const IMAGE_SIZE_MAX: u32 = IMAGE_SIZE_MIN * 5;

// Specifying the parameters

let device = self.scene.device();
Expand Down Expand Up @@ -123,22 +119,16 @@ impl Runner for TrainRunner {
// Rescaling down the images at initialization

let time = Instant::now();
self.cameras_train.par_values_mut().try_for_each(|camera| {
let size_source = camera.size_max();
let size_target = size_source.clamp(IMAGE_SIZE_MIN, IMAGE_SIZE_MAX);
if size_source != size_target {
camera.resize_max(size_target)?;
}
Ok::<_, Report>(())
})?;
resize_cameras(&mut self.cameras_train)?;
log::info!(
target: "gausplat::scepter::gaussian_3d::train",
"may rescale in {:.03?}", time.elapsed(),
);

// Optimizing the scene iteratively

self.cameras_train
let result = self
.cameras_train
.seed(SEED)
.random_values()
.take(iterations)
Expand Down Expand Up @@ -204,14 +194,14 @@ impl Runner for TrainRunner {
}
}

Ok::<_, Report>(())
})?;
Ok(())
});

if !bar.disable {
eprintln!();
}

Ok(())
result
}
}

Expand Down

0 comments on commit 184346b

Please sign in to comment.