Class: DNN::Layers::Dropout
- Inherits:
-
Layer
- Object
- Layer
- DNN::Layers::Dropout
show all
- Defined in:
- lib/dnn/core/layers.rb
Instance Method Summary
collapse
Methods inherited from Layer
#init, #prev_layer, #shape
Constructor Details
#initialize(dropout_ratio) ⇒ Dropout
313
314
315
316
|
# File 'lib/dnn/core/layers.rb', line 313
def initialize(dropout_ratio)
@dropout_ratio = dropout_ratio
@mask = nil
end
|
Instance Method Details
#backward(dout) ⇒ Object
328
329
330
331
|
# File 'lib/dnn/core/layers.rb', line 328
def backward(dout)
dout[@mask] = 0 if @model.training
dout
end
|
#forward(x) ⇒ Object
318
319
320
321
322
323
324
325
326
|
# File 'lib/dnn/core/layers.rb', line 318
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
|