Python object_detection.anchor_generators.grid_anchor_generator.tile_anchors() Examples
The following are 3
code examples of object_detection.anchor_generators.grid_anchor_generator.tile_anchors().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
object_detection.anchor_generators.grid_anchor_generator
, or try the search function
.
Example #1
Source File: flexible_grid_anchor_generator.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 4 votes |
def _generate(self, feature_map_shape_list, im_height=1, im_width=1): """Generates a collection of bounding boxes to be used as anchors. Currently we require the input image shape to be statically defined. That is, im_height and im_width should be integers rather than tensors. Args: feature_map_shape_list: list of pairs of convnet layer resolutions in the format [(height_0, width_0), (height_1, width_1), ...]. For example, setting feature_map_shape_list=[(8, 8), (7, 7)] asks for anchors that correspond to an 8x8 layer followed by a 7x7 layer. im_height: the height of the image to generate the grid for. If both im_height and im_width are 1, anchors can only be generated in absolute coordinates. im_width: the width of the image to generate the grid for. If both im_height and im_width are 1, anchors can only be generated in absolute coordinates. Returns: boxes_list: a list of BoxLists each holding anchor boxes corresponding to the input feature map shapes. Raises: ValueError: if im_height and im_width are 1, but normalized coordinates were requested. """ anchor_grid_list = [] for (feat_shape, base_sizes, aspect_ratios, anchor_stride, anchor_offset ) in zip(feature_map_shape_list, self._base_sizes, self._aspect_ratios, self._anchor_strides, self._anchor_offsets): anchor_grid = grid_anchor_generator.tile_anchors( feat_shape[0], feat_shape[1], tf.cast(tf.convert_to_tensor(base_sizes), dtype=tf.float32), tf.cast(tf.convert_to_tensor(aspect_ratios), dtype=tf.float32), tf.constant([1.0, 1.0]), tf.cast(tf.convert_to_tensor(anchor_stride), dtype=tf.float32), tf.cast(tf.convert_to_tensor(anchor_offset), dtype=tf.float32)) num_anchors = anchor_grid.num_boxes_static() if num_anchors is None: num_anchors = anchor_grid.num_boxes() anchor_indices = tf.zeros([num_anchors]) anchor_grid.add_field('feature_map_index', anchor_indices) if self._normalize_coordinates: if im_height == 1 or im_width == 1: raise ValueError( 'Normalized coordinates were requested upon construction of the ' 'FlexibleGridAnchorGenerator, but a subsequent call to ' 'generate did not supply dimension information.') anchor_grid = box_list_ops.to_normalized_coordinates( anchor_grid, im_height, im_width, check_range=False) anchor_grid_list.append(anchor_grid) return anchor_grid_list
Example #2
Source File: flexible_grid_anchor_generator.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 4 votes |
def _generate(self, feature_map_shape_list, im_height=1, im_width=1): """Generates a collection of bounding boxes to be used as anchors. Currently we require the input image shape to be statically defined. That is, im_height and im_width should be integers rather than tensors. Args: feature_map_shape_list: list of pairs of convnet layer resolutions in the format [(height_0, width_0), (height_1, width_1), ...]. For example, setting feature_map_shape_list=[(8, 8), (7, 7)] asks for anchors that correspond to an 8x8 layer followed by a 7x7 layer. im_height: the height of the image to generate the grid for. If both im_height and im_width are 1, anchors can only be generated in absolute coordinates. im_width: the width of the image to generate the grid for. If both im_height and im_width are 1, anchors can only be generated in absolute coordinates. Returns: boxes_list: a list of BoxLists each holding anchor boxes corresponding to the input feature map shapes. Raises: ValueError: if im_height and im_width are 1, but normalized coordinates were requested. """ anchor_grid_list = [] for (feat_shape, base_sizes, aspect_ratios, anchor_stride, anchor_offset ) in zip(feature_map_shape_list, self._base_sizes, self._aspect_ratios, self._anchor_strides, self._anchor_offsets): anchor_grid = grid_anchor_generator.tile_anchors( feat_shape[0], feat_shape[1], tf.cast(tf.convert_to_tensor(base_sizes), dtype=tf.float32), tf.cast(tf.convert_to_tensor(aspect_ratios), dtype=tf.float32), tf.constant([1.0, 1.0]), tf.cast(tf.convert_to_tensor(anchor_stride), dtype=tf.float32), tf.cast(tf.convert_to_tensor(anchor_offset), dtype=tf.float32)) num_anchors = anchor_grid.num_boxes_static() if num_anchors is None: num_anchors = anchor_grid.num_boxes() anchor_indices = tf.zeros([num_anchors]) anchor_grid.add_field('feature_map_index', anchor_indices) if self._normalize_coordinates: if im_height == 1 or im_width == 1: raise ValueError( 'Normalized coordinates were requested upon construction of the ' 'FlexibleGridAnchorGenerator, but a subsequent call to ' 'generate did not supply dimension information.') anchor_grid = box_list_ops.to_normalized_coordinates( anchor_grid, im_height, im_width, check_range=False) anchor_grid_list.append(anchor_grid) return anchor_grid_list
Example #3
Source File: flexible_grid_anchor_generator.py From models with Apache License 2.0 | 4 votes |
def _generate(self, feature_map_shape_list, im_height=1, im_width=1): """Generates a collection of bounding boxes to be used as anchors. Currently we require the input image shape to be statically defined. That is, im_height and im_width should be integers rather than tensors. Args: feature_map_shape_list: list of pairs of convnet layer resolutions in the format [(height_0, width_0), (height_1, width_1), ...]. For example, setting feature_map_shape_list=[(8, 8), (7, 7)] asks for anchors that correspond to an 8x8 layer followed by a 7x7 layer. im_height: the height of the image to generate the grid for. If both im_height and im_width are 1, anchors can only be generated in absolute coordinates. im_width: the width of the image to generate the grid for. If both im_height and im_width are 1, anchors can only be generated in absolute coordinates. Returns: boxes_list: a list of BoxLists each holding anchor boxes corresponding to the input feature map shapes. Raises: ValueError: if im_height and im_width are 1, but normalized coordinates were requested. """ anchor_grid_list = [] for (feat_shape, base_sizes, aspect_ratios, anchor_stride, anchor_offset ) in zip(feature_map_shape_list, self._base_sizes, self._aspect_ratios, self._anchor_strides, self._anchor_offsets): anchor_grid = grid_anchor_generator.tile_anchors( feat_shape[0], feat_shape[1], tf.cast(tf.convert_to_tensor(base_sizes), dtype=tf.float32), tf.cast(tf.convert_to_tensor(aspect_ratios), dtype=tf.float32), tf.constant([1.0, 1.0]), tf.cast(tf.convert_to_tensor(anchor_stride), dtype=tf.float32), tf.cast(tf.convert_to_tensor(anchor_offset), dtype=tf.float32)) num_anchors = anchor_grid.num_boxes_static() if num_anchors is None: num_anchors = anchor_grid.num_boxes() anchor_indices = tf.zeros([num_anchors]) anchor_grid.add_field('feature_map_index', anchor_indices) if self._normalize_coordinates: if im_height == 1 or im_width == 1: raise ValueError( 'Normalized coordinates were requested upon construction of the ' 'FlexibleGridAnchorGenerator, but a subsequent call to ' 'generate did not supply dimension information.') anchor_grid = box_list_ops.to_normalized_coordinates( anchor_grid, im_height, im_width, check_range=False) anchor_grid_list.append(anchor_grid) return anchor_grid_list