Class: Gsplat::Strategy::Default
- Defined in:
- lib/gsplat/strategy/default.rb
Overview
Original 3DGS densification strategy with gsplat refinements.
Constant Summary collapse
- DEFAULTS =
Upstream-compatible densification defaults.
{ prune_opa: 0.005, grow_grad2d: 0.0002, grow_scale3d: 0.01, grow_scale2d: 0.05, prune_scale3d: 0.1, prune_scale2d: 0.15, refine_scale2d_stop_iter: 0, refine_start_iter: 500, refine_stop_iter: 15_000, reset_every: 3_000, refine_every: 100, pause_refine_after_reset: 0, absgrad: false, revised_opacity: false, key_for_gradient: :means2d }.freeze
Constants inherited from Base
Instance Attribute Summary collapse
-
#absgrad ⇒ Object
readonly
Returns the value of attribute absgrad.
-
#grow_grad2d ⇒ Object
readonly
Returns the value of attribute grow_grad2d.
-
#grow_scale2d ⇒ Object
readonly
Returns the value of attribute grow_scale2d.
-
#grow_scale3d ⇒ Object
readonly
Returns the value of attribute grow_scale3d.
-
#key_for_gradient ⇒ Object
readonly
Returns the value of attribute key_for_gradient.
-
#pause_refine_after_reset ⇒ Object
readonly
Returns the value of attribute pause_refine_after_reset.
-
#prune_opa ⇒ Object
readonly
Returns the value of attribute prune_opa.
-
#prune_scale2d ⇒ Object
readonly
Returns the value of attribute prune_scale2d.
-
#prune_scale3d ⇒ Object
readonly
Returns the value of attribute prune_scale3d.
-
#refine_every ⇒ Object
readonly
Returns the value of attribute refine_every.
-
#refine_scale2d_stop_iter ⇒ Object
readonly
Returns the value of attribute refine_scale2d_stop_iter.
-
#refine_start_iter ⇒ Object
readonly
Returns the value of attribute refine_start_iter.
-
#refine_stop_iter ⇒ Object
readonly
Returns the value of attribute refine_stop_iter.
-
#reset_every ⇒ Object
readonly
Returns the value of attribute reset_every.
-
#revised_opacity ⇒ Object
readonly
Returns the value of attribute revised_opacity.
Instance Method Summary collapse
-
#initialize(**options) ⇒ Default
constructor
A new instance of Default.
-
#initialize_state(scene_scale:) ⇒ Hash
Creates mutable gradient/radius statistics for a scene.
-
#refinement_masks(params, state) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#step_post_backward(params:, optimizers:, state:, step:, info:, **_options) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Methods inherited from Base
#check_sanity, #step_pre_backward
Constructor Details
#initialize(**options) ⇒ Default
Returns a new instance of Default.
32 33 34 35 36 37 38 39 |
# File 'lib/gsplat/strategy/default.rb', line 32 def initialize(**) super() unknown = .keys - DEFAULTS.keys raise ArgumentError, "unknown options: #{unknown.join(', ')}" unless unknown.empty? DEFAULTS.merge().each { |name, value| instance_variable_set(:"@#{name}", value) } end |
Instance Attribute Details
#absgrad ⇒ Object (readonly)
Returns the value of attribute absgrad.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def absgrad @absgrad end |
#grow_grad2d ⇒ Object (readonly)
Returns the value of attribute grow_grad2d.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def grow_grad2d @grow_grad2d end |
#grow_scale2d ⇒ Object (readonly)
Returns the value of attribute grow_scale2d.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def grow_scale2d @grow_scale2d end |
#grow_scale3d ⇒ Object (readonly)
Returns the value of attribute grow_scale3d.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def grow_scale3d @grow_scale3d end |
#key_for_gradient ⇒ Object (readonly)
Returns the value of attribute key_for_gradient.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def key_for_gradient @key_for_gradient end |
#pause_refine_after_reset ⇒ Object (readonly)
Returns the value of attribute pause_refine_after_reset.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def pause_refine_after_reset @pause_refine_after_reset end |
#prune_opa ⇒ Object (readonly)
Returns the value of attribute prune_opa.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def prune_opa @prune_opa end |
#prune_scale2d ⇒ Object (readonly)
Returns the value of attribute prune_scale2d.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def prune_scale2d @prune_scale2d end |
#prune_scale3d ⇒ Object (readonly)
Returns the value of attribute prune_scale3d.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def prune_scale3d @prune_scale3d end |
#refine_every ⇒ Object (readonly)
Returns the value of attribute refine_every.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def refine_every @refine_every end |
#refine_scale2d_stop_iter ⇒ Object (readonly)
Returns the value of attribute refine_scale2d_stop_iter.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def refine_scale2d_stop_iter @refine_scale2d_stop_iter end |
#refine_start_iter ⇒ Object (readonly)
Returns the value of attribute refine_start_iter.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def refine_start_iter @refine_start_iter end |
#refine_stop_iter ⇒ Object (readonly)
Returns the value of attribute refine_stop_iter.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def refine_stop_iter @refine_stop_iter end |
#reset_every ⇒ Object (readonly)
Returns the value of attribute reset_every.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def reset_every @reset_every end |
#revised_opacity ⇒ Object (readonly)
Returns the value of attribute revised_opacity.
26 27 28 |
# File 'lib/gsplat/strategy/default.rb', line 26 def revised_opacity @revised_opacity end |
Instance Method Details
#initialize_state(scene_scale:) ⇒ Hash
Creates mutable gradient/radius statistics for a scene.
45 46 47 |
# File 'lib/gsplat/strategy/default.rb', line 45 def initialize_state(scene_scale:) super.merge(grad2d: nil, count: nil, radii: nil) end |
#refinement_masks(params, state) ⇒ Object
rubocop:disable Metrics/AbcSize
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gsplat/strategy/default.rb', line 61 def refinement_masks(params, state) count = params.fetch(:means).data.shape[0] average = params.fetch(:means).data.class.zeros(count) observed = state[:count].gt(0) average[observed] = state[:grad2d][observed] / state[:count][observed] if observed.any? high = average.gt(grow_grad2d) max_scale = Numo::NMath.exp(params.fetch(:scales).data).max(axis: 1) small = max_scale.le(grow_scale3d * state.fetch(:scene_scale)) small &= state[:radii].le(grow_scale2d) if refine_scale2d_stop_iter.positive? && state[:radii] [high & small, high & small.eq(0)] end |
#step_post_backward(params:, optimizers:, state:, step:, info:, **_options) ⇒ Object
rubocop:disable Metrics/ParameterLists
50 51 52 53 54 55 56 57 |
# File 'lib/gsplat/strategy/default.rb', line 50 def step_post_backward(params:, optimizers:, state:, step:, info:, **) check_sanity(params, optimizers) collect_statistics!(params, state, info) refine!(params, optimizers, state, step) if should_refine?(step) reset_due = step.positive? && (step % reset_every).zero? Ops.reset_opacity!(params, optimizers, maximum: 2 * prune_opa) if reset_due state end |