Caffe2 - Python API
A deep learning, cross platform ML framework
dropout.py
1 # Module caffe2.python.layers.dropout
2 from __future__ import absolute_import
3 from __future__ import division
4 from __future__ import print_function
5 from __future__ import unicode_literals
6 
7 from caffe2.python import schema
8 from caffe2.python.layers.layers import ModelLayer
9 
10 
12 
13  def __init__(
14  self,
15  model,
16  input_record,
17  name='dropout',
18  ratio=0.5,
19  dropout_for_eval=False,
20  **kwargs):
21 
22  super(Dropout, self).__init__(model, name, input_record, **kwargs)
23  assert isinstance(input_record, schema.Scalar), "Incorrect input type"
24  assert (ratio >= 0 and ratio < 1.0), \
25  "Expected 0 <= ratio < 1, but got ratio of %s" % ratio
26 
27  self.output_schema = input_record.clone_schema()
28  self.output_schema.set_value(self.get_next_blob_reference('output'))
29  self.dropout_for_eval = dropout_for_eval
30 
31  self.ratio = ratio
32 
33  def _add_ops(self, net, is_test):
34  input_blob = self.input_record.field_blobs()
35  output_blobs = self.output_schema.field_blobs() \
36  + [net.NextScopedBlob('d_mask')]
37 
38  net.Dropout(input_blob,
39  output_blobs,
40  ratio=self.ratio,
41  is_test=is_test)
42 
43  def add_train_ops(self, net):
44  self._add_ops(net, is_test=False)
45 
46  def add_eval_ops(self, net):
47  self._add_ops(net, is_test=(not self.dropout_for_eval))
48 
49  def add_ops(self, net):
50  self.add_eval_ops(net)
def get_next_blob_reference(self, name)
Definition: layers.py:349
def _add_ops(self, net, is_test)
Definition: dropout.py:33