We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 74ea045 commit 786375aCopy full SHA for 786375a
1 file changed
tensorflow_datasets/core/writer.py
@@ -291,10 +291,16 @@ def write(
291
path: epath.Path,
292
) -> int:
293
"""Returns the number of examples written to the given path."""
294
- serialized_examples = [(k, self._serialize_example(v)) for k, v in examples]
295
- self._example_writer.write(path=path, examples=serialized_examples)
+ (for_writing, for_counting) = itertools.tee(examples, 2)
296
297
- return len(serialized_examples)
+ def serialize_examples() -> Iterator[type_utils.KeySerializedExample]:
+ for k, v in for_writing:
298
+ yield k, self._serialize_example(v)
299
+
300
+ self._example_writer.write(path=path, examples=serialize_examples())
301
+ num_examples = sum(1 for _ in for_counting)
302
303
+ return num_examples
304
305
def write_with_beam(
306
self,
0 commit comments