rfgen.adapters¶
Optional framework adapters that bridge rfgen’s consumer abstractions (BaseSampler, BaseCollator) to framework-specific training APIs.
The core rfgen.storage and rfgen.dataset modules do not depend on any
training framework. Only the adapter modules introduce framework dependencies,
and each is behind a rfgen[<extra>] install extra.
Warning
Pre-implementation. This page describes proposed contracts. Class signatures, parameter types, config field names, and behavior are subject to change before code lands. Once implementation exists, content here will be regenerated from docstrings or sourced from running tests.
Class index¶
Class |
Kind |
Module |
Notes |
|---|---|---|---|
concrete |
|
|
class rfgen.dataset.RfgenTorchDataset¶
from torch.utils.data import IterableDataset
class RfgenTorchDataset(IterableDataset):
"""Wrap a rfgen BaseStore so it can be passed to torch.utils.data.DataLoader.
Behind the rfgen[torch] extra. Importing rfgen.dataset does not import
torch.utils.data; this optional class is loaded lazily.
"""
def __init__(
self,
store: BaseStore,
*,
sampler: BaseSampler | None = None,
collator: BaseCollator | None = None,
): ...
def __iter__(self) -> Iterator[Record | dict[str, torch.Tensor]]:
"""Yields collated batches if collator is set, else raw Records."""
Warning
Pre-implementation. This page describes proposed contracts. Class signatures, parameter types, config field names, and behavior are subject to change before code lands. Once implementation exists, content here will be regenerated from docstrings or sourced from running tests.
Wraps a BaseStore as a torch.utils.data.IterableDataset
so it can be passed directly to torch.utils.data.DataLoader.
Each DataLoader worker opens its own StoreHandle
from the store’s dataset_uri(). The adapter is loaded lazily from
rfgen.dataset, so importing the rest of the consumer toolkit remains
framework-neutral.
When collator is set, __iter__ yields dict[str, torch.Tensor] batches
shaped by the collator. When collator=None, __iter__ yields raw
Record objects.
When sampler is set, iteration order follows the sampler. When sampler=None,
a SequentialSampler is
used by default.
Constructor parameters¶
Name |
Type |
Default |
Description |
|---|---|---|---|
|
- |
Store whose |
|
|
BaseSampler | None |
|
Iteration order; defaults to SequentialSampler |
|
BaseCollator | None |
|
Batch shaping; when |
Notes¶
Framework-neutral core.
rfgen.storageand the defaultrfgen.datasetimport path do not importtorch.utils.data. The optional RfgenTorchDataset symbol is loaded lazily behindrfgen[torch].DataLoader compatibility. Because RfgenTorchDataset is an
IterableDataset, DataLoader sharding for multi-worker loading is controlled bytorch.utils.data.get_worker_info(). Whennum_workers > 1, the__iter__implementation requires a sampler with a concretepartition(worker_id, num_workers)hook usingworker_info.idandworker_info.num_workers. Duck-typed samplers that provide only__iter__and__len__are supported only withnum_workers <= 1; multi-worker custom samplers must implementpartition(...)orbind(source)that returns a sampler with a concretepartition(...)implementation.Collator and batch_size. When
collatoris set,DataLoadershould be constructed withbatch_size=None(orbatch_size=1withcollate_fndisabled) becauseRfgenTorchDataset.__iter__already returns batched tensors from the collator. Whencollator=None, let DataLoader’s default collation handle stacking.
Usage example¶
from rfgen.storage import ZarrStore
from rfgen.dataset.samplers import RandomSampler
from rfgen.dataset.collators import DetectionCollator
from rfgen.dataset import RfgenTorchDataset
from torch.utils.data import DataLoader
store = ZarrStore()
sampler = RandomSampler(seed=42)
collator = DetectionCollator()
dataset = RfgenTorchDataset(store, sampler=sampler, collator=collator)
loader = DataLoader(dataset, batch_size=None, num_workers=4)
for batch in loader:
iq = batch["iq"] # shape (1, 2, N)
bboxes = batch["bboxes"] # list[Tensor], one entry for this record
...
See Also¶
Concepts / Architecture § Consumer Access - framing of the adapter layer.
Reference /
rfgen.dataset- sampler and collator ABCs and concrete classes.