本文整理汇总了Python中keras.backend.min方法的典型用法代码示例。如果您正苦于以下问题:Python backend.min方法的具体用法?Python backend.min怎么用?Python backend.min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.backend
的用法示例。
在下文中一共展示了backend.min方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: yolo_correct_boxes
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def yolo_correct_boxes(box_xy, box_wh, input_shape, image_shape):
'''Get corrected boxes'''
box_yx = box_xy[..., ::-1]
box_hw = box_wh[..., ::-1]
input_shape = K.cast(input_shape, K.dtype(box_yx))
image_shape = K.cast(image_shape, K.dtype(box_yx))
new_shape = K.round(image_shape * K.min(input_shape/image_shape))
offset = (input_shape-new_shape)/2./input_shape
scale = input_shape/new_shape
box_yx = (box_yx - offset) * scale
box_hw *= scale
box_mins = box_yx - (box_hw / 2.)
box_maxes = box_yx + (box_hw / 2.)
boxes = K.concatenate([
box_mins[..., 0:1], # y_min
box_mins[..., 1:2], # x_min
box_maxes[..., 0:1], # y_max
box_maxes[..., 1:2] # x_max
])
# Scale boxes back to original image shape.
boxes *= K.concatenate([image_shape, image_shape])
return boxes
示例2: _correct_boxes
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def _correct_boxes(
self, box_xy, box_wh, input_shape, image_shape):
"""Get corrected boxes, which are scaled to original shape."""
box_yx = box_xy[..., ::-1]
box_hw = box_wh[..., ::-1]
input_shape = K.cast(input_shape, K.dtype(box_yx))
image_shape = K.cast(image_shape, K.dtype(box_yx))
new_shape = K.round(image_shape * K.min(input_shape / image_shape))
offset = (input_shape - new_shape) / 2. / input_shape
scale = input_shape / new_shape
box_yx = (box_yx - offset) * scale
box_hw *= scale
box_mins = box_yx - (box_hw / 2.)
box_maxes = box_yx + (box_hw / 2.)
boxes = K.concatenate([
box_mins[..., 0:1], # y_min
box_mins[..., 1:2], # x_min
box_maxes[..., 0:1], # y_max
box_maxes[..., 1:2] # x_max
])
# Scale boxes back to original image shape.
boxes *= K.concatenate([image_shape, image_shape])
return boxes
示例3: yolo_correct_boxes
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def yolo_correct_boxes(box_xy, box_wh, input_shape, image_shape):
box_yx = box_xy[..., ::-1]
box_hw = box_wh[..., ::-1]
input_shape = K.cast(input_shape, K.dtype(box_yx))
image_shape = K.cast(image_shape, K.dtype(box_yx))
new_shape = K.round(image_shape * K.min(input_shape/image_shape))
offset = (input_shape-new_shape)/2./input_shape
scale = input_shape/new_shape
box_yx = (box_yx - offset) * scale
box_hw *= scale
box_mins = box_yx - (box_hw / 2.)
box_maxes = box_yx + (box_hw / 2.)
boxes = K.concatenate([
box_mins[..., 0:1],
box_mins[..., 1:2],
box_maxes[..., 0:1],
box_maxes[..., 1:2]
])
boxes *= K.concatenate([image_shape, image_shape])
return boxes
示例4: correct_boxes
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def correct_boxes(box_xy, box_wh, input_shape, image_shape):
'''Get corrected boxes'''
box_yx = box_xy[..., ::-1]
box_hw = box_wh[..., ::-1]
input_shape = K.cast(input_shape, K.dtype(box_yx))
image_shape = K.cast(image_shape, K.dtype(box_yx))
new_shape = K.round(image_shape * K.min(input_shape / image_shape))
offset = (input_shape - new_shape) / 2. / input_shape
scale = input_shape / new_shape
box_yx = (box_yx - offset) * scale
box_hw *= scale
box_mins = box_yx - (box_hw / 2.)
box_maxes = box_yx + (box_hw / 2.)
boxes = K.concatenate([
box_mins[..., 0:1], # y_min
box_mins[..., 1:2], # x_min
box_maxes[..., 0:1], # y_max
box_maxes[..., 1:2] # x_max
])
# Scale boxes back to original image shape.
boxes *= K.concatenate([image_shape, image_shape])
return boxes
示例5: approximate_gaussian_ground_truth_image
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def approximate_gaussian_ground_truth_image(image_shape, center, grasp_theta, grasp_width, grasp_height, label, sigma_divisor=None):
""" Gaussian "ground truth" image approximation for a single proposed grasp at a time.
For use with the Cornell grasping dataset
see also: ground_truth_images() in cornell_grasp_dataset_writer.py
"""
if sigma_divisor is None:
sigma_divisor = FLAGS.sigma_divisor
grasp_dims = keras.backend.concatenate([grasp_width, grasp_height])
sigma = keras.backend.max(grasp_dims) / sigma_divisor
# make sure center value for gaussian is 0.5
gaussian = gaussian_kernel_2D(image_shape[:2], center=center, sigma=sigma)
# label 0 is grasp failure, label 1 is grasp success, label 0.5 will have "no effect".
# gaussian center with label 0 should be subtracting 0.5
# gaussian center with label 1 should be adding 0.5
gaussian = ((label * 2) - 1.0) * gaussian
max_num = K.max(K.max(gaussian), K.placeholder(1.0))
min_num = K.min(K.min(gaussian), K.placeholder(-1.0))
gaussian = (gaussian - min_num) / (max_num - min_num)
return gaussian
示例6: call
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def call(self, inputs):
"""This is where the layer's logic lives.
Parameters
----------
inputs: tensor
Input tensor, or list/tuple of input tensors
kwargs: dict
Additional keyword arguments
Returns
-------
tensor
A tensor or list/tuple of tensors
"""
if self.data_format == 'channels_last':
pooled = K.min(inputs, axis=[1, 2])
else:
pooled = K.min(inputs, axis=[2, 3])
return pooled
示例7: step
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def step(self, input_energy_t, states, return_logZ=True):
# not in the following `prev_target_val` has shape = (B, F)
# where B = batch_size, F = output feature dim
# Note: `i` is of float32, due to the behavior of `K.rnn`
prev_target_val, i, chain_energy = states[:3]
t = K.cast(i[0, 0], dtype='int32')
if len(states) > 3:
if K.backend() == 'theano':
m = states[3][:, t:(t + 2)]
else:
m = K.tf.slice(states[3], [0, t], [-1, 2])
input_energy_t = input_energy_t * K.expand_dims(m[:, 0])
chain_energy = chain_energy * K.expand_dims(K.expand_dims(m[:, 0] * m[:, 1])) # (1, F, F)*(B, 1, 1) -> (B, F, F)
if return_logZ:
energy = chain_energy + K.expand_dims(input_energy_t - prev_target_val, 2) # shapes: (1, B, F) + (B, F, 1) -> (B, F, F)
new_target_val = K.logsumexp(-energy, 1) # shapes: (B, F)
return new_target_val, [new_target_val, i + 1]
else:
energy = chain_energy + K.expand_dims(input_energy_t + prev_target_val, 2)
min_energy = K.min(energy, 1)
argmin_table = K.cast(K.argmin(energy, 1), K.floatx()) # cast for tf-version `K.rnn`
return argmin_table, [min_energy, i + 1]
示例8: ranking_loss_with_margin
# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import min [as 别名]
def ranking_loss_with_margin(y_pred, y_true):
"""
Using this loss trains the model to give scores to all correct elements in y_true that are
higher than all scores it gives to incorrect elements in y_true, plus a margin.
For example, let ``y_true = [0, 0, 1, 1, 0]``, and let ``y_pred = [-1, 1, 2, 0, -2]``. We will
find the lowest score assigned to correct elements in ``y_true`` (``0`` in this case), and the
highest score assigned to incorrect elements in ``y_true`` (``1`` in this case). We will then
compute a hinge loss given these values: ``K.maximum(0.0, 1 + 1 - 0)``.
Note that the way we do this uses ``K.max()`` and ``K.min()`` over the elements in ``y_true``,
which means that if you have a lot of values in here, you'll only get gradients backpropping
through two of them (the ones on the margin). This could be an inefficient use of your
computation time. Think carefully about the data that you're using with this loss function.
Because of the way masking works with Keras loss functions, also, you need to be sure that any
masked elements in ``y_pred`` have very negative values before they get passed into this loss
function.
"""
correct_elements = y_pred + (1.0 - y_true) * VERY_LARGE_NUMBER
lowest_scoring_correct = K.min(correct_elements, axis=-1)
incorrect_elements = y_pred + y_true * VERY_NEGATIVE_NUMBER
highest_scoring_incorrect = K.max(incorrect_elements, axis=-1)
return K.mean(K.maximum(0.0, 1.0 + highest_scoring_incorrect - lowest_scoring_correct))