Skip to content

Commit f3a8515

Browse files
committed
Show results for example
1 parent a3e7228 commit f3a8515

File tree

2 files changed

+25
-64
lines changed

2 files changed

+25
-64
lines changed

README.rst

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,75 +52,36 @@ a more extensive list on API and usage.
5252
.multi_sample
5353
.sample_proportion
5454
55-
Construct informative batches
56-
-----------------------------
55+
Merge / stratify / oversample datastreams
56+
-----------------------------------------
57+
The fruit datastreams given below repeatedly yields the string of its fruit
58+
type.
5759

58-
>>> datastream = Datastream.merge([
59-
... (apple_datastream, 2),
60-
... (pear_datastream, 1),
61-
... (banana_datastream, 1),
62-
... ])
63-
... next(iter(datastream.data_loader(batch_size=6)))
64-
['apple', 'apple', 'pear', 'banana', 'apple', 'apple']
60+
.. code-block:: python
6561
62+
>>> datastream = Datastream.merge([
63+
... (apple_datastream, 2),
64+
... (pear_datastream, 1),
65+
... (banana_datastream, 1),
66+
... ])
67+
>>> next(iter(datastream.data_loader(batch_size=8)))
68+
['apple', 'apple', 'pear', 'banana', 'apple', 'apple', 'pear', 'banana']
6669
6770
Zip independently sampled datastreams
6871
-------------------------------------
72+
The fruit datastreams given below repeatedly yields the string of its fruit
73+
type.
6974

7075
.. code-block:: python
7176
72-
datastream = Datastream.zip([
73-
apple_datastream,
74-
Datastream.merge([pear_datastream, banana_datastream])
75-
])
76-
77-
Pipeline functions
78-
------------------
79-
80-
.. code-block:: python
81-
82-
from PIL import Image
83-
from imgaug import augmenters as iaa
84-
from datastream import Dataset
85-
86-
augmenter = iaa.Sequential([...])
87-
88-
def preprocess(image, class_names):
89-
...
90-
91-
dataset = (
92-
Dataset.from_dataframe(df)
93-
.map(lambda row: (
94-
row['image_path'],
95-
row['class_names'],
96-
))
97-
.map(lambda image_path, class_names: (
98-
Image.open(image_path),
99-
class_names,
100-
))
101-
.map(lambda image, class_names: (
102-
augmenter.augment(image=image),
103-
class_names,
104-
))
105-
.map(preprocess)
106-
)
107-
108-
Datastream to pytorch data loader
109-
---------------------------------
110-
111-
.. code-block:: python
112-
113-
data_loader = (
114-
Datastream(dataset)
115-
.data_loader(
116-
batch_size=32,
117-
num_workers=8,
118-
n_batches_per_epoch=100,
119-
)
120-
)
77+
>>> datastream = Datastream.zip([
78+
... apple_datastream,
79+
... Datastream.merge([pear_datastream, banana_datastream]),
80+
... ])
81+
>>> next(iter(datastream.data_loader(batch_size=4)))
82+
[('apple', 'pear'), ('apple', 'banana'), ('apple', 'pear'), ('apple', 'banana')]
12183
12284
More usage examples
12385
-------------------
124-
12586
See the `documentation <https://pytorch-datastream.readthedocs.io/en/latest/>`_
126-
for examples with oversampling / stratification and weighted sampling.
87+
for more usage examples.

datastream/datastream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class Datastream(BaseModel, Generic[T]):
3232
'''
33-
``Datastream`` combines a ``Dataset`` and a sampler into a stream of
33+
``Datastream[T]`` combines a ``Dataset[T]`` and a sampler into a stream of
3434
examples. By default the samples are drawn without replacement until the
3535
full dataset is exhausted. The proportion of the dataset that should be
3636
drawn before allowing replacement can be changed with ``.sample_proportion``.
@@ -119,9 +119,9 @@ def zip(datastreams: List[Datastream]) -> Datastream[Tuple]:
119119
def map(
120120
self: Datastream[T], function: Callable[Union[[T], [...]], R]
121121
) -> Datastream[R]:
122-
'''
123-
Creates a new Datastream with a new mapped dataset. See ``Dataset.map``
124-
for details.
122+
'''
123+
Creates a new Datastream with a new mapped dataset. See
124+
:func:`Dataset.map` for details.
125125
'''
126126
return Datastream(
127127
self.dataset.map(function),

0 commit comments

Comments
 (0)