本文整理汇总了Python中keras.backend.normalize_data_format方法的典型用法代码示例。如果您正苦于以下问题:Python backend.normalize_data_format方法的具体用法?Python backend.normalize_data_format怎么用?Python backend.normalize_data_format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.backend
的用法示例。
在下文中一共展示了backend.normalize_data_format方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, upsampling=(2, 2), output_size=None, data_format=None, **kwargs):
super(BilinearUpsampling, self).__init__(**kwargs)
self.data_format = K.normalize_data_format(data_format)
self.input_spec = InputSpec(ndim=4)
if output_size:
self.output_size = conv_utils.normalize_tuple(
output_size, 2, 'output_size')
self.upsampling = None
else:
self.output_size = None
self.upsampling = conv_utils.normalize_tuple(
upsampling, 2, 'upsampling')
示例2: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, padding=1, data_format=None, **kwargs):
super(ChannelPadding, self).__init__(**kwargs)
self.padding = conv_utils.normalize_tuple(padding, 2, 'padding')
self.data_format = normalize_data_format(data_format)
self.input_spec = InputSpec(ndim=4)
示例3: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, scale_factor=2, data_format=None, **kwargs):
super(SubPixelUpscaling, self).__init__(**kwargs)
self.scale_factor = scale_factor
self.data_format = normalize_data_format(data_format)
示例4: normalize_data_format
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def normalize_data_format(value):
"""Checks that the value correspond to a valid data format.
Copy of the function in keras-team/keras because it's not public API.
# Arguments
value: String or None. `'channels_first'` or `'channels_last'`.
# Returns
A string, either `'channels_first'` or `'channels_last'`
# Example
```python
>>> from keras import backend as K
>>> K.normalize_data_format(None)
'channels_first'
>>> K.normalize_data_format('channels_last')
'channels_last'
```
# Raises
ValueError: if `value` or the global `data_format` invalid.
"""
if value is None:
value = K.image_data_format()
data_format = value.lower()
if data_format not in {'channels_first', 'channels_last'}:
raise ValueError('The `data_format` argument must be one of '
'"channels_first", "channels_last". Received: ' +
str(value))
return data_format
示例5: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, loss_function, lats, data_format='channels_last', weighting='cosine'):
"""
Initialize a weighted loss.
:param loss_function: method: Keras loss function to apply after the weighting
:param lats: ndarray: 1-dimensional array of latitude coordinates
:param data_format: Keras data_format ('channels_first' or 'channels_last')
:param weighting: str: type of weighting to apply. Options are:
cosine: weight by the cosine of the latitude (default)
midlatitude: weight by the cosine of the latitude but also apply a 25% reduction to the equator and boost
to the mid-latitudes
"""
self.loss_function = loss_function
self.lats = lats
self.data_format = K.normalize_data_format(data_format)
if weighting not in ['cosine', 'midlatitude']:
raise ValueError("'weighting' must be one of 'cosine' or 'midlatitude'")
self.weighting = weighting
lat_tensor = K.zeros(lats.shape)
print(lats)
lat_tensor.assign(K.cast_to_floatx(lats[:]))
self.weights = K.cos(lat_tensor * np.pi / 180.)
if self.weighting == 'midlatitude':
self.weights = self.weights - 0.25 * K.sin(lat_tensor * 2 * np.pi / 180.)
self.is_init = False
self.__name__ = 'latitude_weighted_loss'
示例6: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, size=(2, 2), data_format=None, **kwargs):
super().__init__(**kwargs)
self.data_format = K.normalize_data_format(data_format)
self.size = conv_utils.normalize_tuple(size, 2, "size")
示例7: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, ch_j, n_j,
kernel_size=(3, 3),
strides=(1, 1),
r_num=1,
b_alphas=[8, 8, 8],
padding='same',
data_format='channels_last',
dilation_rate=(1, 1),
kernel_initializer='glorot_uniform',
bias_initializer='zeros',
kernel_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
**kwargs):
super(Conv2DCaps, self).__init__(**kwargs)
rank = 2
self.ch_j = ch_j # Number of capsules in layer J
self.n_j = n_j # Number of neurons in a capsule in J
self.kernel_size = conv_utils.normalize_tuple(kernel_size, rank, 'kernel_size')
self.strides = conv_utils.normalize_tuple(strides, rank, 'strides')
self.r_num = r_num
self.b_alphas = b_alphas
self.padding = conv_utils.normalize_padding(padding)
#self.data_format = conv_utils.normalize_data_format(data_format)
self.data_format = K.normalize_data_format(data_format)
self.dilation_rate = (1, 1)
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.input_spec = InputSpec(ndim=rank + 3)
示例8: __init__
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def __init__(self, rank,
filters,
kernel_size,
strides=1,
padding='valid',
data_format='channels_last',
dilation_rate=1,
activation=None,
use_bias=True,
normalize_weight=False,
kernel_initializer='quaternion',
bias_initializer='zeros',
gamma_diag_initializer=sqrt_init,
gamma_off_initializer='zeros',
kernel_regularizer=None,
bias_regularizer=None,
gamma_diag_regularizer=None,
gamma_off_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
gamma_diag_constraint=None,
gamma_off_constraint=None,
init_criterion='he',
seed=None,
spectral_parametrization=False,
epsilon=1e-7,
**kwargs):
super(QuaternionConv, self).__init__(**kwargs)
self.rank = rank
self.filters = filters
self.kernel_size = conv_utils.normalize_tuple(kernel_size, rank, 'kernel_size')
self.strides = conv_utils.normalize_tuple(strides, rank, 'strides')
self.padding = conv_utils.normalize_padding(padding)
self.data_format = K.normalize_data_format(data_format)
self.dilation_rate = conv_utils.normalize_tuple(dilation_rate, rank, 'dilation_rate')
self.activation = activations.get(activation)
self.use_bias = use_bias
self.normalize_weight = normalize_weight
self.init_criterion = init_criterion
self.spectral_parametrization = spectral_parametrization
self.epsilon = epsilon
self.kernel_initializer = sanitizedInitGet(kernel_initializer)
self.bias_initializer = sanitizedInitGet(bias_initializer)
self.gamma_diag_initializer = sanitizedInitGet(gamma_diag_initializer)
self.gamma_off_initializer = sanitizedInitGet(gamma_off_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.bias_regularizer = regularizers.get(bias_regularizer)
self.gamma_diag_regularizer = regularizers.get(gamma_diag_regularizer)
self.gamma_off_regularizer = regularizers.get(gamma_off_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.bias_constraint = constraints.get(bias_constraint)
self.gamma_diag_constraint = constraints.get(gamma_diag_constraint)
self.gamma_off_constraint = constraints.get(gamma_off_constraint)
if seed is None:
self.seed = np.random.randint(1, 10e6)
else:
self.seed = seed
self.input_spec = InputSpec(ndim=self.rank + 2)
开发者ID:Orkis-Research,项目名称:Quaternion-Convolutional-Neural-Networks-for-End-to-End-Automatic-Speech-Recognition,代码行数:62,代码来源:conv.py
示例9: row_conv2d
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import normalize_data_format [as 别名]
def row_conv2d(inputs, kernel, kernel_size, strides, output_shape, data_format=None):
"""Apply 2D conv with weights shared only along rows.
Adapted from K.local_conv2d by @jweyn
# Arguments
inputs: 4D tensor with shape:
(batch_size, filters, new_rows, new_cols)
if data_format='channels_first'
or 4D tensor with shape:
(batch_size, new_rows, new_cols, filters)
if data_format='channels_last'.
kernel: the row-shared weights for convolution,
with shape (output_rows, kernel_size, input_channels, filters)
kernel_size: a tuple of 2 integers, specifying the
width and height of the 2D convolution window.
strides: a tuple of 2 integers, specifying the strides
of the convolution along the width and height.
output_shape: a tuple with (output_row, output_col)
data_format: the data format, channels_first or channels_last
# Returns
A 4d tensor with shape:
(batch_size, filters, new_rows, new_cols)
if data_format='channels_first'
or 4D tensor with shape:
(batch_size, new_rows, new_cols, filters)
if data_format='channels_last'.
# Raises
ValueError: if `data_format` is neither
`channels_last` or `channels_first`.
"""
data_format = K.normalize_data_format(data_format)
stride_row, stride_col = strides
output_row, output_col = output_shape
out = []
for i in range(output_row):
# Slice the rows with the neighbors they need
slice_row = slice(i * stride_row, i * stride_col + kernel_size[0])
if data_format == 'channels_first':
x = inputs[:, :, slice_row, :] # batch, 16, 5, 144
else:
x = inputs[:, slice_row, :, :] # batch, 5, 144, 16
# Convolve, resulting in an array with only one row: batch, 1, 140, 6 or batch, 6, 1, 140
x = K.conv2d(x, kernel[i], strides=strides, padding='valid', data_format=data_format)
out.append(x)
if data_format == 'channels_first':
output = K.concatenate(out, axis=2)
else:
output = K.concatenate(out, axis=1)
del x
del out
return output