def test_return_only_valid_boxes_when_input_contains_invalid_boxes(self): num_classes = 4 num_valid_boxes = 3 num_boxes = 10 code_size = 4 dense_location_placeholder = tf.placeholder(tf.float32, shape=(num_boxes, code_size)) dense_num_boxes_placeholder = tf.placeholder(tf.int32, shape=(num_classes)) box_locations, box_classes = ops.dense_to_sparse_boxes( dense_location_placeholder, dense_num_boxes_placeholder, num_classes) feed_dict = {dense_location_placeholder: np.random.uniform( size=[num_boxes, code_size]), dense_num_boxes_placeholder: np.array([1, 0, 0, 2], dtype=np.int32)} expected_box_locations = (feed_dict[dense_location_placeholder] [:num_valid_boxes]) expected_box_classses = np.array([0, 3, 3]) with self.test_session() as sess: box_locations, box_classes = sess.run([box_locations, box_classes], feed_dict=feed_dict) self.assertAllClose(box_locations, expected_box_locations, rtol=1e-6, atol=1e-6) self.assertAllEqual(box_classes, expected_box_classses)