本文整理汇总了Python中keras.engine.InputSpec方法的典型用法代码示例。如果您正苦于以下问题:Python engine.InputSpec方法的具体用法?Python engine.InputSpec怎么用?Python engine.InputSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.engine
的用法示例。
在下文中一共展示了engine.InputSpec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def __init__(self, target_shape=None,factor=None, data_format=None, **kwargs):
# conmpute dataformat
if data_format is None:
data_format = K.image_data_format()
assert data_format in {
'channels_last', 'channels_first'}
self.data_format = data_format
self.input_spec = [InputSpec(ndim=4)]
self.target_shape = target_shape
self.factor = factor
if self.data_format == 'channels_first':
self.target_size = (target_shape[2], target_shape[3])
elif self.data_format == 'channels_last':
self.target_size = (target_shape[1], target_shape[2])
super(BilinearUpSampling2D, self).__init__(**kwargs)
示例2: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
self.input_spec = [InputSpec(shape=input_shape)]
self.input_dim = input_shape[2]
self.W = self.init((self.output_dim, 4 * self.input_dim),
name='{}_W'.format(self.name))
self.U = self.inner_init((self.input_dim, 4 * self.input_dim),
name='{}_U'.format(self.name))
self.b = K.variable(np.hstack((np.zeros(self.input_dim),
K.get_value(self.forget_bias_init((self.input_dim,))),
np.zeros(self.input_dim),
np.zeros(self.input_dim))),
name='{}_b'.format(self.name))
self.A = self.init((self.input_dim, self.output_dim),
name='{}_A'.format(self.name))
self.ba = K.zeros((self.output_dim,), name='{}_ba'.format(self.name))
self.trainable_weights = [self.W, self.U, self.b, self.A, self.ba]
if self.initial_weights is not None:
self.set_weights(self.initial_weights)
del self.initial_weights
示例3: __init__
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def __init__(self, init='glorot_uniform',
U_regularizer=None,
b_start_regularizer=None,
b_end_regularizer=None,
U_constraint=None,
b_start_constraint=None,
b_end_constraint=None,
weights=None,
**kwargs):
super(ChainCRF, self).__init__(**kwargs)
self.init = initializers.get(init)
self.U_regularizer = regularizers.get(U_regularizer)
self.b_start_regularizer = regularizers.get(b_start_regularizer)
self.b_end_regularizer = regularizers.get(b_end_regularizer)
self.U_constraint = constraints.get(U_constraint)
self.b_start_constraint = constraints.get(b_start_constraint)
self.b_end_constraint = constraints.get(b_end_constraint)
self.initial_weights = weights
self.supports_masking = True
self.uses_learning_phase = True
self.input_spec = [InputSpec(ndim=3)]
示例4: __init__
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def __init__(self, target_shape, offset=None, data_format=None,
**kwargs):
"""Crop to target.
If only one `offset` is set, then all dimensions are offset by this amount.
"""
super(CroppingLike2D, self).__init__(**kwargs)
self.data_format = conv_utils.normalize_data_format(data_format)
self.target_shape = target_shape
if offset is None or offset == 'centered':
self.offset = 'centered'
elif isinstance(offset, int):
self.offset = (offset, offset)
elif hasattr(offset, '__len__'):
if len(offset) != 2:
raise ValueError('`offset` should have two elements. '
'Found: ' + str(offset))
self.offset = offset
self.input_spec = InputSpec(ndim=4)
示例5: _layer_Affine
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def _layer_Affine(self):
self.add_body(0, '''
from keras.engine import Layer, InputSpec
from keras import initializers
from keras import backend as K
class Affine(Layer):
def __init__(self, scale, bias=None, **kwargs):
super(Affine, self).__init__(**kwargs)
self.gamma = scale
self.beta = bias
def call(self, inputs, training=None):
input_shape = K.int_shape(inputs)
# Prepare broadcasting shape.
return self.gamma * inputs + self.beta
def compute_output_shape(self, input_shape):
return input_shape
''')
示例6: __init__
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def __init__(self, init='glorot_uniform',
U_regularizer=None, b_start_regularizer=None, b_end_regularizer=None,
U_constraint=None, b_start_constraint=None, b_end_constraint=None,
weights=None,
**kwargs):
self.supports_masking = True
self.uses_learning_phase = True
self.input_spec = [InputSpec(ndim=3)]
self.init = initializations.get(init)
self.U_regularizer = regularizers.get(U_regularizer)
self.b_start_regularizer = regularizers.get(b_start_regularizer)
self.b_end_regularizer = regularizers.get(b_end_regularizer)
self.U_constraint = constraints.get(U_constraint)
self.b_start_constraint = constraints.get(b_start_constraint)
self.b_end_constraint = constraints.get(b_end_constraint)
self.initial_weights = weights
super(ChainCRF, self).__init__(**kwargs)
示例7: __init__
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def __init__(self, rank,
use_radius=False,
data_format=None,
**kwargs):
super(_CoordinateChannel, self).__init__(**kwargs)
if data_format not in [None, 'channels_first', 'channels_last']:
raise ValueError('`data_format` must be either "channels_last", "channels_first" '
'or None.')
self.rank = rank
self.use_radius = use_radius
self.data_format = K.image_data_format() if data_format is None else data_format
self.axis = 1 if K.image_data_format() == 'channels_first' else -1
self.input_spec = InputSpec(min_ndim=2)
self.supports_masking = True
示例8: __init__
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def __init__(self, padding=(1, 1), data_format=None, **kwargs):
super(ReflectionPadding2D, self).__init__(**kwargs)
self.data_format = conv_utils.normalize_data_format(data_format)
if isinstance(padding, int):
self.padding = ((padding, padding), (padding, padding))
elif hasattr(padding,"__len__"):
if len(padding) != 2:
raise ValueError('`padding` should have two elements. '
'Found: ' + str(padding))
height_padding = conv_utils.normalize_tuple(padding[0], 2, "1st entry of padding")
width_padding = conv_utils.normalize_tuple(padding[1], 2, "2nd entry of padding")
self.padding = (height_padding, width_padding)
else:
raise ValueError('`padding` should be either an int, '
'a tuple of 2 ints '
'(symmetric_height_pad, symmetric_width_pad), '
'or a tuple of 2 tuples of 2 ints '
'((top_pad, bottom_pad), (left_pad, right_pad)). '
'Found: ' + str(padding))
self.input_spec = InputSpec(ndim=4)
示例9: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
self.input_spec = [InputSpec(shape=input_shape)]
shape = (input_shape[self.axis],)
self.gamma = self.add_weight(shape,
initializer=self.gamma_init,
regularizer=self.gamma_regularizer,
name='{}_gamma'.format(self.name),
trainable=False)
self.beta = self.add_weight(shape,
initializer=self.beta_init,
regularizer=self.beta_regularizer,
name='{}_beta'.format(self.name),
trainable=False)
self.running_mean = self.add_weight(shape, initializer='zero',
name='{}_running_mean'.format(self.name),
trainable=False)
self.running_std = self.add_weight(shape, initializer='one',
name='{}_running_std'.format(self.name),
trainable=False)
if self.initial_weights is not None:
self.set_weights(self.initial_weights)
del self.initial_weights
self.built = True
示例10: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
self.input_spec = [InputSpec(ndim=3)]
assert len(input_shape) == 3
self.W = self.add_weight(shape=(input_shape[2], 1),
name='{}_W'.format(self.name),
initializer=self.init)
self.trainable_weights = [self.W]
super(AttentionWeightedAverage, self).build(input_shape)
示例11: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
output_shape = self.layer.get_output_shape_for(input_shape)
if output_shape != input_shape:
raise Exception('Cannot apply residual to layer "{}": '
'mismatching input and output shapes'
'input="{}" and output="{}"'
.format(self.layer.name, input_shape, output_shape))
if not self.layer.built:
self.layer.build(input_shape)
self.layer.built = True
self.input_spec = [InputSpec(shape=input_shape)]
super(Residual, self).build()
示例12: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
if len(input_shape) < 4:
raise ValueError('Inputs to `DepthwiseConv2D` 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 '
'`DepthwiseConv2D` '
'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=(input_dim * self.depth_multiplier,),
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
示例13: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
self.input_spec = [InputSpec(shape=input_shape)]
shape = (input_shape[self.axis],)
self.gamma = self.add_weight(shape,
initializer=self.gamma_init,
regularizer=self.gamma_regularizer,
name='{}_gamma'.format(self.name),
trainable=False)
self.beta = self.add_weight(shape,
initializer=self.beta_init,
regularizer=self.beta_regularizer,
name='{}_beta'.format(self.name),
trainable=False)
self.running_mean = self.add_weight(shape, initializer='zero',
name='{}_running_mean'.format(self.name),
trainable=False)
self.running_std = self.add_weight(shape, initializer='one',
name='{}_running_std'.format(self.name),
trainable=False)
if self.initial_weights is not None:
self.set_weights(self.initial_weights)
del self.initial_weights
self.built = True
示例14: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
self.input_spec = [InputSpec(shape=input_shape)]
shape = (int(input_shape[self.axis]),)
self.gamma = K.variable(self.gamma_init(shape), name='%s_gamma' % self.name)
self.beta = K.variable(self.beta_init(shape), name='%s_beta' % self.name)
self.trainable_weights = [self.gamma, self.beta]
if self.initial_weights is not None:
self.set_weights(self.initial_weights)
del self.initial_weights
示例15: build
# 需要导入模块: from keras import engine [as 别名]
# 或者: from keras.engine import InputSpec [as 别名]
def build(self, input_shape):
self.input_spec = [InputSpec(shape=input_shape)]
shape = (int(input_shape[self.axis]),)
# Compatibility with TensorFlow >= 1.0.0
self.gamma = K.variable(self.gamma_init(shape), name='{}_gamma'.format(self.name))
self.beta = K.variable(self.beta_init(shape), name='{}_beta'.format(self.name))
#self.gamma = self.gamma_init(shape, name='{}_gamma'.format(self.name))
#self.beta = self.beta_init(shape, name='{}_beta'.format(self.name))
self.trainable_weights = [self.gamma, self.beta]
if self.initial_weights is not None:
self.set_weights(self.initial_weights)
del self.initial_weights