本文整理汇总了Python中tensorflow.keras.backend.flatten方法的典型用法代码示例。如果您正苦于以下问题:Python backend.flatten方法的具体用法?Python backend.flatten怎么用?Python backend.flatten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.keras.backend
的用法示例。
在下文中一共展示了backend.flatten方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _rotation_matrix_zyz
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def _rotation_matrix_zyz(self, params):
phi = params[0] * 2 * np.pi - np.pi; theta = params[1] * 2 * np.pi - np.pi; psi_t = params[2] * 2 * np.pi - np.pi;
loc_r = params[3:6] * 2 - 1
a1 = self._rotation_matrix_axis(2, psi_t) # first rotate about z axis for angle psi_t
a2 = self._rotation_matrix_axis(1, theta)
a3 = self._rotation_matrix_axis(2, phi)
rm = K.dot(K.dot(a3,a2),a1)
rm = tf.transpose(rm)
c = K.dot(-rm, K.expand_dims(loc_r))
rm = K.flatten(rm)
theta = K.concatenate([rm[:3], c[0], rm[3:6], c[1], rm[6:9], c[2]])
return theta
示例2: _mask_rotation_matrix_zyz
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def _mask_rotation_matrix_zyz(self, params):
phi = params[0] * 2 * np.pi - np.pi; theta = params[1] * 2 * np.pi - np.pi; psi_t = params[2] * 2 * np.pi - np.pi;
loc_r = params[3:6] * 0 # magnitude of Fourier transformation is translation-invariant
a1 = self._rotation_matrix_axis(2, psi_t)
a2 = self._rotation_matrix_axis(1, theta)
a3 = self._rotation_matrix_axis(2, phi)
rm = K.dot(K.dot(a3,a2),a1)
rm = tf.transpose(rm)
c = K.dot(-rm, K.expand_dims(loc_r))
rm = K.flatten(rm)
theta = K.concatenate([rm[:3], c[0], rm[3:6], c[1], rm[6:9], c[2]])
return theta
示例3: flatten
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def flatten(v):
"""
flatten Tensor v
Parameters:
v: Tensor to be flattened
Returns:
flat Tensor
"""
return tf.reshape(v, [-1])
示例4: soft_l0_wrap
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def soft_l0_wrap(wt = 1.):
def soft_l0(x):
"""
maximize the number of 0 weights
"""
nb_weights = tf.cast(tf.size(x), tf.float32)
nb_zero_wts = tf.reduce_sum(soft_delta(K.flatten(x)))
return wt * (nb_weights - nb_zero_wts) / nb_weights
return soft_l0
示例5: iou
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def iou(y_true, y_pred, smooth=1.):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) - intersection + smooth)
示例6: iou_thresholded
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def iou_thresholded(y_true, y_pred, threshold=0.5, smooth=1.):
y_pred = threshold_binarize(y_pred, threshold)
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) - intersection + smooth)
示例7: dice_coef
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def dice_coef(y_true, y_pred, smooth=1.):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection + smooth) / (
K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
示例8: dice_coefficient
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def dice_coefficient(y_true, y_pred, smooth=0.00001):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection + smooth) / \
(K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
示例9: dice_coef_binary
# 需要导入模块: from tensorflow.keras import backend [as 别名]
# 或者: from tensorflow.keras.backend import flatten [as 别名]
def dice_coef_binary(y_true, y_pred, smooth=1e-7):
'''
Dice coefficient for 2 categories. Ignores background pixel label 0
Pass to model as metric during compile statement
'''
y_true_f = K.flatten(K.one_hot(K.cast(y_true, 'int32'),
num_classes=2)[..., 1:])
y_pred_f = K.flatten(y_pred[..., 1:])
intersect = K.sum(y_true_f * y_pred_f, axis=-1)
denom = K.sum(y_true_f + y_pred_f, axis=-1)
return K.mean((2. * intersect / (denom + smooth)))