예제 #1
0
 def bias_initializer(_, *args, **kwargs):
     return K.concatenate([
         self.bias_initializer((self.filters, ), *args,
                               **kwargs),
         initializers.Ones()((self.filters, ), *args, **kwargs),
         self.bias_initializer((self.filters * 2, ), *args,
                               **kwargs),
         initializers.Ones()((self.filters, ), *args, **kwargs),
         self.bias_initializer((self.filters * 2, ), *args,
                               **kwargs)
     ])
예제 #2
0
 def bias_initializer(_, *args, **kwargs):
     return array_ops.concat([
         self.bias_initializer((self.units * 5, ), *args, **kwargs),
         initializers.Ones()((self.units, ), *args, **kwargs),
         self.bias_initializer((self.units * 2, ), *args, **kwargs),
     ],
                             axis=0)
예제 #3
0
 def bias_initializer(shape, *args, **kwargs):
     return K.concatenate([
         self.bias_initializer((self.units, ), *args, **kwargs),
         initializers.Ones()((self.units, ), *args, **kwargs),
         self.bias_initializer((self.units * 2, ), *args,
                               **kwargs),
     ])
예제 #4
0
    def build(self, input_shape):
        if type(input_shape) is list:
            feature_shape = input_shape[0]
        else:
            feature_shape = input_shape

        self.kernel_shape = (*self.kernel_size, feature_shape[-1],
                             self.filters)
        self.kernel = self.add_weight(name='kernel',
                                      shape=self.kernel_shape,
                                      initializer=self.kernel_initializer,
                                      regularizer=self.kernel_regularizer,
                                      constraint=self.kernel_constraint,
                                      trainable=True,
                                      dtype=self.dtype)

        if self.weightnorm:
            self.wn_g = self.add_weight(name='wn_g',
                                        shape=(self.filters, ),
                                        initializer=initializers.Ones(),
                                        trainable=True,
                                        dtype=self.dtype)

        if self.use_bias:
            self.bias = self.add_weight(name='bias',
                                        shape=(self.filters, ),
                                        initializer=self.bias_initializer,
                                        regularizer=self.bias_regularizer,
                                        constraint=self.bias_constraint,
                                        trainable=True,
                                        dtype=self.dtype)
        else:
            self.bias = None

        super(Conv2D, self).build(input_shape)
예제 #5
0
 def cake_bias_initializer(_, *args, **kwargs):
     return K.concatenate([
         self.cake_bias_initializer((self.units, ), *args,
                                    **kwargs),
         initializers.Ones()((self.units, ), *args, **kwargs),
         self.cake_bias_initializer((self.units, ), *args,
                                    **kwargs),
     ])
예제 #6
0
 def build(self, input_shape):
     super(Conv2DWeightNorm, self).build(input_shape)
     self.wn_g = self.add_weight(name='wn_g',
                                 shape=(self.filters, ),
                                 dtype=self.dtype,
                                 initializer=initializers.Ones(),
                                 trainable=True)
     square_sum = K.sum(K.square(self.kernel), [0, 1, 2])
     self.kernel = self.kernel / K.sqrt(square_sum + self.eps) * self.wn_g
예제 #7
0
 def sub_bias_initializer(_, *args, **kwagrs):
     return K.concatenate([
         self.sub_bias_initializer((self.sub_units, ), *args,
                                   **kwagrs),
         initializers.Ones()((self.sub_units, ), *args,
                             **kwagrs),
         self.sub_bias_initializer((self.sub_units * 2, ),
                                   *args, **kwagrs),
     ])
예제 #8
0
 def build(self, input_shape):
     self.gamma = self.add_weight(name='gamma',
                                  shape=input_shape[-1:],
                                  initializer=initializers.Ones(),
                                  trainable=True)
     self.beta = self.add_weight(name='beta',
                                 shape=input_shape[-1:],
                                 initializer=initializers.Zeros(),
                                 trainable=True)
     super(LayerNormalization, self).build(input_shape)
예제 #9
0
 def bias_initializer(_, *args, **kwargs):
     # Forget gate is the second slice.
     init = K.concatenate([
         self._bias_initializer(
             (1, self.num_units), *args, **kwargs),
         initializers.Ones()((1, self.num_units), *args, **kwargs),
         self._bias_initializer(
             (2, self.num_units), *args, **kwargs),
     ],
                          axis=0)
     return array_ops.reshape(init, self.canonical_bias_shapes)
예제 #10
0
    def build(self, input_shape, key_size, last_dim):
        dtype = dtypes.as_dtype(self.dtype or K.floatx())
        if not (dtype.is_floating or dtype.is_complex):
            raise TypeError('Unable to build `PolymorphicDenseBase` layer with non-floating point '
                            'dtype %s' % (dtype,))
        input_shape = tensor_shape.TensorShape(input_shape)
        if tensor_shape.dimension_value(input_shape[-1]) is None:
            raise ValueError('The last dimension of the inputs to `PolymorphicDenseBase` '
                             'should be defined. Found `None`.')

        # Scalar that defines distance sensitivity when key is compared with
        # keys map
        self.similarity_sensitivity = self.add_weight(
            'similarity_sensitivity',
            shape=[self.modes],
            initializer=initializers.Ones(),
            regularizer=self.kernel_regularizer,
            dtype=self.dtype,
            trainable=True)

        # Keys map that is compared with generated keys 
        self.keys_map = self.add_weight(
            'keys_map',
            shape=[self.modes, key_size],
            initializer=self.kernel_initializer,
            regularizer=self.kernel_regularizer,
            constraint=self.kernel_constraint,
            dtype=self.dtype,
            trainable=True)

        # Inputs processing weights map
        self.kernels = self.add_weight(
            'kernels',
            shape=[self.modes, last_dim, self.units],
            initializer=self.kernel_initializer,
            regularizer=self.kernel_regularizer,
            constraint=self.kernel_constraint,
            dtype=self.dtype,
            trainable=True)

        if self.use_bias:
            # Inputs processing biases map
            self.biases = self.add_weight(
                'biases',
                shape=[self.modes, self.units],
                initializer=self.bias_initializer,
                regularizer=self.bias_regularizer,
                constraint=self.bias_constraint,
                dtype=self.dtype,
                trainable=True)
        else:
            self.biases = None
        super(PolymorphicDenseBase, self).build(input_shape)
예제 #11
0
 def __init__(self,
              weights=None,
              axis=-1,
              beta_init='zero',
              gamma_init='one',
              momentum=0.9,
              **kwargs):
     print("--Scale--init", axis)
     # 参数**kwargs代表按字典方式继承父类
     self.momentum = momentum
     self.axis = axis
     self.beta_init = initializers.Zeros()
     self.gamma_init = initializers.Ones()
     self.initial_weights = weights
     super(Scale, self).__init__(**kwargs)