forked from watarika/ComfyUI-ImageBatch-Utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.py
37 lines (30 loc) · 1.12 KB
/
nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class ImageBatchToSubBatchesNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"batch_size": ("INT", { "default": 1, "min": 1, "step": 1, }),
}
}
RETURN_TYPES = ("IMAGE",)
OUTPUT_IS_LIST = (True,)
FUNCTION = "execute"
CATEGORY = "image"
def execute(self, image, batch_size):
"""
Splits the image batch into smaller batches of the specified size.
Parameters:
image (torch.Tensor): A batch of images in the form of a PyTorch tensor.
batch_size (int): The number of images in each smaller batch.
Returns:
tuple: A tuple containing a list of smaller batches.
"""
num_batches = (image.shape[0] + batch_size - 1) // batch_size # Calculate the number of batches
return ([image[i*batch_size:(i+1)*batch_size] for i in range(num_batches)], )
NODE_CLASS_MAPPINGS = {
"ImageBatchToSubBatches": ImageBatchToSubBatchesNode
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ImageBatchToSubBatches": "Image Batch To Sub Batches",
}