def testParseFloat(self):
    float_array_val = [1.5, 1.4, 2.0]
    features = {'floats': self._FloatFeature(float_array_val)}
    example = tf.train.Example(features=tf.train.Features(feature=features))

    parser = tf_example_parser.FloatParser('floats')
    result = parser.parse(example)
    self.assertIsNotNone(result)
    np_testing.assert_almost_equal(result, float_array_val)

    parser = tf_example_parser.StringParser('another_floats')
    result = parser.parse(example)
    self.assertIsNone(result)
Esempio n. 2
0
 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 = {}