streams
streams
¶
Classes:
| Name | Description |
|---|---|
DataStream |
Base class for handling a generic data stream. |
BufferedDataStream |
Data stream with buffer support to store historical data. |
Dataset |
A buffered dataset that streams data from a PyTorch dataset and simulates data-streams for input/output. |
ImageFileStream |
A buffered dataset for image data. |
LabelStream |
A buffered stream for single and multi-label annotations. |
TokensStream |
A buffered dataset for tokenized text, where each token is paired with its corresponding labels. |
Classes¶
DataStream
¶
Base class for handling a generic data stream.
Initialize a DataStream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
props
|
DataProps
|
Properties of the stream. |
required |
clock
|
Clock
|
Clock object for time management (usually provided from outside). |
Clock()
|
Methods:
| Name | Description |
|---|---|
create |
Create and set the name for a given stream, also updates data stream labels. |
enable |
Enable the stream, allowing data to be retrieved. |
disable |
Disable the stream, preventing data from being retrieved. |
set |
Set a new data sample into the stream, that will be provided when calling "get()". |
get |
Get the most recent data sample from the stream (i.e., the last one that was "set"). |
set_props |
Set (edit) the data properties picking up the ones of another DataStream. |
Source code in unaiverse/streams.py
Methods:¶
create
staticmethod
¶
create(stream: DataStream, name: str | None = None, group: str = 'none', public: bool = True, pubsub: bool = True)
Create and set the name for a given stream, also updates data stream labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
DataStream
|
The stream object to modify. |
required |
name
|
str
|
The name of the stream. |
None
|
group
|
str
|
The name of the group to which the stream belongs. |
'none'
|
public
|
bool
|
If the stream is going to be served in the public net or the private one. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Stream |
The modified stream with updated group name. |
Source code in unaiverse/streams.py
enable
¶
disable
¶
set
¶
Set a new data sample into the stream, that will be provided when calling "get()".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Data sample to set. |
required |
data_tag
|
int
|
Custom data time tag >= 0 (Default: -1, meaning no tags). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if data was accepted based on time constraints, else False. |
Source code in unaiverse/streams.py
get
¶
Get the most recent data sample from the stream (i.e., the last one that was "set").
Returns:
| Type | Description |
|---|---|
Tensor | None
|
torch.Tensor | None: Adapted data sample if available. |
Source code in unaiverse/streams.py
set_props
¶
set_props(data_stream: DataStream)
Set (edit) the data properties picking up the ones of another DataStream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_stream
|
DataStream
|
the source DataStream from which DataProp is taken. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in unaiverse/streams.py
BufferedDataStream
¶
Bases: DataStream
Data stream with buffer support to store historical data.
Initialize a BufferedDataStream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_static
|
bool
|
If True, the buffer stores only one item that is reused. |
False
|
Methods:
| Name | Description |
|---|---|
get |
Get the current data sample based on cycle and buffer. |
set |
Store a new data sample into the buffer. |
set_first_cycle |
Manually set the first cycle for the buffer. |
get_first_cycle |
Get the first cycle of the stream. |
restart |
Restart the buffer using the current clock cycle. |
clear_buffer |
Clear the data buffer |
to_text_snippet |
Convert buffered text samples to a single long string. |
get_since_timestamp |
Retrieve all samples starting from a given timestamp. |
get_since_cycle |
Retrieve all samples starting from a given clock cycle. |
Source code in unaiverse/streams.py
Methods:¶
get
¶
Get the current data sample based on cycle and buffer.
Returns:
| Type | Description |
|---|---|
tuple[Tensor | None, float]
|
torch.Tensor | None: Current buffered sample. |
Source code in unaiverse/streams.py
set
¶
Store a new data sample into the buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Data to store. |
required |
data_tag
|
int
|
Custom data time tag >= 0 (Default: -1, meaning no tags). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the data was buffered. |
Source code in unaiverse/streams.py
set_first_cycle
¶
Manually set the first cycle for the buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
int
|
Global cycle to start from. |
required |
get_first_cycle
¶
restart
¶
Restart the buffer using the current clock cycle.
clear_buffer
¶
Clear the data buffer
Source code in unaiverse/streams.py
to_text_snippet
¶
Convert buffered text samples to a single long string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int | None
|
Optional length of the resulting text snippet. |
None
|
Returns:
| Type | Description |
|---|---|
|
str | None: Human-readable text sequence. |
Source code in unaiverse/streams.py
get_since_timestamp
¶
get_since_timestamp(since_what_timestamp: float, stride: int = 1) -> tuple[list[int] | None, list[Tensor | None] | None, int, DataProps]
Retrieve all samples starting from a given timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since_what_timestamp
|
float
|
Timestamp in seconds. |
required |
stride
|
int
|
Sampling stride. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[list[int] | None, list[Tensor | None] | None, int, DataProps]
|
Tuple containing list of cycles, data, current cycle, and data properties. |
Source code in unaiverse/streams.py
get_since_cycle
¶
get_since_cycle(since_what_cycle: int, stride: int = 1) -> tuple[list[int] | None, list[Tensor | None] | None, int, DataProps]
Retrieve all samples starting from a given clock cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since_what_cycle
|
int
|
Cycle number. |
required |
stride
|
int
|
Stride to skip cycles. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[list[int] | None, list[Tensor | None] | None, int, DataProps]
|
Tuple with cycles, data, current cycle, and properties. |
Source code in unaiverse/streams.py
Dataset
¶
Bases: BufferedDataStream
A buffered dataset that streams data from a PyTorch dataset and simulates data-streams for input/output.
Initialize a Dataset instance, which wraps around a PyTorch Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor_dataset
|
Dataset
|
The PyTorch Dataset to wrap. |
required |
shape
|
tuple
|
The shape of each sample from the data stream. |
required |
index
|
int
|
The index of the element returned by getitem to pick up. |
0
|
Source code in unaiverse/streams.py
Methods:¶
ImageFileStream
¶
ImageFileStream(image_dir: str, list_of_image_files: str, device: device = None, circular: bool = True, show_images: bool = False)
Bases: BufferedDataStream
A buffered dataset for image data.
Initialize an ImageFileStream instance for streaming image data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_dir
|
str
|
The directory containing image files. |
required |
list_of_image_files
|
str
|
Path to the file with list of file names of the images. |
required |
device
|
device
|
The device to store the tensors on. Default is CPU. |
None
|
circular
|
bool
|
Whether to loop the dataset or not. Default is True. |
True
|
Source code in unaiverse/streams.py
Methods:¶
LabelStream
¶
LabelStream(label_dir: str, label_file_csv: str, device: device = None, circular: bool = True, single_class: bool = False, line_header: bool = False)
Bases: BufferedDataStream
A buffered stream for single and multi-label annotations.
Initialize an LabelStream instance for streaming labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_dir
|
str
|
The directory containing image files. |
required |
label_file_csv
|
str
|
Path to the CSV file with labels for the images. |
required |
device
|
device
|
The device to store the tensors on. Default is CPU. |
None
|
circular
|
bool
|
Whether to loop the dataset or not. Default is True. |
True
|
single_class
|
bool
|
Whether to only consider a single class for labeling. Default is False. |
False
|
Source code in unaiverse/streams.py
Methods:¶
TokensStream
¶
Bases: BufferedDataStream
A buffered dataset for tokenized text, where each token is paired with its corresponding labels.
Initialize a Tokens instance for streaming tokenized data and associated labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens_file_csv
|
str
|
Path to the CSV file containing token data. |
required |
circular
|
bool
|
Whether to loop the dataset or not. Default is True. |
True
|
max_tokens
|
int
|
Whether to cut the stream to a maximum number of tokens. Default is -1 (no cut). |
-1
|