本文整理匯總了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