Class: Torch::Optim::LRScheduler::MultiStepLR

Inherits:
LRScheduler
  • Object
show all
Defined in:
lib/torch/optim/lr_scheduler/multi_step_lr.rb

Instance Method Summary collapse

Methods inherited from LRScheduler

#step

Constructor Details

#initialize(optimizer, milestones, gamma: 0.1, last_epoch: -1)) ⇒ MultiStepLR

Returns a new instance of MultiStepLR.



5
6
7
8
9
# File 'lib/torch/optim/lr_scheduler/multi_step_lr.rb', line 5

def initialize(optimizer, milestones, gamma: 0.1, last_epoch: -1)
  @milestones = milestones.map.with_index.map { |v, i| [v, i + 1] }.to_h
  @gamma = gamma
  super(optimizer, last_epoch)
end

Instance Method Details

#get_lrObject



11
12
13
14
15
16
17
18
19
# File 'lib/torch/optim/lr_scheduler/multi_step_lr.rb', line 11

def get_lr
  if !@milestones.include?(@last_epoch)
    @optimizer.param_groups.map { |group| group[:lr] }
  else
    @optimizer.param_groups.map do |group|
      group[:lr] * @gamma ** @milestones[@last_epoch]
    end
  end
end