-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBatchOffset.py
51 lines (42 loc) · 1.52 KB
/
BatchOffset.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import torch
import numpy as np
class BatchOffset:
def __init__(self):
self.type = "BatchOffset"
self.output_node = True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"images": ("IMAGE",),
"offset": ("INT", {
"default": -1,
"min": -100, # Arbitrary limit, can be adjusted
"max": 100, # Arbitrary limit, can be adjusted
"step": 1
})
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "offset_batch"
CATEGORY = "image/batch"
def offset_batch(self, images, offset):
# Check if we have a batch of images
if len(images.shape) < 4 or images.shape[0] <= 1:
print("Warning: BatchOffset node requires a batch of multiple images")
return (images,)
# Calculate the effective offset (handling negative numbers)
batch_size = images.shape[0]
effective_offset = offset % batch_size
# Perform the offset operation
# For offset -1, this will move each image one position forward
# and wrap the first image to the end
shifted_images = torch.roll(images, shifts=effective_offset, dims=0)
return (shifted_images,)
# This is required for ComfyUI to recognize and load the node
NODE_CLASS_MAPPINGS = {
"BatchOffset": BatchOffset
}
NODE_DISPLAY_NAME_MAPPINGS = {
"BatchOffset": "Batch Offset"
}