本文整理汇总了Python中tensorflow.crop_and_resize方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.crop_and_resize方法的具体用法?Python tensorflow.crop_and_resize怎么用?Python tensorflow.crop_and_resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.crop_and_resize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reorder_projected_boxes
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import crop_and_resize [as 别名]
def reorder_projected_boxes(box_corners):
"""Helper function to reorder image corners.
This reorders the corners from [x1, y1, x2, y2] to
[y1, x1, y2, x2] which is required by the tf.crop_and_resize op.
Args:
box_corners: tensor image corners in the format
N x [x1, y1, x2, y2]
Returns:
box_corners_reordered: tensor image corners in the format
N x [y1, x1, y2, x2]
"""
boxes_reordered = tf.stack([box_corners[:, 1],
box_corners[:, 0],
box_corners[:, 3],
box_corners[:, 2]],
axis=1)
return boxes_reordered
示例2: _roi_crop
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import crop_and_resize [as 别名]
def _roi_crop(self, roi_proposals, conv_feature_map, im_shape):
# Get normalized bounding boxes.
bboxes = self._get_bboxes(roi_proposals, im_shape)
# Generate fake batch ids
bboxes_shape = tf.shape(bboxes)
batch_ids = tf.zeros((bboxes_shape[0], ), dtype=tf.int32)
# Apply crop and resize with extracting a crop double the desired size.
crops = tf.image.crop_and_resize(
conv_feature_map, bboxes, batch_ids,
[self._pooled_width * 2, self._pooled_height * 2], name="crops"
)
# Applies max pool with [2,2] kernel to reduce the crops to half the
# size, and thus having the desired output.
prediction_dict = {
'roi_pool': tf.nn.max_pool(
crops, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1],
padding=self._pooled_padding
),
}
if self._debug:
prediction_dict['bboxes'] = bboxes
prediction_dict['crops'] = crops
prediction_dict['batch_ids'] = batch_ids
prediction_dict['conv_feature_map'] = conv_feature_map
return prediction_dict