コード例 #1
0
  def testParseString(self):
    string_val = 'abc'
    features = {'string': self._BytesFeature(string_val)}
    example = tf.train.Example(features=tf.train.Features(feature=features))

    parser = tf_example_parser.StringParser('string')
    result = parser.parse(example)
    self.assertIsNotNone(result)
    self.assertEqual(result, string_val)

    parser = tf_example_parser.StringParser('another_string')
    result = parser.parse(example)
    self.assertIsNone(result)
コード例 #2
0
  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)