def __init__(self, num_fractal_blocks, fractal_block_depth,
base_layer_builder, mixer=None, drop_path=False,
p_local_drop_path=0.5, p_drop_base_case=0.25,
p_drop_recursive_case=0.25, name=None):
"""Initializes the FractalNet.
Args:
num_fractal_blocks: The number of fractal blocks the net is made from.
This variable is named `B` in the FractalNet paper. This argument uses
the word `block` in the sense that the FractalNet paper uses it.
fractal_block_depth: How deeply nested the blocks are. This variable is
`C-1` in the paper.
base_layer_builder: A callable that takes a name and returns a `Layer`
object. We would pass in a convolutional layer to reproduce the results
in the paper.
mixer: The join operation in the paper. Assumed to have two arguments.
Defaults to element-wise averaging. Mixing doesn't occur if either path
gets dropped.
drop_path: A boolean, whether or not to do drop-path. Defaults to False.
If selected, we do drop path as described in the paper (unless drop-path
choices is provided in which case how drop path is done can be further
customized by the user.
p_local_drop_path: A probability between 0.0 and 1.0. 0.0 means always do
global drop path. 1.0 means always do local drop path. Default: 0.5,
as in the paper.
p_drop_base_case: The probability, when doing local drop path, to drop the
base case.
p_drop_recursive_case: The probability, when doing local drop path, to
drop the recusrive case. (Requires: `p_drop_base_case +
p_drop_recursive_case < 1`)
name: An optional string name.
"""
self.set_constructor_args('td.FractalNet',
*get_local_arguments(FractalNet.__init__, True))
if mixer is None:
mixer = lambda a, b: tf.add(a, b)/2.0
self._num_fractal_blocks = num_fractal_blocks
self._fractal_block_depth = fractal_block_depth
self._mixer = mixer
self._drop_path = drop_path
self._p_local_drop_path = p_local_drop_path
self._p_drop_base_case = p_drop_base_case
self._p_drop_recursive_case = p_drop_recursive_case
self._drop_path_choices = None
super(FractalNet, self).__init__(name_or_scope=name)
self._children = {}
self._choice_id = {}
self._choices = []
with tf.variable_scope(self._vscope):
for block_idx in xrange(num_fractal_blocks):
for binary_seq in _binary_sequences_of_at_most(fractal_block_depth):
child_name = 'block_' + '_'.join(
[str(block_idx)] + [str(b) for b in binary_seq])
self._children[block_idx, binary_seq] = base_layer_builder(
name=child_name)
if len(binary_seq) < fractal_block_depth:
self._choice_id[(block_idx, binary_seq)] = len(self._choices)
self._choices.append((block_idx, binary_seq))
self._propagate_types()
评论列表
文章目录