MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / Dropout

Function Dropout

tensorpack/models/regularize.py:145–175  ·  view source on GitHub ↗

Same as `tf.layers.dropout`. However, for historical reasons, the first positional argument is interpreted as keep_prob rather than drop_prob. Explicitly use `rate=` keyword arguments to ensure things are consistent.

(x, *args, **kwargs)

Source from the content-addressed store, hash-verified

143
144@layer_register(use_scope=None)
145def Dropout(x, *args, **kwargs):
146 """
147 Same as `tf.layers.dropout`.
148 However, for historical reasons, the first positional argument is
149 interpreted as keep_prob rather than drop_prob.
150 Explicitly use `rate=` keyword arguments to ensure things are consistent.
151 """
152 if 'is_training' in kwargs:
153 kwargs['training'] = kwargs.pop('is_training')
154 if len(args) > 0:
155 if args[0] != 0.5:
156 logger.warn(
157 "The first positional argument to tensorpack.Dropout is the probability to keep, rather than to drop. "
158 "This is different from the rate argument in tf.layers.Dropout due to historical reasons. "
159 "To mimic tf.layers.Dropout, explicitly use keyword argument 'rate' instead")
160 rate = 1 - args[0]
161 elif 'keep_prob' in kwargs:
162 assert 'rate' not in kwargs, "Cannot set both keep_prob and rate!"
163 rate = 1 - kwargs.pop('keep_prob')
164 elif 'rate' in kwargs:
165 rate = kwargs.pop('rate')
166 else:
167 rate = 0.5
168
169 if kwargs.get('training', None) is None:
170 kwargs['training'] = get_current_tower_context().is_training
171
172 if get_tf_version_tuple() <= (1, 12):
173 return tf.layers.dropout(x, rate=rate, **kwargs)
174 else:
175 return tf.nn.dropout(x, rate=rate if kwargs['training'] else 0.)

Callers 3

build_graphMethod · 0.85
build_graphMethod · 0.85
get_logitsMethod · 0.85

Calls 3

get_tf_version_tupleFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected