Class: Gsplat::Training::ImageFitter
- Inherits:
-
Object
- Object
- Gsplat::Training::ImageFitter
- Defined in:
- lib/gsplat/training/image_fitter.rb
Overview
A small self-consistency image fitting loop used by examples and E2E tests.
Defined Under Namespace
Classes: MeanSquaredError, Result
Instance Attribute Summary collapse
-
#dtype ⇒ Object
readonly
Returns the value of attribute dtype.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#learning_rate ⇒ Object
readonly
Returns the value of attribute learning_rate.
-
#n_gaussians ⇒ Object
readonly
Returns the value of attribute n_gaussians.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #fit(steps: 300) ⇒ Object
-
#initialize(width: 64, height: 64, n_gaussians: 2_000, learning_rate: 20.0, seed: 42, dtype: Numo::SFloat) ⇒ ImageFitter
constructor
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(width: 64, height: 64, n_gaussians: 2_000, learning_rate: 20.0, seed: 42, dtype: Numo::SFloat) ⇒ ImageFitter
rubocop:disable Metrics/ParameterLists
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gsplat/training/image_fitter.rb', line 33 def initialize(width: 64, height: 64, n_gaussians: 2_000, learning_rate: 20.0, seed: 42, dtype: Numo::SFloat) # rubocop:enable Metrics/ParameterLists @width = width @height = height @n_gaussians = n_gaussians @learning_rate = learning_rate @dtype = dtype @rng = Random.new(seed) build_scene end |
Instance Attribute Details
#dtype ⇒ Object (readonly)
Returns the value of attribute dtype.
30 31 32 |
# File 'lib/gsplat/training/image_fitter.rb', line 30 def dtype @dtype end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
30 31 32 |
# File 'lib/gsplat/training/image_fitter.rb', line 30 def height @height end |
#learning_rate ⇒ Object (readonly)
Returns the value of attribute learning_rate.
30 31 32 |
# File 'lib/gsplat/training/image_fitter.rb', line 30 def learning_rate @learning_rate end |
#n_gaussians ⇒ Object (readonly)
Returns the value of attribute n_gaussians.
30 31 32 |
# File 'lib/gsplat/training/image_fitter.rb', line 30 def n_gaussians @n_gaussians end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
30 31 32 |
# File 'lib/gsplat/training/image_fitter.rb', line 30 def width @width end |
Instance Method Details
#fit(steps: 300) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gsplat/training/image_fitter.rb', line 46 def fit(steps: 300) raise ArgumentError, "steps must be a positive integer" unless steps.is_a?(Integer) && steps.positive? target = render(@teacher_colors) colors = initial_colors history = [psnr(render(colors), target)] steps.times do variable = Autograd::Variable.new(colors, requires_grad: true) rendered = render(variable) MeanSquaredError.apply(rendered, target).backward colors = clipped(colors - (learning_rate * variable.grad), 0.0, 1.0) history << psnr(render(colors), target) end Result.new( initial_psnr: history.first, final_psnr: history.last, history: history.freeze, colors: colors, target: target ) end |