PytorchStream#

class capymoa.stream.PytorchStream[source]#

Bases: Stream

PytorchStream turns a PyTorch dataset into a datastream.

>>> from capymoa.evaluation import ClassificationEvaluator
...
>>> from capymoa.datasets import get_download_dir
>>> from capymoa.stream import PytorchStream
>>> from torchvision import datasets
>>> from torchvision.transforms import ToTensor
>>> print("Using PyTorch Dataset"); pytorchDataset = datasets.FashionMNIST( 
...     root=get_download_dir(),
...     train=True,
...     download=True,
...     transform=ToTensor()
... )
Using PyTorch Dataset...
>>> pytorch_stream = PytorchStream(dataset=pytorchDataset)
>>> pytorch_stream.get_schema()
@relation PytorchDataset

@attribute attrib_0 numeric
@attribute attrib_1 numeric
...
@attribute attrib_783 numeric
@attribute class {T-shirt/top,Trouser,Pullover,Dress,Coat,Sandal,Shirt,Sneaker,Bag,'Ankle boot'}

@data
>>> pytorch_stream.next_instance()
LabeledInstance(
    Schema(PytorchDataset),
    x=ndarray(..., 784),
    y_index=9,
    y_label='Ankle boot'
)
__init__(
dataset: Dataset,
target_type='categorical',
)[source]#

Construct PytorchStream from a PyTorch dataset.

Parameters:
  • dataset – PyTorch containing tuples of x and y

  • enforce_regression – Force the task to be a regression task, default is False

has_more_instances()[source]#

Return True if the stream have more instances to read.

next_instance()[source]#

Return the next instance in the stream.

Raises:

ValueError – If the machine learning task is neither a regression nor a classification task.

Returns:

A labeled instances or a regression depending on the schema.

get_schema()[source]#

Return the schema of the stream.

get_moa_stream()[source]#

Get the MOA stream object if it exists.

restart()[source]#

Restart the stream to read instances from the beginning.

CLI_help() str[source]#

Return cli help string for the stream.