本文整理汇总了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)
示例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
示例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)}
示例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
示例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
示例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)
示例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)