ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
train.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7#include <reusex/gsplat/GaussianCloud.hpp>
8#include <reusex/gsplat/TrainingViews.hpp>
9
10#include <atomic>
11#include <cstdint>
12#include <filesystem>
13#include <string>
14#include <vector>
15
16namespace cv {
17class Mat;
18}
19
20namespace reusex {
21class ProjectDB;
22}
23
24namespace reusex::gsplat {
25
38 bool enabled = false;
39
46 double cap_factor = 2.0;
47 std::int64_t cap_absolute = 0;
48
50 double growth = 1.05;
51
52 int refine_every = 100;
53 int refine_start = 500;
57 double refine_stop_fraction = 0.85;
58
60 float min_opacity = 0.005f;
61
62 float noise_lr = 5e5f;
63 float noise_opacity_t = 0.005f;
64 float noise_opacity_k = 100.0f;
65
88 float opacity_reg = 0.0f;
89 float scale_reg = 0.0f;
90};
91
99 int iterations = 2000;
100
101 float lr_means = 1.6e-4f;
102 float lr_scales = 5e-3f;
103 float lr_quats = 1e-3f;
104 float lr_opacities = 5e-2f;
105 float lr_sh_dc = 2.5e-3f;
106
116 float lr_sh_rest = 2.5e-3f / 20.0f;
117
132
134 float lambda_dssim = 0.2f;
135
142 bool prune_enabled = true;
143 int prune_interval = 500;
144 int prune_start = 500;
145 float prune_opacity = 0.005f;
146 float prune_max_scale = 10.0f;
147
152
161
165 int eval_interval = 1000;
166
171
182 unsigned seed = 42;
183
184 int log_interval = 100;
185
188 std::vector<int> render_iterations;
189 std::filesystem::path render_dir;
190 std::size_t render_view_index = 0;
191
200 const std::atomic_bool *cancel_token = nullptr;
201
211 std::filesystem::path checkpoint_dir;
212};
213
216 int iteration = 0;
217 double loss = 0;
218 double l1 = 0;
219 double psnr = 0;
220 std::size_t gaussians = 0;
221};
222
229 int iteration = 0;
230 double train_psnr = 0;
231 double train_ssim = 0;
232 double holdout_psnr = 0;
233 double holdout_ssim = 0;
234 std::size_t train_views = 0;
235 std::size_t holdout_views = 0;
236 std::size_t gaussians = 0;
237};
238
241 std::vector<TrainMetrics> history;
243 std::vector<EvalMetrics> evals;
244 double seconds = 0;
245 std::size_t final_count = 0;
246 double final_psnr = 0;
251 std::size_t relocated = 0;
252 std::size_t added = 0;
253
262 std::vector<std::size_t> trained_views;
263 std::vector<std::size_t> holdout_view_indices;
267 std::vector<std::filesystem::path> renders;
268
273 std::vector<std::filesystem::path> checkpoints;
274
282
286 bool cancelled = false;
290};
291
296
302
312 const std::vector<TrainingView> &views,
313 const TrainOptions &opt = {});
314
317cv::Mat render_view(const GaussianCloud &gaussians, const TrainingView &view);
318
321 std::string seed_cloud = "cloud";
325
331 std::string splat_name = "splat";
332
335 std::filesystem::path out_ply;
336};
337
360
361} // namespace reusex::gsplat
cv::Mat render_view(const GaussianCloud &gaussians, const TrainingView &view)
Rasterize gaussians from view.
TrainResult train_gaussians(const GaussianCloud &init, const std::vector< TrainingView > &views, const TrainOptions &opt={})
Train Gaussians against posed views.
bool is_available()
True when this build actually contains the CUDA trainer.
TrainResult run_gsplat_stage(ProjectDB &db, const GsplatStageOptions &opt)
Load the seed cloud and views from db, train, and store the splat.
bool has_cuda_device()
True when this process can actually reach a CUDA device right now.
One held-out evaluation pass.
Definition train.hpp:228
double holdout_psnr
dB over views it never sees
Definition train.hpp:232
double train_psnr
dB over views the optimizer does see
Definition train.hpp:230
A set of 3D Gaussians in plain host memory.
Parameters for seeding Gaussians from a ReUseX point cloud.
End-to-end options for the rux create gsplat stage.
Definition train.hpp:320
std::string splat_name
Name the trained splat is stored under in the project (#322).
Definition train.hpp:331
std::string seed_cloud
ProjectDB cloud used to seed Gaussians.
Definition train.hpp:321
TrainingViewOptions views
Definition train.hpp:323
std::filesystem::path out_ply
Optional extra copy on disk, for a viewer outside ReUseX.
Definition train.hpp:335
3DGS-MCMC density control (Kheradmand et al.
Definition train.hpp:37
float noise_lr
scales the Langevin noise (paper's value)
Definition train.hpp:62
float opacity_reg
L1 regularizers in activated space.
Definition train.hpp:88
float min_opacity
Opacity at or below which a Gaussian counts as dead and is relocated.
Definition train.hpp:60
int refine_start
first eligible iteration
Definition train.hpp:53
int refine_every
iterations between relocate+grow passes
Definition train.hpp:52
double cap_factor
Hard ceiling on the Gaussian count, as a multiple of the seed count.
Definition train.hpp:46
double growth
Multiplicative growth per refine pass, capped by the budget.
Definition train.hpp:50
float noise_opacity_k
noise gate sharpness
Definition train.hpp:64
std::int64_t cap_absolute
Definition train.hpp:47
double refine_stop_fraction
Last eligible iteration, as a fraction of the run.
Definition train.hpp:57
float noise_opacity_t
noise gate transition point
Definition train.hpp:63
One row of the loss history.
Definition train.hpp:215
double psnr
dB, from the MSE of the same view
Definition train.hpp:219
double loss
the optimized objective
Definition train.hpp:217
double l1
mean absolute error against the target view
Definition train.hpp:218
Optimizer / schedule parameters for the 3DGS training loop.
Definition train.hpp:98
int eval_max_views
Upper bound on the views used per evaluation pass, per side.
Definition train.hpp:170
const std::atomic_bool * cancel_token
Cooperative cancellation, owned by the caller and polled once per iteration.
Definition train.hpp:200
float lambda_dssim
Weight of the D-SSIM term: loss = (1-l)*L1 + l*(1 - SSIM).
Definition train.hpp:134
int sh_degree_interval
Iterations between unlocking one more SH band (reference 3DGS's oneUpSHdegree).
Definition train.hpp:131
int checkpoint_keep
How many checkpoint files to keep; older ones are deleted as new ones land.
Definition train.hpp:208
MCMCOptions mcmc
MCMC density control.
Definition train.hpp:151
int prune_interval
iterations between prune passes
Definition train.hpp:143
float lr_opacities
on logit-opacity
Definition train.hpp:104
std::filesystem::path checkpoint_dir
Directory for checkpoint .ply files.
Definition train.hpp:211
bool prune_enabled
Periodically drop Gaussians whose opacity has collapsed.
Definition train.hpp:142
float lr_means
scaled by scene extent (see above)
Definition train.hpp:101
unsigned seed
Seeds the per-iteration view draw, which makes the training schedule reproducible.
Definition train.hpp:182
float prune_max_scale
drop Gaussians larger than this [m]
Definition train.hpp:146
float lr_scales
on log-scales
Definition train.hpp:102
int checkpoint_every
Write an intermediate .ply every N iterations (0 = off, the default).
Definition train.hpp:205
int log_interval
iterations between progress log lines
Definition train.hpp:184
std::size_t render_view_index
Definition train.hpp:190
int holdout_every
Held-out split: every holdout_every-th view (indices 0, N, 2N, …) is excluded from training and used ...
Definition train.hpp:160
std::vector< int > render_iterations
Dump a rendered PNG of render_view_index at each of these iterations (0 = the untrained seed).
Definition train.hpp:188
float lr_sh_rest
Learning rate for SH degrees 1..GaussianInitOptions::sh_degree — the view-*dependent* colour.
Definition train.hpp:116
int prune_start
first iteration eligible for pruning
Definition train.hpp:144
std::filesystem::path render_dir
Definition train.hpp:189
float lr_sh_dc
on the degree-0 SH coefficients
Definition train.hpp:105
float lr_quats
on raw (unnormalised) quaternions
Definition train.hpp:103
float prune_opacity
alpha below which a Gaussian is dropped
Definition train.hpp:145
int eval_interval
Iterations between held-out evaluation passes.
Definition train.hpp:165
std::size_t added
cumulative MCMC growth
Definition train.hpp:252
std::vector< std::filesystem::path > checkpoints
Intermediate .ply files from the checkpoint_every schedule that are still on disk,...
Definition train.hpp:273
std::vector< std::size_t > holdout_view_indices
Definition train.hpp:263
std::vector< EvalMetrics > evals
Held-out evaluations, empty when TrainOptions::holdout_every is 0.
Definition train.hpp:243
double final_holdout_psnr
Held-out PSNR at the last evaluation, 0 when there was no split.
Definition train.hpp:249
std::vector< std::filesystem::path > renders
PNGs written by the render_iterations schedule, in write order.
Definition train.hpp:267
double final_psnr
mean PSNR over the last logged window
Definition train.hpp:246
std::size_t relocated
cumulative MCMC relocations
Definition train.hpp:251
int iterations_run
The last iteration actually executed.
Definition train.hpp:289
int final_sh_degree
The highest SH degree the warm-up schedule actually unlocked, which is not always gaussians....
Definition train.hpp:281
std::vector< std::size_t > trained_views
The view indices the optimizer actually drew during the run, sorted and deduplicated,...
Definition train.hpp:262
GaussianCloud gaussians
Definition train.hpp:240
std::vector< TrainMetrics > history
Definition train.hpp:241
bool cancelled
True when the run stopped early on a cancel request rather than by reaching TrainOptions::iterations.
Definition train.hpp:286
Selection and preprocessing knobs for building the training set.
One posed training image for the Gaussian-splatting optimizer.