def setUp(self): super(RCNNTargetTest, self).setUp() # We don't care about the class labels or the batch number in most of # these tests. self._num_classes = 5 self._placeholder_label = 3.0 self._config = EasyDict({ "foreground_threshold": 0.5, "background_threshold_high": 0.5, "background_threshold_low": 0.1, "foreground_fraction": 0.5, "minibatch_size": 2, }) # We check for a difference smaller than this numbers in our tests # instead of checking for exact equality. self._equality_delta = 1e-03 self._shared_model = RCNNTarget(self._num_classes, self._config, seed=0) tf.reset_default_graph()
def testOddMinibatchSize(self): """Tests we're getting the right results when there's an odd minibatch size. """ config = EasyDict({ 'foreground_threshold': 0.5, 'background_threshold_high': 0.5, 'background_threshold_low': 0.1, 'foreground_fraction': 0.5, 'minibatch_size': 5, }) model = RCNNTarget(self._num_classes, config, seed=0) gt_boxes = tf.constant( [(200, 300, 250, 390, self._placeholder_label)], dtype=tf.float32 ) proposed_boxes = tf.constant( [ (12, 70, 350, 540), # noise (190, 310, 240, 370), # IoU: 0.4763 (197, 300, 252, 389), # IoU: 0.9015 (196, 300, 252, 389), # IoU: 0.8859 (197, 303, 252, 394), # IoU: 0.8459 (180, 310, 235, 370), # IoU: 0.3747 (0, 0, 400, 400), # noise (197, 302, 252, 389), # IoU: 0.8832 (180, 310, 235, 370), # IoU: 0.3747 (180, 310, 235, 370), # IoU: 0.3747 (0, 0, 400, 400), # noise ], dtype=tf.float32 ) (proposals_label, bbox_targets) = self._run_rcnn_target( model, gt_boxes, proposed_boxes ) foreground_number = proposals_label[proposals_label >= 1].shape[0] background_number = proposals_label[proposals_label == 0].shape[0] foreground_fraction = config.foreground_fraction minibatch_size = config.minibatch_size self.assertLessEqual( foreground_number, np.floor(foreground_fraction * minibatch_size) ) self.assertGreater(foreground_number, 0) self.assertLessEqual( background_number, minibatch_size - foreground_number ) self.assertEqual( proposals_label[proposals_label >= 0].shape[0], config.minibatch_size )