Class: DNN::Layers::Dropout
- Inherits:
-
Layer
- Object
- Layer
- DNN::Layers::Dropout
show all
- Defined in:
- lib/dnn/core/layers.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Layer
#build, #built?, #prev_layer, #shape
Constructor Details
#initialize(dropout_ratio) ⇒ Dropout
Returns a new instance of Dropout.
493
494
495
496
497
|
# File 'lib/dnn/core/layers.rb', line 493
def initialize(dropout_ratio)
super()
@dropout_ratio = dropout_ratio
@mask = nil
end
|
Instance Attribute Details
#dropoit_ratio ⇒ Object
Returns the value of attribute dropoit_ratio.
491
492
493
|
# File 'lib/dnn/core/layers.rb', line 491
def dropoit_ratio
@dropoit_ratio
end
|
Class Method Details
.load(hash) ⇒ Object
503
504
505
|
# File 'lib/dnn/core/layers.rb', line 503
def self.load(hash)
self.new(hash[:dropout_ratio])
end
|
.load_hash(hash) ⇒ Object
499
500
501
|
# File 'lib/dnn/core/layers.rb', line 499
def self.load_hash(hash)
self.new(hash[:dropout_ratio])
end
|
Instance Method Details
#backward(dout) ⇒ Object
517
518
519
520
|
# File 'lib/dnn/core/layers.rb', line 517
def backward(dout)
dout[@mask] = 0 if @model.training?
dout
end
|
#forward(x) ⇒ Object
507
508
509
510
511
512
513
514
515
|
# File 'lib/dnn/core/layers.rb', line 507
def forward(x)
if @model.training?
@mask = SFloat.ones(*x.shape).rand < @dropout_ratio
x[@mask] = 0
else
x *= (1 - @dropout_ratio)
end
x
end
|
#to_hash ⇒ Object
522
523
524
|
# File 'lib/dnn/core/layers.rb', line 522
def to_hash
{name: self.class.name, dropout_ratio: @dropout_ratio}
end
|