Returns a `tf.Operation` to write a dataset to a file. Args: dataset: a `tf.data.Dataset` whose elements are to be written to a file Returns: A `tf.Operation` that, when run, writes contents of `dataset` to a file.
(self, dataset)
| 66 | argument_dtype=dtypes.string) |
| 67 | |
| 68 | def write(self, dataset): |
| 69 | """Returns a `tf.Operation` to write a dataset to a file. |
| 70 | |
| 71 | Args: |
| 72 | dataset: a `tf.data.Dataset` whose elements are to be written to a file |
| 73 | |
| 74 | Returns: |
| 75 | A `tf.Operation` that, when run, writes contents of `dataset` to a file. |
| 76 | """ |
| 77 | if not isinstance(dataset, dataset_ops.DatasetV2): |
| 78 | raise TypeError("`dataset` must be a `tf.data.Dataset` object.") |
| 79 | if not dataset_ops.get_structure(dataset).is_compatible_with( |
| 80 | tensor_spec.TensorSpec([], dtypes.string)): |
| 81 | raise TypeError( |
| 82 | "`dataset` must produce scalar `DT_STRING` tensors whereas it " |
| 83 | "produces shape {0} and types {1}".format( |
| 84 | dataset_ops.get_legacy_output_shapes(dataset), |
| 85 | dataset_ops.get_legacy_output_types(dataset))) |
| 86 | return gen_experimental_dataset_ops.dataset_to_tf_record( |
| 87 | dataset._variant_tensor, self._filename, self._compression_type) # pylint: disable=protected-access |