当前位置: 首页>>代码示例>>Python>>正文


Python feature_pb2.Features方法代码示例

本文整理汇总了Python中tensorflow.core.example.feature_pb2.Features方法的典型用法代码示例。如果您正苦于以下问题:Python feature_pb2.Features方法的具体用法?Python feature_pb2.Features怎么用?Python feature_pb2.Features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.core.example.feature_pb2的用法示例。


在下文中一共展示了feature_pb2.Features方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _write_test_data

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def _write_test_data():
        schema = feature_spec_to_schema({"f0": tf.VarLenFeature(dtype=tf.int64),
                                         "f1": tf.VarLenFeature(dtype=tf.int64),
                                         "f2": tf.VarLenFeature(dtype=tf.int64)})
        batches = [
            [1, 4, None],
            [2, None, None],
            [3, 5, None],
            [None, None, None],
        ]

        example_proto = [example_pb2.Example(features=feature_pb2.Features(feature={
            "f" + str(i): feature_pb2.Feature(int64_list=feature_pb2.Int64List(value=[f]))
            for i, f in enumerate(batch) if f is not None
        })) for batch in batches]

        return DataUtil.write_test_data(example_proto, schema) 
开发者ID:spotify,项目名称:spotify-tensorflow,代码行数:19,代码来源:dataset_test.py

示例2: generate_image

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def generate_image(image_shape, image_format='jpeg', label=0):
  """Generates an image and an example containing the encoded image.

  GenerateImage must be called within an active session.

  Args:
    image_shape: the shape of the image to generate.
    image_format: the encoding format of the image.
    label: the int64 labels for the image.

  Returns:
    image: the generated image.
    example: a TF-example with a feature key 'image/encoded' set to the
      serialized image and a feature key 'image/format' set to the image
      encoding format ['jpeg', 'png'].
  """
  image = np.random.random_integers(0, 255, size=image_shape)
  tf_encoded = _encoder(image, image_format)
  example = example_pb2.Example(features=feature_pb2.Features(feature={
      'image/encoded': _encoded_bytes_feature(tf_encoded),
      'image/format': _string_feature(image_format),
      'image/class/label': _encoded_int64_feature(np.array(label)),
  }))

  return image, example.SerializeToString() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:test_utils.py

示例3: GenerateImage

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def GenerateImage(self, image_format, image_shape):
    """Generates an image and an example containing the encoded image.

    Args:
      image_format: the encoding format of the image.
      image_shape: the shape of the image to generate.

    Returns:
      image: the generated image.
      example: a TF-example with a feature key 'image/encoded' set to the
        serialized image and a feature key 'image/format' set to the image
        encoding format ['jpeg', 'JPEG', 'png', 'PNG', 'raw'].
    """
    num_pixels = image_shape[0] * image_shape[1] * image_shape[2]
    image = np.linspace(
        0, num_pixels - 1, num=num_pixels).reshape(image_shape).astype(np.uint8)
    tf_encoded = self._Encoder(image, image_format)
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'image/encoded': self._EncodedBytesFeature(tf_encoded),
        'image/format': self._StringFeature(image_format)
    }))

    return image, example.SerializeToString() 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:25,代码来源:tfexample_decoder_test.py

示例4: testDecodeExampleWithFloatTensor

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeExampleWithFloatTensor(self):
    np_array = np.random.rand(2, 3, 1).astype('f')

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'array': self._EncodedFloatFeature(np_array),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'array': parsing_ops.FixedLenFeature(np_array.shape, dtypes.float32)
      }
      items_to_handlers = {'array': tfexample_decoder.Tensor('array'),}
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_array] = decoder.decode(serialized_example, ['array'])
      self.assertAllEqual(tf_array.eval(), np_array) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:tfexample_decoder_test.py

示例5: testDecodeExampleWithInt64Tensor

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeExampleWithInt64Tensor(self):
    np_array = np.random.randint(1, 10, size=(2, 3, 1))

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'array': self._EncodedInt64Feature(np_array),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'array': parsing_ops.FixedLenFeature(np_array.shape, dtypes.int64)
      }
      items_to_handlers = {'array': tfexample_decoder.Tensor('array'),}
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_array] = decoder.decode(serialized_example, ['array'])
      self.assertAllEqual(tf_array.eval(), np_array) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:tfexample_decoder_test.py

示例6: testDecodeExampleWithVarLenTensor

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeExampleWithVarLenTensor(self):
    np_array = np.array([[[1], [2], [3]], [[4], [5], [6]]])

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'labels': self._EncodedInt64Feature(np_array),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'labels': parsing_ops.VarLenFeature(dtype=dtypes.int64),
      }
      items_to_handlers = {'labels': tfexample_decoder.Tensor('labels'),}
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels, np_array.flatten()) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:22,代码来源:tfexample_decoder_test.py

示例7: testDecodeExampleWithVarLenTensorToDense

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeExampleWithVarLenTensorToDense(self):
    np_array = np.array([[1, 2, 3], [4, 5, 6]])
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'labels': self._EncodedInt64Feature(np_array),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'labels': parsing_ops.VarLenFeature(dtype=dtypes.int64),
      }
      items_to_handlers = {
          'labels': tfexample_decoder.Tensor(
              'labels', shape=np_array.shape),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels, np_array) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:24,代码来源:tfexample_decoder_test.py

示例8: testDecodeExampleWithSparseTensor

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeExampleWithSparseTensor(self):
    np_indices = np.array([[1], [2], [5]])
    np_values = np.array([0.1, 0.2, 0.6]).astype('f')
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'indices': self._EncodedInt64Feature(np_indices),
        'values': self._EncodedFloatFeature(np_values),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'indices': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'values': parsing_ops.VarLenFeature(dtype=dtypes.float32),
      }
      items_to_handlers = {'labels': tfexample_decoder.SparseTensor(),}
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels.indices, np_indices)
      self.assertAllEqual(labels.values, np_values)
      self.assertAllEqual(labels.dense_shape, np_values.shape) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:26,代码来源:tfexample_decoder_test.py

示例9: testDecodeJpegImage

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeJpegImage(self):
    image_tensor = np.random.randint(256, size=(4, 5, 3)).astype(np.uint8)
    encoded_jpeg = self._EncodeImage(image_tensor)
    decoded_jpeg = self._DecodeImage(encoded_jpeg)
    example = tf.train.Example(features=tf.train.Features(feature={
        'image/encoded': self._BytesFeature(encoded_jpeg),
        'image/format': self._BytesFeature('jpeg'),
        'image/source_id': self._BytesFeature('image_id'),
    })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder()
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    self.assertAllEqual((tensor_dict[fields.InputDataFields.image].
                         get_shape().as_list()), [None, None, 3])
    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)

    self.assertAllEqual(decoded_jpeg, tensor_dict[fields.InputDataFields.image])
    self.assertEqual('image_id', tensor_dict[fields.InputDataFields.source_id]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:22,代码来源:tf_example_decoder_test.py

示例10: testDecodeImageKeyAndFilename

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeImageKeyAndFilename(self):
    image_tensor = np.random.randint(256, size=(4, 5, 3)).astype(np.uint8)
    encoded_jpeg = self._EncodeImage(image_tensor)
    example = tf.train.Example(features=tf.train.Features(feature={
        'image/encoded': self._BytesFeature(encoded_jpeg),
        'image/key/sha256': self._BytesFeature('abc'),
        'image/filename': self._BytesFeature('filename')
    })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder()
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)

    self.assertEqual('abc', tensor_dict[fields.InputDataFields.key])
    self.assertEqual('filename', tensor_dict[fields.InputDataFields.filename]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:19,代码来源:tf_example_decoder_test.py

示例11: testDecodePngImage

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodePngImage(self):
    image_tensor = np.random.randint(256, size=(4, 5, 3)).astype(np.uint8)
    encoded_png = self._EncodeImage(image_tensor, encoding_type='png')
    decoded_png = self._DecodeImage(encoded_png, encoding_type='png')
    example = tf.train.Example(features=tf.train.Features(feature={
        'image/encoded': self._BytesFeature(encoded_png),
        'image/format': self._BytesFeature('png'),
        'image/source_id': self._BytesFeature('image_id')
    })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder()
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    self.assertAllEqual((tensor_dict[fields.InputDataFields.image].
                         get_shape().as_list()), [None, None, 3])
    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)

    self.assertAllEqual(decoded_png, tensor_dict[fields.InputDataFields.image])
    self.assertEqual('image_id', tensor_dict[fields.InputDataFields.source_id]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:22,代码来源:tf_example_decoder_test.py

示例12: testDecodeEmptyPngInstanceMasks

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeEmptyPngInstanceMasks(self):
    image_tensor = np.random.randint(256, size=(10, 10, 3)).astype(np.uint8)
    encoded_jpeg = self._EncodeImage(image_tensor)
    encoded_masks = []
    example = tf.train.Example(
        features=tf.train.Features(
            feature={
                'image/encoded': self._BytesFeature(encoded_jpeg),
                'image/format': self._BytesFeature('jpeg'),
                'image/object/mask': self._BytesFeature(encoded_masks),
                'image/height': self._Int64Feature([10]),
                'image/width': self._Int64Feature([10]),
            })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder(
        load_instance_masks=True, instance_mask_type=input_reader_pb2.PNG_MASKS)
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)
      self.assertAllEqual(
          tensor_dict[fields.InputDataFields.groundtruth_instance_masks].shape,
          [0, 10, 10]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:25,代码来源:tf_example_decoder_test.py

示例13: testDecodeObjectLabel

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeObjectLabel(self):
    image_tensor = np.random.randint(256, size=(4, 5, 3)).astype(np.uint8)
    encoded_jpeg = self._EncodeImage(image_tensor)
    bbox_classes = [0, 1]
    example = tf.train.Example(features=tf.train.Features(feature={
        'image/encoded': self._BytesFeature(encoded_jpeg),
        'image/format': self._BytesFeature('jpeg'),
        'image/object/class/label': self._Int64Feature(bbox_classes),
    })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder()
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    self.assertAllEqual((tensor_dict[
        fields.InputDataFields.groundtruth_classes].get_shape().as_list()),
                        [None])

    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)

    self.assertAllEqual(bbox_classes,
                        tensor_dict[fields.InputDataFields.groundtruth_classes]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:24,代码来源:tf_example_decoder_test.py

示例14: testDecodeObjectArea

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeObjectArea(self):
    image_tensor = np.random.randint(256, size=(4, 5, 3)).astype(np.uint8)
    encoded_jpeg = self._EncodeImage(image_tensor)
    object_area = [100., 174.]
    example = tf.train.Example(features=tf.train.Features(feature={
        'image/encoded': self._BytesFeature(encoded_jpeg),
        'image/format': self._BytesFeature('jpeg'),
        'image/object/area': self._FloatFeature(object_area),
    })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder()
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    self.assertAllEqual((tensor_dict[fields.InputDataFields.groundtruth_area].
                         get_shape().as_list()), [None])
    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)

    self.assertAllEqual(object_area,
                        tensor_dict[fields.InputDataFields.groundtruth_area]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:22,代码来源:tf_example_decoder_test.py

示例15: testDecodeObjectIsCrowd

# 需要导入模块: from tensorflow.core.example import feature_pb2 [as 别名]
# 或者: from tensorflow.core.example.feature_pb2 import Features [as 别名]
def testDecodeObjectIsCrowd(self):
    image_tensor = np.random.randint(256, size=(4, 5, 3)).astype(np.uint8)
    encoded_jpeg = self._EncodeImage(image_tensor)
    object_is_crowd = [0, 1]
    example = tf.train.Example(features=tf.train.Features(feature={
        'image/encoded': self._BytesFeature(encoded_jpeg),
        'image/format': self._BytesFeature('jpeg'),
        'image/object/is_crowd': self._Int64Feature(object_is_crowd),
    })).SerializeToString()

    example_decoder = tf_example_decoder.TfExampleDecoder()
    tensor_dict = example_decoder.decode(tf.convert_to_tensor(example))

    self.assertAllEqual((tensor_dict[
        fields.InputDataFields.groundtruth_is_crowd].get_shape().as_list()),
                        [None])
    with self.test_session() as sess:
      tensor_dict = sess.run(tensor_dict)

    self.assertAllEqual([bool(item) for item in object_is_crowd],
                        tensor_dict[
                            fields.InputDataFields.groundtruth_is_crowd]) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:24,代码来源:tf_example_decoder_test.py


注:本文中的tensorflow.core.example.feature_pb2.Features方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。