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 |
---|---|---|---|
|
Iterable[V]
|
The sequence to be split into batches. |
required |
|
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 |
---|---|---|---|
|
List[V]
|
The input sequence. |
required |
|
int
|
The expected size of the output list. The
difference between this value and the actual length of |
required |
|
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: