MCPcopy Create free account
hub / github.com/tensorflow/datasets / SubSplitInfo

Class SubSplitInfo

tensorflow_datasets/core/splits.py:359–410  ·  view source on GitHub ↗

Wrapper around a sub split info. This class expose info on the subsplit: ``` ds, info = tfds.load(..., split='train[75%:]', with_info=True) info.splits['train[75%:]'].num_examples ```

Source from the content-addressed store, hash-verified

357
358@dataclasses.dataclass(eq=False, frozen=True)
359class SubSplitInfo:
360 """Wrapper around a sub split info.
361
362 This class expose info on the subsplit:
363
364 ```
365 ds, info = tfds.load(..., split='train[75%:]', with_info=True)
366 info.splits['train[75%:]'].num_examples
367 ```
368 """
369
370 name: str
371 file_instructions: list[shard_utils.FileInstruction]
372
373 @property
374 def shard_lengths(self) -> list[int]:
375 return [f.take for f in self.file_instructions]
376
377 @property
378 def examples_in_shards(self) -> list[int]:
379 return [f.examples_in_shard for f in self.file_instructions]
380
381 @property
382 def num_examples(self) -> int:
383 """Returns the number of example in the subsplit."""
384 return sum(self.shard_lengths)
385
386 @property
387 def num_bytes(self) -> int:
388 return 0 # Unknown
389
390 @property
391 def num_shards(self) -> int:
392 return len(self.file_instructions)
393
394 @property
395 def filenames(self) -> list[str]:
396 """Returns the list of filenames."""
397 return sorted(os.path.basename(f.filename) for f in self.file_instructions)
398
399 @property
400 def filepaths(self) -> list[epath.Path]:
401 """Returns the list of filepaths."""
402 return sorted(epath.Path(f.filename) for f in self.file_instructions)
403
404 def to_proto(self) -> proto_lib.SplitInfo:
405 return proto_lib.SplitInfo(
406 name=self.name,
407 shard_lengths=self.shard_lengths,
408 num_bytes=self.num_bytes,
409 statistics=None,
410 )
411
412
413# TODO(epot): `: tfds.Split` type should be `Union[str, Split]`

Callers 1

__getitem__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected