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

Class TFRecordDatasetV2

tensorflow/python/data/ops/readers.py:273–330  ·  view source on GitHub ↗

A `Dataset` comprising records from one or more TFRecord files.

Source from the content-addressed store, hash-verified

271
272@tf_export("data.TFRecordDataset", v1=[])
273class TFRecordDatasetV2(dataset_ops.DatasetV2):
274 """A `Dataset` comprising records from one or more TFRecord files."""
275
276 def __init__(self, filenames, compression_type=None, buffer_size=None,
277 num_parallel_reads=None):
278 """Creates a `TFRecordDataset` to read one or more TFRecord files.
279
280 Args:
281 filenames: A `tf.string` tensor or `tf.data.Dataset` containing one or
282 more filenames.
283 compression_type: (Optional.) A `tf.string` scalar evaluating to one of
284 `""` (no compression), `"ZLIB"`, or `"GZIP"`.
285 buffer_size: (Optional.) A `tf.int64` scalar representing the number of
286 bytes in the read buffer. If your input pipeline is I/O bottlenecked,
287 consider setting this parameter to a value 1-100 MBs. If `None`, a
288 sensible default for both local and remote file systems is used.
289 num_parallel_reads: (Optional.) A `tf.int64` scalar representing the
290 number of files to read in parallel. If greater than one, the records of
291 files read in parallel are outputted in an interleaved order. If your
292 input pipeline is I/O bottlenecked, consider setting this parameter to a
293 value greater than one to parallelize the I/O. If `None`, files will be
294 read sequentially.
295
296 Raises:
297 TypeError: If any argument does not have the expected type.
298 ValueError: If any argument does not have the expected shape.
299 """
300 filenames = _create_or_validate_filenames_dataset(filenames)
301
302 self._filenames = filenames
303 self._compression_type = compression_type
304 self._buffer_size = buffer_size
305 self._num_parallel_reads = num_parallel_reads
306
307 def creator_fn(filename):
308 return _TFRecordDataset(filename, compression_type, buffer_size)
309
310 self._impl = _create_dataset_reader(creator_fn, filenames,
311 num_parallel_reads)
312 variant_tensor = self._impl._variant_tensor # pylint: disable=protected-access
313 super(TFRecordDatasetV2, self).__init__(variant_tensor)
314
315 def _clone(self,
316 filenames=None,
317 compression_type=None,
318 buffer_size=None,
319 num_parallel_reads=None):
320 return TFRecordDatasetV2(filenames or self._filenames,
321 compression_type or self._compression_type,
322 buffer_size or self._buffer_size,
323 num_parallel_reads or self._num_parallel_reads)
324
325 def _inputs(self):
326 return self._impl._inputs() # pylint: disable=protected-access
327
328 @property
329 def element_spec(self):
330 return tensor_spec.TensorSpec([], dtypes.string)

Callers 2

_cloneMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected