Iterables Utils¶
Provides a generator that yields chunks of the input sequence
of the size specified by the batch_size
parameter. The last
chunk may be a smaller batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
Iterable[V]
|
The sequence to be split into batches. |
required |
batch_size |
int
|
The expected size of a batch. |
required |
Returns:
Type | Description |
---|---|
Generator[List[V], None, None]
|
A generator that yields chunks
of |
Examples:
list(create_batches([1, 2, 3, 4, 5], 2))
# [[1, 2], [3, 4], [5]]
list(create_batches("abcde", 3))
# [['a', 'b', 'c'], ['d', 'e']]
Source code in supervision/utils/iterables.py
Fill the sequence with padding elements until the sequence reaches the desired size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
List[V]
|
The input sequence. |
required |
desired_size |
int
|
The expected size of the output list. The
difference between this value and the actual length of |
required |
content |
V
|
The element to be placed at the end of the input
|
required |
Returns:
Type | Description |
---|---|
List[V]
|
A padded version of the input |
Examples: