コード例 #1
0
  def testBoundingBoxParser(self):
    bounding_boxes = np.array([[0.0, 0.5, 0.3], [0.0, 0.1, 0.6],
                               [1.0, 0.6, 0.8], [1.0, 0.6, 0.7]]).transpose()
    features = {
        'ymin': self._FloatFeature(bounding_boxes[:, 0]),
        'xmin': self._FloatFeature(bounding_boxes[:, 1]),
        'ymax': self._FloatFeature(bounding_boxes[:, 2]),
        'xmax': self._FloatFeature(bounding_boxes[:, 3])
    }

    example = tf.train.Example(features=tf.train.Features(feature=features))

    parser = tf_example_parser.BoundingBoxParser('xmin', 'ymin', 'xmax', 'ymax')
    result = parser.parse(example)
    self.assertIsNotNone(result)
    np_testing.assert_almost_equal(result, bounding_boxes)

    parser = tf_example_parser.BoundingBoxParser('xmin', 'ymin', 'xmax',
                                                 'another_ymax')
    result = parser.parse(example)
    self.assertIsNone(result)
コード例 #2
0
ファイル: kagglify.py プロジェクト: dzx/kaggleStuff
 def __init__(self):
     self.items_to_handlers = {
         fields.DetectionResultFields.key:
         StringParser(fields.TfExampleFields.source_id),
         # Object detections.
         fields.DetectionResultFields.detection_boxes:
         (tf_example_parser.BoundingBoxParser(
             fields.TfExampleFields.detection_bbox_xmin,
             fields.TfExampleFields.detection_bbox_ymin,
             fields.TfExampleFields.detection_bbox_xmax,
             fields.TfExampleFields.detection_bbox_ymax)),
         fields.DetectionResultFields.detection_classes:
         (tf_example_parser.Int64Parser(
             fields.TfExampleFields.detection_class_label)),
         fields.DetectionResultFields.detection_scores:
         (tf_example_parser.FloatParser(
             fields.TfExampleFields.detection_score)),
     }
     self.optional_items_to_handlers = {}