當前位置: 首頁>>代碼示例>>Python>>正文


Python parsing_ops.FixedLenSequenceFeature方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.parsing_ops.FixedLenSequenceFeature方法的典型用法代碼示例。如果您正苦於以下問題:Python parsing_ops.FixedLenSequenceFeature方法的具體用法?Python parsing_ops.FixedLenSequenceFeature怎麽用?Python parsing_ops.FixedLenSequenceFeature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.parsing_ops的用法示例。


在下文中一共展示了parsing_ops.FixedLenSequenceFeature方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testDecodeSequenceExampleNumBoxesSequenceNotSparse

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def testDecodeSequenceExampleNumBoxesSequenceNotSparse(self):
    tensor_0 = np.array([[32.0, 21.0], [55.5, 22.0]])
    sequence = tf.train.SequenceExample(
        feature_lists=tf.train.FeatureLists(feature_list={
            'tensor_0': self._SequenceFloatFeature(tensor_0, guard_value=-2.0),
        }))
    serialized_sequence = sequence.SerializeToString()
    decoder = tfexample_decoder.TFSequenceExampleDecoder(
        keys_to_context_features={},
        keys_to_sequence_features={
            'tensor_0':
                parsing_ops.FixedLenSequenceFeature([2], dtype=tf.float32),
        },
        items_to_handlers={
            'num_boxes':
                tfexample_decoder.NumBoxesSequence(
                    keys=('tensor_0'), check_consistency=False)
        },
    )

    with self.assertRaisesRegex(ValueError,
                                'tensor must be of type tf.SparseTensor.'):
      decoder.decode(serialized_sequence) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:25,代碼來源:tfexample_decoder_test.py

示例2: _process_yielded_dict

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def _process_yielded_dict(feature_values, keys, features, dtypes, shapes):
  """Read feature_values from the generator and emit a proper output dict."""
  if not isinstance(feature_values, dict):
    raise TypeError("generator must return dict, saw: %s" % feature_values)

  processed_values = {}
  for pk in keys:
    if feature_values.get(pk, None) is not None:
      processed_values[pk] = np.asarray(
          feature_values[pk], dtype=dtypes[pk].as_numpy_dtype)
      check_shape = tensor_shape.TensorShape(processed_values[pk].shape)
      if not shapes[pk].is_compatible_with(check_shape):
        raise ValueError(
            "Feature '%s' has shape %s that is incompatible with declared "
            "shape: %s" % (pk, shapes[pk], check_shape))
      continue
    if isinstance(features[pk], parsing_ops.FixedLenFeature):
      if features[pk].default_value is not None:
        processed_values[pk] = np.asarray(
            features[pk].default_value, dtype=dtypes[pk].as_numpy_dtype)
    elif isinstance(features[pk], parsing_ops.FixedLenSequenceFeature):
      processed_values[pk] = np.empty(
          [0] + features[pk].shape.aslist(), dtype=dtypes[pk].as_numpy_dtype)
    else:
      raise ValueError(
          "Expected generator to return key '%s' with non-empty value" % pk)

  return processed_values 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:30,代碼來源:python_input.py

示例3: config

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def config(self):
    if self.is_sparse:
      return {self.column_name: parsing_ops.VarLenFeature(self.dtype)}
    else:
      return {self.column_name: parsing_ops.FixedLenSequenceFeature(
          [], self.dtype, allow_missing=True,
          default_value=self.default_value)} 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:feature_column.py

示例4: _create_sequence_feature_spec_for_parsing

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def _create_sequence_feature_spec_for_parsing(sequence_feature_columns,
                                              allow_missing_by_default=False):
  """Prepares a feature spec for parsing `tf.SequenceExample`s.

  Args:
    sequence_feature_columns: an iterable containing all the feature columns.
      All items should be instances of classes derived from `_FeatureColumn`.
    allow_missing_by_default: whether to set `allow_missing=True` by default for
      `FixedLenSequenceFeature`s.
  Returns:
    A dict mapping feature keys to `FixedLenSequenceFeature` or `VarLenFeature`.
  """
  feature_spec = create_feature_spec_for_parsing(sequence_feature_columns)
  sequence_feature_spec = {}
  for key, feature in feature_spec.items():
    if (isinstance(feature, parsing_ops.VarLenFeature) or
        isinstance(feature, parsing_ops.FixedLenSequenceFeature)):
      sequence_feature = feature
    elif isinstance(feature, parsing_ops.FixedLenFeature):
      default_is_set = feature.default_value is not None
      if default_is_set:
        logging.warning(
            'Found default value {} for feature "{}". Ignoring this value and '
            'setting `allow_missing=True` instead.'.
            format(feature.default_value, key))
      sequence_feature = parsing_ops.FixedLenSequenceFeature(
          shape=feature.shape,
          dtype=feature.dtype,
          allow_missing=(allow_missing_by_default or default_is_set))
    else:
      raise TypeError(
          "Unsupported feature type: {}".format(type(feature).__name__))
    sequence_feature_spec[key] = sequence_feature
  return sequence_feature_spec 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:36,代碼來源:feature_column.py

示例5: _create_sequence_feature_spec_for_parsing

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def _create_sequence_feature_spec_for_parsing(sequence_feature_columns,
                                              allow_missing_by_default=False):
  """Prepares a feature spec for parsing `tf.SequenceExample`s.

  Args:
    sequence_feature_columns: an iterable containing all the feature columns.
      All items should be instances of classes derived from `_FeatureColumn`.
    allow_missing_by_default: whether to set `allow_missing=True` by default for
      `FixedLenSequenceFeature`s.
  Returns:
    A dict mapping feature keys to `FixedLenSequenceFeature` or `VarLenFeature`.
  """
  feature_spec = create_feature_spec_for_parsing(sequence_feature_columns)
  sequence_feature_spec = {}
  for key, feature in feature_spec.items():
    if isinstance(feature, parsing_ops.VarLenFeature):
      sequence_feature = feature
    elif isinstance(feature, parsing_ops.FixedLenFeature):
      default_is_set = feature.default_value is not None
      if default_is_set:
        logging.warning(
            'Found default value {} for feature "{}". Ignoring this value and '
            'setting `allow_missing=True` instead.'.
            format(feature.default_value, key))
      sequence_feature = parsing_ops.FixedLenSequenceFeature(
          shape=feature.shape,
          dtype=feature.dtype,
          allow_missing=(allow_missing_by_default or default_is_set))
    else:
      raise TypeError(
          "Unsupported feature type: {}".format(type(feature).__name__))
    sequence_feature_spec[key] = sequence_feature
  return sequence_feature_spec 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:35,代碼來源:feature_column.py

示例6: testDecodeSequenceExample

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def testDecodeSequenceExample(self):
    float_array = np.array([[32.0, 21.0], [55.5, 12.0]])
    sequence = tf.train.SequenceExample(
        context=tf.train.Features(feature={
            'string': self._StringFeature('test')
        }),
        feature_lists=tf.train.FeatureLists(feature_list={
            'floats': self._SequenceFloatFeature(float_array)
        }))
    serialized_sequence = sequence.SerializeToString()
    decoder = tfexample_decoder.TFSequenceExampleDecoder(
        keys_to_context_features={
            'string':
                parsing_ops.FixedLenFeature(
                    (), tf.string, default_value='')
        },
        keys_to_sequence_features={
            'floats':
                parsing_ops.FixedLenSequenceFeature([2], dtype=tf.float32),
        },
        items_to_handlers={
            'string': tfexample_decoder.Tensor('string'),
            'floats': tfexample_decoder.Tensor('floats'),
        },
    )
    decoded_string, decoded_floats = decoder.decode(
        serialized_sequence, items=['string', 'floats'])
    with self.test_session():
      self.assertEqual(decoded_string.eval(), b'test')
      self.assertAllClose(decoded_floats.eval(), float_array) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:32,代碼來源:tfexample_decoder_test.py

示例7: testDecodeExampleWithBoundingBoxDense

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenSequenceFeature [as 別名]
def testDecodeExampleWithBoundingBoxDense(self):
    num_bboxes = 10
    np_ymin = np.random.rand(num_bboxes, 1)
    np_xmin = np.random.rand(num_bboxes, 1)
    np_ymax = np.random.rand(num_bboxes, 1)
    np_xmax = np.random.rand(num_bboxes, 1)
    np_bboxes = np.hstack([np_ymin, np_xmin, np_ymax, np_xmax])

    example = tf.train.Example(
        features=tf.train.Features(
            feature={
                'image/object/bbox/ymin': self._EncodedFloatFeature(np_ymin),
                'image/object/bbox/xmin': self._EncodedFloatFeature(np_xmin),
                'image/object/bbox/ymax': self._EncodedFloatFeature(np_ymax),
                'image/object/bbox/xmax': self._EncodedFloatFeature(np_xmax),
            }))
    serialized_example = example.SerializeToString()

    with self.cached_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])

      keys_to_features = {
          'image/object/bbox/ymin':
              parsing_ops.FixedLenSequenceFeature([],
                                                  tf.float32,
                                                  allow_missing=True),
          'image/object/bbox/xmin':
              parsing_ops.FixedLenSequenceFeature([],
                                                  tf.float32,
                                                  allow_missing=True),
          'image/object/bbox/ymax':
              parsing_ops.FixedLenSequenceFeature([],
                                                  tf.float32,
                                                  allow_missing=True),
          'image/object/bbox/xmax':
              parsing_ops.FixedLenSequenceFeature([],
                                                  tf.float32,
                                                  allow_missing=True),
      }

      items_to_handlers = {
          'object/bbox':
              tfexample_decoder.BoundingBox(['ymin', 'xmin', 'ymax', 'xmax'],
                                            'image/object/bbox/'),
      }

      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_bboxes] = decoder.decode(serialized_example, ['object/bbox'])
      bboxes = tf_bboxes.eval()

    self.assertAllClose(np_bboxes, bboxes) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:54,代碼來源:tfexample_decoder_test.py


注:本文中的tensorflow.python.ops.parsing_ops.FixedLenSequenceFeature方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。