MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _features_to_raw_params

Function _features_to_raw_params

tensorflow/python/ops/parsing_ops.py:190–303  ·  view source on GitHub ↗

Split feature tuples into raw params used by `gen_parsing_ops`. Args: features: A `dict` mapping feature keys to objects of a type in `types`. types: Type of features to allow, among `FixedLenFeature`, `VarLenFeature`, `SparseFeature`, and `FixedLenSequenceFeature`. Returns:

(features, types)

Source from the content-addressed store, hash-verified

188
189
190def _features_to_raw_params(features, types):
191 """Split feature tuples into raw params used by `gen_parsing_ops`.
192
193 Args:
194 features: A `dict` mapping feature keys to objects of a type in `types`.
195 types: Type of features to allow, among `FixedLenFeature`, `VarLenFeature`,
196 `SparseFeature`, and `FixedLenSequenceFeature`.
197
198 Returns:
199 Tuple of `sparse_keys`, `sparse_types`, `dense_keys`, `dense_types`,
200 `dense_defaults`, `dense_shapes`.
201
202 Raises:
203 ValueError: if `features` contains an item not in `types`, or an invalid
204 feature.
205 """
206 sparse_keys = []
207 sparse_types = []
208 dense_keys = []
209 dense_types = []
210 # When the graph is built twice, multiple dense_defaults in a normal dict
211 # could come out in different orders. This will fail the _e2e_test which
212 # expects exactly the same graph.
213 # OrderedDict which preserves the order can solve the problem.
214 dense_defaults = collections.OrderedDict()
215 dense_shapes = []
216 if features:
217 # NOTE: We iterate over sorted keys to keep things deterministic.
218 for key in sorted(features.keys()):
219 feature = features[key]
220 if isinstance(feature, VarLenFeature):
221 if VarLenFeature not in types:
222 raise ValueError("Unsupported VarLenFeature %s." % (feature,))
223 if not feature.dtype:
224 raise ValueError("Missing type for feature %s." % key)
225 sparse_keys.append(key)
226 sparse_types.append(feature.dtype)
227 elif isinstance(feature, SparseFeature):
228 if SparseFeature not in types:
229 raise ValueError("Unsupported SparseFeature %s." % (feature,))
230
231 if not feature.index_key:
232 raise ValueError(
233 "Missing index_key for SparseFeature %s." % (feature,))
234 if not feature.value_key:
235 raise ValueError(
236 "Missing value_key for SparseFeature %s." % (feature,))
237 if not feature.dtype:
238 raise ValueError("Missing type for feature %s." % key)
239 index_keys = feature.index_key
240 if isinstance(index_keys, str):
241 index_keys = [index_keys]
242 elif len(index_keys) > 1:
243 tf_logging.warning("SparseFeature is a complicated feature config "
244 "and should only be used after careful "
245 "consideration of VarLenFeature.")
246 for index_key in sorted(index_keys):
247 if index_key in sparse_keys:

Callers 5

parse_example_v2Function · 0.85
parse_sequence_exampleFunction · 0.85
parse_single_example_v2Function · 0.85

Calls 4

is_fully_definedMethod · 0.80
keysMethod · 0.45
appendMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected