本文整理汇总了Python中chainer.functions.maximum方法的典型用法代码示例。如果您正苦于以下问题:Python functions.maximum方法的具体用法?Python functions.maximum怎么用?Python functions.maximum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer.functions
的用法示例。
在下文中一共展示了functions.maximum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def __call__(self, *xs):
operation = self.operation
if operation == 0: # PROD
return six.moves.reduce(lambda x, y: x * y, xs),
elif operation == 1: # SUM
coeffs = self.coeffs
if coeffs is not None:
assert len(xs) == len(coeffs)
xs = [x * coeff for x, coeff in zip(xs, coeffs)]
return six.moves.reduce(lambda x, y: x + y, xs),
elif operation == 2: # MAX
return six.moves.reduce(lambda x, y: functions.maximum(x, y), xs),
else:
raise ValueError('Invalid EltwiseParameter.EltwiseOp value.')
示例2: calc_intersection
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def calc_intersection(self, top_left_x_1, width_1, top_left_x_2, width_2, top_left_y_1, height_1, top_left_y_2, height_2):
width_overlap = self.calc_overlap(
top_left_x_1,
width_1,
top_left_x_2,
width_2
)
height_overlap = self.calc_overlap(
top_left_y_1,
height_1,
top_left_y_2,
height_2
)
width_overlap = F.maximum(width_overlap, self.xp.zeros_like(width_overlap))
height_overlap = F.maximum(height_overlap, self.xp.zeros_like(height_overlap))
return width_overlap * height_overlap
示例3: get_aabb_corners
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def get_aabb_corners(grids, image_size):
_, _, height, width = grids.shape
grids = (grids + 1) / 2
x_points = grids[:, 0, ...] * image_size.width
y_points = grids[:, 1, ...] * image_size.height
x_points = F.clip(x_points, 0., float(image_size.width))
y_points = F.clip(y_points, 0., float(image_size.height))
top_left_x = F.get_item(x_points, [..., 0, 0])
top_left_y = F.get_item(y_points, [..., 0, 0])
top_right_x = F.get_item(x_points, [..., 0, width - 1])
top_right_y = F.get_item(y_points, [..., 0, width - 1])
bottom_right_x = F.get_item(x_points, [..., height - 1, width - 1])
bottom_right_y = F.get_item(y_points, [..., height - 1, width - 1])
bottom_left_x = F.get_item(x_points, [..., height - 1, 0])
bottom_left_y = F.get_item(y_points, [..., height - 1, 0])
top_left_x_aabb = F.minimum(top_left_x, bottom_left_x)
top_left_y_aabb = F.minimum(top_left_y, top_right_y)
bottom_right_x_aabb = F.maximum(top_right_x, bottom_right_x)
bottom_right_y_aabb = F.maximum(bottom_left_y, bottom_right_y)
return top_left_y_aabb, top_left_x_aabb, bottom_right_y_aabb, bottom_right_x_aabb
示例4: calc_loss
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def calc_loss(self, grids, image_size, **kwargs):
normalize = kwargs.get('normalize', True)
top_left_x, top_right_x, _, _, top_left_y, _, bottom_left_y, _ = self.get_corners(grids, image_size)
# penalize upside down images
distance = top_left_y - bottom_left_y
up_down_loss = F.maximum(distance, self.xp.zeros_like(distance.array))
if normalize:
up_down_loss = F.sum(up_down_loss)
# penalize images that are vertically mirrored
distance = top_left_x - top_right_x
left_right_loss = F.maximum(distance, self.xp.zeros_like(distance.array))
if normalize:
left_right_loss = F.sum(left_right_loss)
return up_down_loss + left_right_loss
示例5: random_hsv_image
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def random_hsv_image(bgr_image, delta_hue, delta_sat_scale, delta_val_scale):
hsv_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2HSV).astype(np.float32)
# hue
hsv_image[:, :, 0] += int((np.random.rand() * delta_hue * 2 - delta_hue) * 255)
# sat
sat_scale = 1 + np.random.rand() * delta_sat_scale * 2 - delta_sat_scale
hsv_image[:, :, 1] *= sat_scale
# val
val_scale = 1 + np.random.rand() * delta_val_scale * 2 - delta_val_scale
hsv_image[:, :, 2] *= val_scale
hsv_image[hsv_image < 0] = 0
hsv_image[hsv_image > 255] = 255
hsv_image = hsv_image.astype(np.uint8)
bgr_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR)
return bgr_image
# non maximum suppression
示例6: reshape_to_yolo_size
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def reshape_to_yolo_size(img):
input_height, input_width, _ = img.shape
min_pixel = 320
#max_pixel = 608
max_pixel = 448
min_edge = np.minimum(input_width, input_height)
if min_edge < min_pixel:
input_width *= min_pixel / min_edge
input_height *= min_pixel / min_edge
max_edge = np.maximum(input_width, input_height)
if max_edge > max_pixel:
input_width *= max_pixel / max_edge
input_height *= max_pixel / max_edge
input_width = int(input_width / 32 + round(input_width % 32 / 32)) * 32
input_height = int(input_height / 32 + round(input_height % 32 / 32)) * 32
img = cv2.resize(img, (input_width, input_height))
return img
示例7: __call__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def __call__(self, *xs):
operation = self.operation
if operation == 0: # PROD
return six.moves.reduce(lambda x, y: x * y, xs),
elif operation == 1: # SUM
coeffs = self.coeffs
if coeffs is not None:
assert len(xs) == len(coeffs)
xs = [x * coeff for x, coeff in zip(xs, coeffs)]
return six.moves.reduce(lambda x, y: x + y, xs),
elif operation == 2: # MAX
return six.moves.reduce(lambda x, y: functions.maximum(x, y), xs),
else:
raise ValueError('Invalid EltwiseParameter.EltwiseOp value.')
示例8: clip_actions
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def clip_actions(actions, min_action, max_action):
min_actions = F.broadcast_to(min_action, actions.shape)
max_actions = F.broadcast_to(max_action, actions.shape)
return F.maximum(F.minimum(actions, max_actions), min_actions)
示例9: greedy_actions
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def greedy_actions(self):
with chainer.force_backprop_mode():
a = self.mu
if self.min_action is not None:
a = F.maximum(
self.xp.broadcast_to(self.min_action, a.array.shape), a)
if self.max_action is not None:
a = F.minimum(
self.xp.broadcast_to(self.max_action, a.array.shape), a)
return a
示例10: forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def forward(self, v1,v2):
return F.maximum(v1, v2)
示例11: forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def forward(self, inputs, devices):
x1, x2 = inputs
return functions.maximum(x1, x2),
示例12: forward_expected
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def forward_expected(self, inputs):
x1, x2 = inputs
expected = numpy.maximum(x1, x2)
expected = numpy.asarray(expected)
return expected,
示例13: test_maximum_inconsistent_shapes
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def test_maximum_inconsistent_shapes(self):
x1_data = numpy.random.uniform(-1, 1, (3, 2)).astype(self.dtype)
x2_data = numpy.random.uniform(-1, 1, (2, 3)).astype(self.dtype)
x1 = chainer.Variable(x1_data)
x2 = chainer.Variable(x2_data)
with self.assertRaises(type_check.InvalidType):
functions.maximum(x1, x2)
示例14: calc_direction_loss
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def calc_direction_loss(self, grids):
top_left_x, top_right_x, _, top_left_y, _, bottom_left_y = self.get_corners(grids)
# penalize upside down images
distance = top_left_y - bottom_left_y
loss_values = F.maximum(distance, self.xp.zeros_like(distance))
up_down_loss = F.average(loss_values)
# penalize images that are vertically mirrored
distance = top_left_x - top_right_x
loss_values = F.maximum(distance, self.xp.zeros_like(distance))
left_right_loss = F.average(loss_values)
return up_down_loss + left_right_loss
示例15: calc_overlap
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import maximum [as 别名]
def calc_overlap(self, left_1, width_1, left_2, width_2):
radius_1 = width_1 / 2
center_1 = left_1 + radius_1
radius_2 = width_2 / 2
center_2 = left_2 + radius_2
center_distance = center_2 - center_1
center_distance = F.maximum(center_distance, center_distance * -1)
min_distance_for_no_overlap = radius_1 + radius_2
return min_distance_for_no_overlap - center_distance