An iterator that read the records from a TFRecords file. Args: path: The path to the TFRecords file. options: (optional) A TFRecordOptions object. Yields: Strings. Raises: IOError: If `path` cannot be opened for reading.
(path, options=None)
| 156 | instructions=("Use eager execution and: \n" |
| 157 | "`tf.data.TFRecordDataset(path)`")) |
| 158 | def tf_record_iterator(path, options=None): |
| 159 | """An iterator that read the records from a TFRecords file. |
| 160 | |
| 161 | Args: |
| 162 | path: The path to the TFRecords file. |
| 163 | options: (optional) A TFRecordOptions object. |
| 164 | |
| 165 | Yields: |
| 166 | Strings. |
| 167 | |
| 168 | Raises: |
| 169 | IOError: If `path` cannot be opened for reading. |
| 170 | """ |
| 171 | compression_type = TFRecordOptions.get_compression_type_string(options) |
| 172 | with errors.raise_exception_on_not_ok_status() as status: |
| 173 | reader = pywrap_tensorflow.PyRecordReader_New( |
| 174 | compat.as_bytes(path), 0, compat.as_bytes(compression_type), status) |
| 175 | |
| 176 | if reader is None: |
| 177 | raise IOError("Could not open %s." % path) |
| 178 | try: |
| 179 | while True: |
| 180 | try: |
| 181 | reader.GetNext() |
| 182 | except errors.OutOfRangeError: |
| 183 | break |
| 184 | yield reader.record() |
| 185 | finally: |
| 186 | reader.Close() |
| 187 | |
| 188 | |
| 189 | @tf_export( |
nothing calls this directly
no test coverage detected