当前位置: 首页>>代码示例>>Python>>正文


Python topology.InputSpec方法代码示例

本文整理汇总了Python中keras.engine.topology.InputSpec方法的典型用法代码示例。如果您正苦于以下问题:Python topology.InputSpec方法的具体用法?Python topology.InputSpec怎么用?Python topology.InputSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.engine.topology的用法示例。


在下文中一共展示了topology.InputSpec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def __init__(self, feature_num,
    			feature_size,
                 embedding_size,
                 output_dim=1,
                 activation=None,
                 **kwargs):
        if 'input_shape' not in kwargs and 'input_dim' in kwargs:
            kwargs['input_shape'] = (kwargs.pop('input_dim'),)
        super(FMLayer, self).__init__(**kwargs)

        self.output_dim = output_dim
        self.embedding_size = embedding_size
        self.activation = activations.get(activation)
        self.input_spec = InputSpec(ndim=2)
        self.feature_num = feature_num
        self.feature_size = feature_size 
开发者ID:DominickZhang,项目名称:KDDCup2019_admin,代码行数:18,代码来源:fm_keras.py

示例2: __init__

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def __init__(self, size=(1, 1), target_size=None, data_format='default', **kwargs):
        """Init.
            size: factor to original shape (ie. original-> size * original).
            target size: target size (ie. original->target).
        """
        if data_format == 'default':
            data_format = K.image_data_format()
        self.size = tuple(size)

        if target_size is not None:
            self.target_size = tuple(target_size)
        else:
            self.target_size = None
        assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {tf, th}'

        self.data_format = data_format
        self.input_spec = [InputSpec(ndim=4)]

        super(BilinearUpSampling2D, self).__init__(**kwargs) 
开发者ID:xiaochus,项目名称:MobileNetV3,代码行数:21,代码来源:bilinear_upsampling.py

示例3: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        if len(input_shape) < 4:
            raise ValueError('Inputs to `SeparableConv2D` should have rank 4. '
                             'Received input shape:', str(input_shape))
        if self.data_format == 'channels_first':
            channel_axis = 1
        else:
            channel_axis = 3
        if input_shape[channel_axis] is None:
            raise ValueError('The channel dimension of the inputs to '
                             '`SeparableConv2D` '
                             'should be defined. Found `None`.')
        input_dim = int(input_shape[channel_axis])
        depthwise_kernel_shape = (self.kernel_size[0],
                                  self.kernel_size[1],
                                  input_dim,
                                  self.depth_multiplier)

        self.depthwise_kernel = self.add_weight(
            shape=depthwise_kernel_shape,
            initializer=self.depthwise_initializer,
            name='depthwise_kernel',
            regularizer=self.depthwise_regularizer,
            constraint=self.depthwise_constraint)

        if self.use_bias:
            self.bias = self.add_weight(shape=(self.filters,),
                                        initializer=self.bias_initializer,
                                        name='bias',
                                        regularizer=self.bias_regularizer,
                                        constraint=self.bias_constraint)
        else:
            self.bias = None
        # Set input spec.
        self.input_spec = InputSpec(ndim=4, axes={channel_axis: input_dim})
        self.built = True 
开发者ID:rcmalli,项目名称:keras-mobilenet,代码行数:38,代码来源:depthwise_conv2d.py

示例4: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        assert len(input_shape) == 2
        input_dim = input_shape[1]
        numeric_size = input_dim - self.feature_num
        self.numeric_size = numeric_size
        all_size = numeric_size + self.feature_size

        self.input_spec = InputSpec(dtype=K.floatx(), shape=(None, input_dim))

        self.w_one_hot = self.add_weight(name='one_one_hot', 
                                 shape=(self.feature_size, self.output_dim),
                                 initializer='glorot_uniform',
                                 trainable=True)
        self.w_numeric = self.add_weight(name='one_numeric', 
                                 shape=(numeric_size, self.output_dim),
                                 initializer='glorot_uniform',
                                 trainable=True)
        self.v_one_hot = self.add_weight(name='two_one_hot', 
                                 shape=(self.feature_size, self.embedding_size),
                                 initializer='glorot_uniform',
                                 trainable=True)
        self.v_numeric = self.add_weight(name='two_numeric', 
                                 shape=(numeric_size, self.embedding_size),
                                 initializer='glorot_uniform',
                                 trainable=True)
        self.b = self.add_weight(name='bias', 
                                 shape=(self.output_dim,),
                                 initializer='zeros',
                                 trainable=True)

        super(FMLayer, self).build(input_shape) 
开发者ID:DominickZhang,项目名称:KDDCup2019_admin,代码行数:33,代码来源:fm_keras.py

示例5: __init__

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def __init__(self, axis=0,
                 kernel_initializer='zeros',
                 kernel_constraint=None,
                 kernel_regularizer=None,
                 **kwargs):
        '''

        Parameters
        ----------
        axis : int
            Axis along which to perform the pooling. By default 0 (should be time).

        kernel_initializer: Initializer for the weights matrix

        kernel_regularizer: Regularizer function applied to the weights matrix

        kernel_constraint: Constraint function applied to the weights matrix
        kwargs
        '''

        if 'input_shape' not in kwargs and 'input_dim' in kwargs:
            kwargs['input_shape'] = (kwargs.pop('input_dim'), )

        super(AutoPool1D, self).__init__(**kwargs)

        self.axis = axis
        self.kernel_initializer = initializers.get(kernel_initializer)
        self.kernel_constraint = constraints.get(kernel_constraint)
        self.kernel_regularizer = regularizers.get(kernel_regularizer)
        self.input_spec = InputSpec(min_ndim=3)
        self.supports_masking = True 
开发者ID:marl,项目名称:autopool,代码行数:33,代码来源:autopool.py

示例6: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        assert len(input_shape) >= 3
        input_dim = input_shape[-1]

        self.kernel = self.add_weight(shape=(1, input_dim),
                                      initializer=self.kernel_initializer,
                                      name='kernel',
                                      regularizer=self.kernel_regularizer,
                                      constraint=self.kernel_constraint)
        self.input_spec = InputSpec(min_ndim=2, axes={-1: input_dim})
        self.built = True 
开发者ID:marl,项目名称:autopool,代码行数:13,代码来源:autopool.py

示例7: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        self.input_spec = [InputSpec(shape=input_shape)]
        gamma = self.gamma_init * np.ones((input_shape[self.axis],))
        self.gamma = K.variable(gamma, name='{}_gamma'.format(self.name))
        self.trainable_weights = [self.gamma]
        super(L2Normalization, self).build(input_shape) 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:8,代码来源:keras_layer_L2Normalization.py

示例8: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        self.input_spec = [InputSpec(shape=input_shape)]
        super(DecodeDetectionsFast, self).build(input_shape) 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:5,代码来源:keras_layer_DecodeDetectionsFast.py

示例9: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        self.input_spec = [InputSpec(shape=input_shape)]
        super(DecodeDetections, self).build(input_shape) 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:5,代码来源:keras_layer_DecodeDetections.py

示例10: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        self.input_spec = [InputSpec(shape=input_shape)]
        super(AnchorBoxes, self).build(input_shape) 
开发者ID:advboxes,项目名称:perceptron-benchmark,代码行数:5,代码来源:keras_layer_AnchorBoxes.py

示例11: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        self.input_spec = [InputSpec(shape=input_shape)]
        gamma = self.gamma_init * np.ones((input_shape[self.axis],))
        self.gamma = K.variable(gamma, name="{}_gamma".format(self.name))
        self.trainable_weights = [self.gamma]
        super(L2Normalization, self).build(input_shape) 
开发者ID:liuguiyangnwpu,项目名称:DL.EyeSight,代码行数:8,代码来源:normalization.py

示例12: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        self.input_spec = [InputSpec(shape=input_shape)]
        shape = (input_shape[self.axis],)
        init_gamma = self.scale * np.ones(shape)
        self.gamma = K.variable(init_gamma, name=self.name+'_gamma')
        self.trainable_weights = [self.gamma] 
开发者ID:mogoweb,项目名称:aiexamples,代码行数:8,代码来源:ssd_layers.py

示例13: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        bs, input_length, input_dim = input_shape

        self.controller_input_dim, self.controller_output_dim = controller_input_output_shape(
                input_dim, self.units, self.m_depth, self.n_slots, self.shift_range, self.read_heads,
                self.write_heads)
            
        # Now that we've calculated the shape of the controller, we have add it to the layer/model.
        if self.controller is None:
            self.controller = Dense(
                name = "controller",
                activation = 'linear',
                bias_initializer = 'zeros',
                units = self.controller_output_dim,
                input_shape = (bs, input_length, self.controller_input_dim))
            self.controller.build(input_shape=(self.batch_size, input_length, self.controller_input_dim))
            self.controller_with_state = False


        # This is a fixed shift matrix
        self.C = _circulant(self.n_slots, self.shift_range)

        self.trainable_weights = self.controller.trainable_weights 

        # We need to declare the number of states we want to carry around.
        # In our case the dimension seems to be 6 (LSTM) or 5 (GRU) or 4 (FF),
        # see self.get_initial_states, those respond to:
        # [old_ntm_output] + [init_M, init_wr, init_ww] +  [init_h] (LSMT and GRU) + [(init_c] (LSTM only))
        # old_ntm_output does not make sense in our world, but is required by the definition of the step function we
        # intend to use.
        # WARNING: What self.state_spec does is only poorly understood,
        # I only copied it from keras/recurrent.py.
        self.states = [None, None, None, None]
        self.state_spec = [InputSpec(shape=(None, self.output_dim)),                            # old_ntm_output
                            InputSpec(shape=(None, self.n_slots, self.m_depth)),                # Memory
                            InputSpec(shape=(None, self.read_heads, self.n_slots)),   # weights_read
                            InputSpec(shape=(None, self.write_heads, self.n_slots))]  # weights_write

        super(NeuralTuringMachine, self).build(input_shape) 
开发者ID:flomlo,项目名称:ntm_keras,代码行数:41,代码来源:ntm.py

示例14: __init__

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def __init__(self, n_clusters, weights=None, alpha=1.0, **kwargs):
        if 'input_shape' not in kwargs and 'input_dim' in kwargs:
            kwargs['input_shape'] = (kwargs.pop('input_dim'),)
        super(ClusteringLayer, self).__init__(**kwargs)
        self.n_clusters = n_clusters
        self.alpha = alpha
        self.initial_weights = weights
        self.input_spec = InputSpec(ndim=2) 
开发者ID:XifengGuo,项目名称:DEC-keras,代码行数:10,代码来源:DEC.py

示例15: build

# 需要导入模块: from keras.engine import topology [as 别名]
# 或者: from keras.engine.topology import InputSpec [as 别名]
def build(self, input_shape):
        assert len(input_shape) == 2
        input_dim = input_shape[1]
        self.input_spec = InputSpec(dtype=K.floatx(), shape=(None, input_dim))
        self.clusters = self.add_weight(shape=(self.n_clusters, input_dim), initializer='glorot_uniform', name='clusters')
        if self.initial_weights is not None:
            self.set_weights(self.initial_weights)
            del self.initial_weights
        self.built = True 
开发者ID:XifengGuo,项目名称:DEC-keras,代码行数:11,代码来源:DEC.py


注:本文中的keras.engine.topology.InputSpec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。