Update nodes.py

This commit is contained in:
Kijai 2023-12-21 15:08:06 +02:00
parent aa54cbb6cf
commit ccce5cc2b1

View File

@ -510,15 +510,15 @@ class GetImagesFromBatchIndexed:
} }
def indexedimagesfrombatch(self, images, indexes): def indexedimagesfrombatch(self, images, indexes):
# Parse the indexes string into a list of integers # Parse the indexes string into a list of integers
index_list = [int(index.strip()) for index in indexes.split(',')] index_list = [int(index.strip()) for index in indexes.split(',')]
# Fetch images based on parsed indexes # Convert list of indices to a PyTorch tensor
chosen_images = [images[index] for index in index_list if 0 <= index < len(images)] indices_tensor = torch.tensor(index_list, dtype=torch.long)
# Check if any index was out of range and raise an error if so # Select the images at the specified indices
if len(chosen_images) != len(index_list): chosen_images = images[indices_tensor]
raise ValueError("One or more indexes are out of range")
return (chosen_images,) return (chosen_images,)