Parses a single tf.train.SequenceExample into video and label tensors.
(self,
serialized_example: tf.train.SequenceExample)
| 310 | {self._label_field: tf.io.VarLenFeature(tf.int64)}) |
| 311 | |
| 312 | def decode(self, |
| 313 | serialized_example: tf.train.SequenceExample) -> Dict[str, Any]: |
| 314 | """Parses a single tf.train.SequenceExample into video and label tensors.""" |
| 315 | contexts, features = tf.io.parse_single_sequence_example( |
| 316 | serialized_example, |
| 317 | context_features=self._context_features, |
| 318 | sequence_features=self._sequence_features) |
| 319 | decoded_tensor = {**contexts, **features} |
| 320 | for i, name in enumerate(self._feature_names): |
| 321 | # Convert the VarLen feature to dense tensor. |
| 322 | if self._feature_from_bytes[i]: |
| 323 | dtype = tf.dtypes.as_dtype(self._feature_dtypes[i]) |
| 324 | decoded_tensor[name] = tf.cast( |
| 325 | tf.io.decode_raw(decoded_tensor[name], out_type=dtype), tf.float32 |
| 326 | ) |
| 327 | else: |
| 328 | if isinstance(decoded_tensor[name], tf.SparseTensor): |
| 329 | decoded_tensor[name] = tf.sparse.to_dense(decoded_tensor[name]) |
| 330 | return decoded_tensor |
| 331 | |
| 332 | |
| 333 | class Parser(parser.Parser): |
no outgoing calls