Exemplo n.º 1
0
    def __init__(self,
                 depth,
                 filter_size,
                 hidden_filter_size,
                 strides,
                 padding,
                 bias=blocks_lstm.LSTMBiasInit,
                 initializer=block_util.RsqrtInitializer(dims=(0, 1, 2)),
                 name=None):
        super(RasterScanConv2DLSTM, self).__init__([None, None, depth], name)

        with self._BlockScope():
            self._input_conv = blocks_masked_conv2d.RasterScanConv2D(
                4 * depth,
                filter_size,
                strides,
                padding,
                strict_order=False,
                bias=None,
                act=None,
                initializer=initializer,
                name='input_conv2d')

            self._hidden_conv = blocks_std.Conv2D(4 * depth,
                                                  hidden_filter_size, [1, 1],
                                                  'SAME',
                                                  bias=None,
                                                  act=None,
                                                  initializer=initializer,
                                                  name='hidden_conv2d')

            if bias is not None:
                self._bias = blocks_std.BiasAdd(bias, name='biases')
            else:
                self._bias = blocks_std.PassThrough()
Exemplo n.º 2
0
    def __init__(self,
                 depth,
                 filter_size,
                 strides,
                 padding,
                 strict_order=True,
                 bias=None,
                 act=None,
                 initializer=None,
                 name=None):
        super(RasterScanConv2D, self).__init__(depth,
                                               filter_size,
                                               strides,
                                               padding,
                                               bias,
                                               act,
                                               name=name)

        if (filter_size[0] % 2) != 1 or (filter_size[1] % 2) != 1:
            raise ValueError('Kernel size should be odd.')

        with self._BlockScope():
            if initializer is None:
                initializer = block_util.RsqrtInitializer(dims=(0, 1, 2))
            self._initializer = initializer
            self._strict_order = strict_order
Exemplo n.º 3
0
    def __init__(self,
                 depth,
                 filter_size,
                 hidden_filter_size,
                 strides,
                 padding,
                 bias=LSTMBiasInit,
                 initializer=block_util.RsqrtInitializer(dims=(0, 1, 2)),
                 use_moving_average=False,
                 name=None):
        super(Conv2DLSTM, self).__init__([None, None, depth], name)
        self._iter = 0

        with self._BlockScope():
            self._input_conv = blocks_std.Conv2D(4 * depth,
                                                 filter_size,
                                                 strides,
                                                 padding,
                                                 bias=None,
                                                 act=None,
                                                 initializer=initializer,
                                                 name='input_conv2d')

            self._hidden_conv = blocks_std.Conv2D(4 * depth,
                                                  hidden_filter_size, [1, 1],
                                                  'SAME',
                                                  bias=None,
                                                  act=None,
                                                  initializer=initializer,
                                                  name='hidden_conv2d')

            if bias is not None:
                self._bias = blocks_std.BiasAdd(bias, name='biases')
            else:
                self._bias = blocks_std.PassThrough()
Exemplo n.º 4
0
    def __init__(self,
                 depth,
                 filter_size,
                 strides,
                 padding,
                 bias=None,
                 act=None,
                 initializer=None,
                 name=None):
        super(InFillingConv2D, self).__init__(depth,
                                              filter_size,
                                              strides,
                                              padding,
                                              bias,
                                              act,
                                              name=name)

        if (filter_size[0] % 2) != 1 or (filter_size[1] % 2) != 1:
            raise ValueError('Kernel size should be odd.')
        if filter_size[0] == 1 and filter_size[1] == 1:
            raise ValueError('Kernel size should be larger than 1x1.')

        with self._BlockScope():
            if initializer is None:
                initializer = block_util.RsqrtInitializer(dims=(0, 1, 2))
            self._initializer = initializer
Exemplo n.º 5
0
  def __init__(self, depth, filter_size, strides, padding,
               bias=None, act=None, initializer=None, name=None):
    """Initializes a Conv2D block.

    Arguments:
      depth: The output depth of the block (i.e., #filters)
      filter_size: The size of the 2D filter. If it's specified as an integer,
        it's going to create a square filter. Otherwise, this is a tuple
        specifying the height x width of the filter.
      strides: A tuple specifying the y and x stride.
      padding: One of the valid padding modes allowed by tf.nn.conv2d, or
        'REFLECT'/'SYMMETRIC' for mirror padding.
      bias: An initializer for the bias, or a Bias class object. If None, there
          will be no bias in this block. See BiasAdd block.
      act: Optional activation function applied to the output.
      initializer: Optional initializer for weights.
      name: The name for this conv2d op.
    """
    super(Conv2D, self).__init__(depth, filter_size, strides, padding, bias,
                                 act, conv=tf.nn.conv2d, name=name)

    with self._BlockScope():
      if initializer is None:
        initializer = block_util.RsqrtInitializer(dims=(0, 1, 2))
      self._initializer = initializer
Exemplo n.º 6
0
  def __init__(self,
               depth,
               bias=Bias(0),
               act=None,  # e.g., tf.nn.relu
               initializer=block_util.RsqrtInitializer(),
               linear_block_factory=(lambda d, i: Linear(d, initializer=i)),
               name=None):
    """Initializes NN block.

    Args:
      depth: The depth of the output.
      bias: An initializer for the bias, or a Bias class object. If None, there
        will be no bias term for this NN block. See BiasAdd block.
      act: Optional activation function. If None, no activation is applied.
      initializer: The initialization method for the matrix weights.
      linear_block_factory: A function used to create a linear block.
      name: The name of this block.
    """
    super(NN, self).__init__(name)

    with self._BlockScope():
      self._linear_block_factory = linear_block_factory
      self._depth = depth
      self._initializer = initializer
      self._matrices = None

      self._bias = BiasAdd(bias) if bias else PassThrough()
      self._act = act if act else PassThrough()
Exemplo n.º 7
0
  def __init__(self,
               depth,
               initializer=block_util.RsqrtInitializer(),
               name=None):
    super(Linear, self).__init__(depth, name)

    with self._BlockScope():
      self._initializer = initializer
  def __init__(self,
               depth,
               bias=LSTMBiasInit,
               initializer=block_util.RsqrtInitializer(),
               name=None):
    super(LSTM, self).__init__([depth], name)

    with self._BlockScope():
      self._depth = depth
      self._nn = blocks_std.NN(
          4 * depth, bias=bias, act=None, initializer=initializer)
      self._hidden_linear = blocks_std.Linear(
          4 * depth, initializer=initializer)
Exemplo n.º 9
0
    def __init__(self,
                 depth,
                 filter_size,
                 strides,
                 padding,
                 strict_order=True,
                 bias=None,
                 act=None,
                 initializer=None,
                 name=None):
        super(DepthOrderConv2D, self).__init__(depth,
                                               filter_size,
                                               strides,
                                               padding,
                                               bias,
                                               act,
                                               name=name)

        with self._BlockScope():
            if initializer is None:
                initializer = block_util.RsqrtInitializer(dims=(0, 1, 2))
            self._initializer = initializer
            self._strict_order = strict_order
Exemplo n.º 10
0
    def __init__(self,
                 depth,
                 filter_size,
                 strides,
                 padding,
                 strict_order=True,
                 input_group_size=1,
                 output_group_size=1,
                 bias=None,
                 act=None,
                 initializer=None,
                 name=None):
        super(GroupRasterScanConv2D, self).__init__(depth,
                                                    filter_size,
                                                    strides,
                                                    padding,
                                                    bias,
                                                    act,
                                                    name=name)

        if (filter_size[0] % 2) != 1 or (filter_size[1] % 2) != 1:
            raise ValueError('Kernel size should be odd.')

        with self._BlockScope():
            if initializer is None:
                initializer = block_util.RsqrtInitializer(dims=(0, 1, 2))
            self._initializer = initializer
            self._input_group_size = input_group_size
            self._output_group_size = output_group_size
            self._strict_order = strict_order

            if depth % self._output_group_size != 0:
                raise ValueError(
                    'Invalid depth group size: {} for depth {}'.format(
                        self._output_group_size, depth))
            self._output_group_count = depth // self._output_group_size