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 = 0.5) ⇒ Dropout
Returns a new instance of Dropout.
286
287
288
289
290
|
# File 'lib/dnn/core/layers.rb', line 286
def initialize(dropout_ratio = 0.5)
super()
@dropout_ratio = dropout_ratio
@mask = nil
end
|
Instance Attribute Details
#dropout_ratio ⇒ Object
Returns the value of attribute dropout_ratio.
280
281
282
|
# File 'lib/dnn/core/layers.rb', line 280
def dropout_ratio
@dropout_ratio
end
|
Class Method Details
.load_hash(hash) ⇒ Object
282
283
284
|
# File 'lib/dnn/core/layers.rb', line 282
def self.load_hash(hash)
self.new(hash[:dropout_ratio])
end
|
Instance Method Details
#backward(dout) ⇒ Object
302
303
304
305
|
# File 'lib/dnn/core/layers.rb', line 302
def backward(dout)
dout[@mask] = 0 if @model.training?
dout
end
|
#forward(x) ⇒ Object
292
293
294
295
296
297
298
299
300
|
# File 'lib/dnn/core/layers.rb', line 292
def forward(x)
if @model.training?
@mask = Xumo::SFloat.ones(*x.shape).rand < @dropout_ratio
x[@mask] = 0
else
x *= (1 - @dropout_ratio)
end
x
end
|
#to_hash ⇒ Object
307
308
309
|
# File 'lib/dnn/core/layers.rb', line 307
def to_hash
super({dropout_ratio: @dropout_ratio})
end
|