Class: Torch::Optim::LRScheduler::MultiStepLR
- Inherits:
-
LRScheduler
- Object
- LRScheduler
- Torch::Optim::LRScheduler::MultiStepLR
- Defined in:
- lib/torch/optim/lr_scheduler/multi_step_lr.rb
Instance Method Summary collapse
- #get_lr ⇒ Object
-
#initialize(optimizer, milestones, gamma: 0.1, last_epoch: -1)) ⇒ MultiStepLR
constructor
A new instance of MultiStepLR.
Methods inherited from LRScheduler
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_lr ⇒ Object
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 |