Python object_detection.core.target_assigner.batch_assign_targets() Examples
The following are 30
code examples of object_detection.core.target_assigner.batch_assign_targets().
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.core.target_assigner
, or try the search function
.
Example #1
Source File: ssd_meta_arch.py From moveo_ros with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #2
Source File: ssd_meta_arch.py From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #3
Source File: ssd_meta_arch.py From tensorflow with BSD 2-Clause "Simplified" License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #4
Source File: ssd_meta_arch.py From MBMD with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #5
Source File: ssd_meta_arch.py From HereIsWally with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #6
Source File: ssd_meta_arch.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #7
Source File: target_assigner_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_multi_class_target_assigner( num_classes=3) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #8
Source File: ssd_meta_arch.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #9
Source File: target_assigner_test.py From MAX-Object-Detector with Apache License 2.0 | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_cls_weights = [[[1, 1, 1, 1], [1, 1, 1, 1]]] exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #10
Source File: target_assigner_test.py From Accident-Detection-on-Indian-Roads with GNU Affero General Public License v3.0 | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #11
Source File: ssd_meta_arch.py From DOTA_models with Apache License 2.0 | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #12
Source File: target_assigner_test.py From vehicle_counting_tensorflow with MIT License | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_cls_weights = [[[1, 1, 1, 1], [1, 1, 1, 1]]] exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #13
Source File: ssd_meta_arch.py From hands-detection with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #14
Source File: target_assigner_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_cls_weights = [[[1, 1, 1, 1], [1, 1, 1, 1]]] exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #15
Source File: target_assigner_test.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #16
Source File: ssd_meta_arch.py From object_detector_app with MIT License | 5 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #17
Source File: target_assigner_test.py From models with Apache License 2.0 | 5 votes |
def test_batch_assign_empty_groundtruth(self): def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets): groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners) gt_box_batch = [groundtruth_boxlist] gt_class_targets_batch = [gt_class_targets] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets_batch, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_box_corners = np.zeros((0, 4), dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1]], dtype=np.float32) exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_cls_weights = [[[1, 1, 1, 1], [1, 1, 1, 1]]] exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_reg_weights = [[0, 0]] num_classes = 3 pad = 1 gt_class_targets = np.zeros((0, num_classes + pad), dtype=np.float32) (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_box_corners, gt_class_targets]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #18
Source File: target_assigner_test.py From Accident-Detection-on-Indian-Roads with GNU Affero General Public License v3.0 | 4 votes |
def test_batch_assign_multiclass_targets(self): def graph_fn(anchor_means, groundtruth_boxlist1, groundtruth_boxlist2, class_targets1, class_targets2): box_list1 = box_list.BoxList(groundtruth_boxlist1) box_list2 = box_list.BoxList(groundtruth_boxlist2) gt_box_batch = [box_list1, box_list2] gt_class_targets = [class_targets1, class_targets2] anchors_boxlist = box_list.BoxList(anchor_means) multiclass_target_assigner = self._get_target_assigner() num_classes = 3 unmatched_class_label = tf.constant([1] + num_classes * [0], tf.float32) (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( multiclass_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets, unmatched_class_label) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_boxlist1 = np.array([[0., 0., 0.2, 0.2]], dtype=np.float32) groundtruth_boxlist2 = np.array([[0, 0.25123152, 1, 1], [0.015789, 0.0985, 0.55789, 0.3842]], dtype=np.float32) class_targets1 = np.array([[0, 1, 0, 0]], dtype=np.float32) class_targets2 = np.array([[0, 0, 0, 1], [0, 0, 1, 0]], dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1], [0, .1, .5, .5], [.75, .75, 1, 1]], dtype=np.float32) exp_reg_targets = [[[0, 0, -0.5, -0.5], [0, 0, 0, 0], [0, 0, 0, 0,], [0, 0, 0, 0,],], [[0, 0, 0, 0,], [0, 0.01231521, 0, 0], [0.15789001, -0.01500003, 0.57889998, -1.15799987], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1, 1, 1], [1, 1, 1, 1]] exp_cls_targets = [[[0, 1, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]], [[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0]]] exp_reg_weights = [[1, 0, 0, 0], [0, 1, 1, 0]] (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute(graph_fn, [ anchor_means, groundtruth_boxlist1, groundtruth_boxlist2, class_targets1, class_targets2 ]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #19
Source File: faster_rcnn_meta_arch.py From g-tensorflow-models with Apache License 2.0 | 4 votes |
def _get_mask_proposal_boxes_and_classes( self, detection_boxes, num_detections, image_shape, groundtruth_boxlists, groundtruth_classes_with_background_list, groundtruth_weights_list): """Returns proposal boxes and class targets to compute evaluation mask loss. During evaluation, detection boxes are used to extract features for mask prediction. Therefore, to compute mask loss during evaluation detection boxes must be used to compute correct class and mask targets. This function returns boxes and classes in the correct format for computing mask targets during evaluation. Args: detection_boxes: A 3-D float tensor of shape [batch, max_detection_boxes, 4] containing detection boxes in normalized co-ordinates. num_detections: A 1-D float tensor of shape [batch] containing number of valid boxes in `detection_boxes`. image_shape: A 1-D tensor of shape [4] containing image tensor shape. groundtruth_boxlists: A list of groundtruth boxlists. groundtruth_classes_with_background_list: A list of groundtruth classes. groundtruth_weights_list: A list of groundtruth weights. Return: mask_proposal_boxes: detection boxes to use for mask proposals in absolute co-ordinates. mask_proposal_boxlists: `mask_proposal_boxes` in a list of BoxLists in absolute co-ordinates. mask_proposal_paddings_indicator: a tensor indicating valid boxes. mask_proposal_one_hot_flat_cls_targets_with_background: Class targets computed using detection boxes. """ batch, max_num_detections, _ = detection_boxes.shape.as_list() proposal_boxes = tf.reshape(box_list_ops.to_absolute_coordinates( box_list.BoxList(tf.reshape(detection_boxes, [-1, 4])), image_shape[1], image_shape[2]).get(), [batch, max_num_detections, 4]) proposal_boxlists = [ box_list.BoxList(detection_boxes_single_image) for detection_boxes_single_image in tf.unstack(proposal_boxes) ] paddings_indicator = self._padded_batched_proposals_indicator( tf.to_int32(num_detections), detection_boxes.shape[1]) (batch_cls_targets_with_background, _, _, _, _) = target_assigner.batch_assign_targets( target_assigner=self._detector_target_assigner, anchors_batch=proposal_boxlists, gt_box_batch=groundtruth_boxlists, gt_class_targets_batch=groundtruth_classes_with_background_list, unmatched_class_label=tf.constant( [1] + self._num_classes * [0], dtype=tf.float32), gt_weights_batch=groundtruth_weights_list) flat_cls_targets_with_background = tf.reshape( batch_cls_targets_with_background, [-1, self._num_classes + 1]) one_hot_flat_cls_targets_with_background = tf.argmax( flat_cls_targets_with_background, axis=1) one_hot_flat_cls_targets_with_background = tf.one_hot( one_hot_flat_cls_targets_with_background, flat_cls_targets_with_background.get_shape()[1]) return (proposal_boxes, proposal_boxlists, paddings_indicator, one_hot_flat_cls_targets_with_background)
Example #20
Source File: target_assigner_test.py From Accident-Detection-on-Indian-Roads with GNU Affero General Public License v3.0 | 4 votes |
def test_batch_assign_targets(self): def graph_fn(anchor_means, groundtruth_boxlist1, groundtruth_boxlist2): box_list1 = box_list.BoxList(groundtruth_boxlist1) box_list2 = box_list.BoxList(groundtruth_boxlist2) gt_box_batch = [box_list1, box_list2] gt_class_targets = [None, None] anchors_boxlist = box_list.BoxList(anchor_means) agnostic_target_assigner = self._get_target_assigner() (cls_targets, cls_weights, reg_targets, reg_weights, _) = targetassigner.batch_assign_targets( agnostic_target_assigner, anchors_boxlist, gt_box_batch, gt_class_targets) return (cls_targets, cls_weights, reg_targets, reg_weights) groundtruth_boxlist1 = np.array([[0., 0., 0.2, 0.2]], dtype=np.float32) groundtruth_boxlist2 = np.array([[0, 0.25123152, 1, 1], [0.015789, 0.0985, 0.55789, 0.3842]], dtype=np.float32) anchor_means = np.array([[0, 0, .25, .25], [0, .25, 1, 1], [0, .1, .5, .5], [.75, .75, 1, 1]], dtype=np.float32) exp_reg_targets = [[[0, 0, -0.5, -0.5], [0, 0, 0, 0], [0, 0, 0, 0,], [0, 0, 0, 0,],], [[0, 0, 0, 0,], [0, 0.01231521, 0, 0], [0.15789001, -0.01500003, 0.57889998, -1.15799987], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1, 1, 1], [1, 1, 1, 1]] exp_cls_targets = [[[1], [0], [0], [0]], [[0], [1], [1], [0]]] exp_reg_weights = [[1, 0, 0, 0], [0, 1, 1, 0]] (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out) = self.execute( graph_fn, [anchor_means, groundtruth_boxlist1, groundtruth_boxlist2]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights)
Example #21
Source File: ssd_meta_arch.py From object_detection_with_tensorflow with MIT License | 4 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list, groundtruth_keypoints_list=None): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. groundtruth_keypoints_list: (optional) a list of 3-D tensors of shape [num_boxes, num_keypoints, 2] Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] if groundtruth_keypoints_list is not None: for boxlist, keypoints in zip( groundtruth_boxlists, groundtruth_keypoints_list): boxlist.add_field(fields.BoxListFields.keypoints, keypoints) return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #22
Source File: ssd_meta_arch.py From Elphas with Apache License 2.0 | 4 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list, groundtruth_keypoints_list=None, groundtruth_weights_list=None): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. groundtruth_keypoints_list: (optional) a list of 3-D tensors of shape [num_boxes, num_keypoints, 2] groundtruth_weights_list: A list of 1-D tf.float32 tensors of shape [num_boxes] containing weights for groundtruth boxes. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxlists = [ box_list.BoxList(boxes) for boxes in groundtruth_boxes_list ] groundtruth_classes_with_background_list = [ tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT') for one_hot_encoding in groundtruth_classes_list ] if groundtruth_keypoints_list is not None: for boxlist, keypoints in zip( groundtruth_boxlists, groundtruth_keypoints_list): boxlist.add_field(fields.BoxListFields.keypoints, keypoints) return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list, groundtruth_weights_list)
Example #23
Source File: man_meta_arch.py From MBMD with MIT License | 4 votes |
def _assign_targets(self, groundtruth_boxes_list, groundtruth_classes_list): """Assign groundtruth targets. Adds a background class to each one-hot encoding of groundtruth classes and uses target assigner to obtain regression and classification targets. Args: groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4] containing coordinates of the groundtruth boxes. Groundtruth boxes are provided in [y_min, x_min, y_max, x_max] format and assumed to be normalized and clipped relative to the image window with y_min <= y_max and x_min <= x_max. groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of shape [num_boxes, num_classes] containing the class targets with the 0th index assumed to map to the first non-background class. Returns: batch_cls_targets: a tensor with shape [batch_size, num_anchors, num_classes], batch_cls_weights: a tensor with shape [batch_size, num_anchors], batch_reg_targets: a tensor with shape [batch_size, num_anchors, box_code_dimension] batch_reg_weights: a tensor with shape [batch_size, num_anchors], match_list: a list of matcher.Match objects encoding the match between anchors and groundtruth boxes for each image of the batch, with rows of the Match objects corresponding to groundtruth boxes and columns corresponding to anchors. """ groundtruth_boxes_list = tf.reshape(groundtruth_boxes_list, [self._batch_size*(self._seq_length), -1]) groundtruth_boxes_list = tf.unstack(groundtruth_boxes_list, axis=0) groundtruth_boxlists = [ box_list.BoxList(tf.expand_dims(boxes, axis=0)) for boxes in groundtruth_boxes_list ] groundtruth_classes_list = tf.reshape(groundtruth_classes_list, [self._batch_size*(self._seq_length), -1]) groundtruth_classes_list = tf.unstack(groundtruth_classes_list, axis=0) groundtruth_classes_with_background_list = [ tf.reshape(tf.one_hot(one_hot_encoding, self.num_classes+1), [1, self.num_classes+1]) for one_hot_encoding in groundtruth_classes_list ] return target_assigner.batch_assign_targets( self._target_assigner, self.anchors, groundtruth_boxlists, groundtruth_classes_with_background_list)
Example #24
Source File: target_assigner_test.py From MBMD with MIT License | 4 votes |
def test_batch_assign_empty_groundtruth(self): box_coords_expanded = tf.zeros((1, 4), tf.float32) box_coords = tf.slice(box_coords_expanded, [0, 0], [0, 4]) box_list1 = box_list.BoxList(box_coords) gt_box_batch = [box_list1] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] exp_match_0 = [] num_classes = 3 pad = 1 gt_class_targets = tf.zeros((0, num_classes + pad)) gt_class_targets_batch = [gt_class_targets] multiclass_target_assigner = self._get_multi_class_target_assigner( num_classes=3) (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( multiclass_target_assigner, priors, gt_box_batch, gt_class_targets_batch) self.assertTrue(isinstance(match_list, list) and len(match_list) == 1) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0)
Example #25
Source File: target_assigner_test.py From MBMD with MIT License | 4 votes |
def test_batch_assign_targets(self): box_list1 = box_list.BoxList(tf.constant([[0., 0., 0.2, 0.2]])) box_list2 = box_list.BoxList(tf.constant( [[0, 0.25123152, 1, 1], [0.015789, 0.0985, 0.55789, 0.3842]] )) gt_box_batch = [box_list1, box_list2] gt_class_targets = [None, None] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1], [0, .1, .5, .5], [.75, .75, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1], [.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, -0.5, -0.5], [0, 0, 0, 0], [0, 0, 0, 0,], [0, 0, 0, 0,],], [[0, 0, 0, 0,], [0, 0.01231521, 0, 0], [0.15789001, -0.01500003, 0.57889998, -1.15799987], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1, 1, 1], [1, 1, 1, 1]] exp_cls_targets = [[[1], [0], [0], [0]], [[0], [1], [1], [0]]] exp_reg_weights = [[1, 0, 0, 0], [0, 1, 1, 0]] exp_match_0 = [0] exp_match_1 = [1, 2] agnostic_target_assigner = self._get_agnostic_target_assigner() (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( agnostic_target_assigner, priors, gt_box_batch, gt_class_targets) self.assertTrue(isinstance(match_list, list) and len(match_list) == 2) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0, match_out_1) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0) self.assertAllClose(match_out_1, exp_match_1)
Example #26
Source File: target_assigner_test.py From object_detection_kitti with Apache License 2.0 | 4 votes |
def test_batch_assign_empty_groundtruth(self): box_coords_expanded = tf.zeros((1, 4), tf.float32) box_coords = tf.slice(box_coords_expanded, [0, 0], [0, 4]) box_list1 = box_list.BoxList(box_coords) gt_box_batch = [box_list1] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] exp_match_0 = [] num_classes = 3 pad = 1 gt_class_targets = tf.zeros((0, num_classes + pad)) gt_class_targets_batch = [gt_class_targets] multiclass_target_assigner = self._get_multi_class_target_assigner( num_classes=3) (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( multiclass_target_assigner, priors, gt_box_batch, gt_class_targets_batch) self.assertTrue(isinstance(match_list, list) and len(match_list) == 1) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0)
Example #27
Source File: target_assigner_test.py From object_detection_kitti with Apache License 2.0 | 4 votes |
def test_batch_assign_targets(self): box_list1 = box_list.BoxList(tf.constant([[0., 0., 0.2, 0.2]])) box_list2 = box_list.BoxList(tf.constant( [[0, 0.25123152, 1, 1], [0.015789, 0.0985, 0.55789, 0.3842]] )) gt_box_batch = [box_list1, box_list2] gt_class_targets = [None, None] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1], [0, .1, .5, .5], [.75, .75, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1], [.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, -0.5, -0.5], [0, 0, 0, 0], [0, 0, 0, 0,], [0, 0, 0, 0,],], [[0, 0, 0, 0,], [0, 0.01231521, 0, 0], [0.15789001, -0.01500003, 0.57889998, -1.15799987], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1, 1, 1], [1, 1, 1, 1]] exp_cls_targets = [[[1], [0], [0], [0]], [[0], [1], [1], [0]]] exp_reg_weights = [[1, 0, 0, 0], [0, 1, 1, 0]] exp_match_0 = [0] exp_match_1 = [1, 2] agnostic_target_assigner = self._get_agnostic_target_assigner() (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( agnostic_target_assigner, priors, gt_box_batch, gt_class_targets) self.assertTrue(isinstance(match_list, list) and len(match_list) == 2) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0, match_out_1) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0) self.assertAllClose(match_out_1, exp_match_1)
Example #28
Source File: target_assigner_test.py From moveo_ros with MIT License | 4 votes |
def test_batch_assign_empty_groundtruth(self): box_coords_expanded = tf.zeros((1, 4), tf.float32) box_coords = tf.slice(box_coords_expanded, [0, 0], [0, 4]) box_list1 = box_list.BoxList(box_coords) gt_box_batch = [box_list1] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] exp_match_0 = [] num_classes = 3 pad = 1 gt_class_targets = tf.zeros((0, num_classes + pad)) gt_class_targets_batch = [gt_class_targets] multiclass_target_assigner = self._get_multi_class_target_assigner( num_classes=3) (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( multiclass_target_assigner, priors, gt_box_batch, gt_class_targets_batch) self.assertTrue(isinstance(match_list, list) and len(match_list) == 1) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0)
Example #29
Source File: target_assigner_test.py From hands-detection with MIT License | 4 votes |
def test_batch_assign_empty_groundtruth(self): box_coords_expanded = tf.zeros((1, 4), tf.float32) box_coords = tf.slice(box_coords_expanded, [0, 0], [0, 4]) box_list1 = box_list.BoxList(box_coords) gt_box_batch = [box_list1] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, 0, 0], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1]] exp_cls_targets = [[[1, 0, 0, 0], [1, 0, 0, 0]]] exp_reg_weights = [[0, 0]] exp_match_0 = [] num_classes = 3 pad = 1 gt_class_targets = tf.zeros((0, num_classes + pad)) gt_class_targets_batch = [gt_class_targets] multiclass_target_assigner = self._get_multi_class_target_assigner( num_classes=3) (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( multiclass_target_assigner, priors, gt_box_batch, gt_class_targets_batch) self.assertTrue(isinstance(match_list, list) and len(match_list) == 1) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0)
Example #30
Source File: target_assigner_test.py From hands-detection with MIT License | 4 votes |
def test_batch_assign_targets(self): box_list1 = box_list.BoxList(tf.constant([[0., 0., 0.2, 0.2]])) box_list2 = box_list.BoxList(tf.constant( [[0, 0.25123152, 1, 1], [0.015789, 0.0985, 0.55789, 0.3842]] )) gt_box_batch = [box_list1, box_list2] gt_class_targets = [None, None] prior_means = tf.constant([[0, 0, .25, .25], [0, .25, 1, 1], [0, .1, .5, .5], [.75, .75, 1, 1]]) prior_stddevs = tf.constant([[.1, .1, .1, .1], [.1, .1, .1, .1], [.1, .1, .1, .1], [.1, .1, .1, .1]]) priors = box_list.BoxList(prior_means) priors.add_field('stddev', prior_stddevs) exp_reg_targets = [[[0, 0, -0.5, -0.5], [0, 0, 0, 0], [0, 0, 0, 0,], [0, 0, 0, 0,],], [[0, 0, 0, 0,], [0, 0.01231521, 0, 0], [0.15789001, -0.01500003, 0.57889998, -1.15799987], [0, 0, 0, 0]]] exp_cls_weights = [[1, 1, 1, 1], [1, 1, 1, 1]] exp_cls_targets = [[[1], [0], [0], [0]], [[0], [1], [1], [0]]] exp_reg_weights = [[1, 0, 0, 0], [0, 1, 1, 0]] exp_match_0 = [0] exp_match_1 = [1, 2] agnostic_target_assigner = self._get_agnostic_target_assigner() (cls_targets, cls_weights, reg_targets, reg_weights, match_list) = targetassigner.batch_assign_targets( agnostic_target_assigner, priors, gt_box_batch, gt_class_targets) self.assertTrue(isinstance(match_list, list) and len(match_list) == 2) with self.test_session() as sess: (cls_targets_out, cls_weights_out, reg_targets_out, reg_weights_out, match_out_0, match_out_1) = sess.run([ cls_targets, cls_weights, reg_targets, reg_weights] + [ match.matched_column_indices() for match in match_list]) self.assertAllClose(cls_targets_out, exp_cls_targets) self.assertAllClose(cls_weights_out, exp_cls_weights) self.assertAllClose(reg_targets_out, exp_reg_targets) self.assertAllClose(reg_weights_out, exp_reg_weights) self.assertAllClose(match_out_0, exp_match_0) self.assertAllClose(match_out_1, exp_match_1)