11import logging
22import os
3- import math
43import json
54
65import numpy as np
@@ -624,79 +623,6 @@ def _group_process(cls, texts, **kwargs):
624623# ========== Image Transform Nodes ==========
625624
626625
627- class ResizeImagesToSameSizeNode (ImageProcessingNode ):
628- node_id = "ResizeImagesToSameSize"
629- display_name = "Resize Images to Same Size"
630- description = "Resize all images to the same width and height."
631- extra_inputs = [
632- io .Int .Input ("width" , default = 512 , min = 1 , max = 8192 , tooltip = "Target width." ),
633- io .Int .Input ("height" , default = 512 , min = 1 , max = 8192 , tooltip = "Target height." ),
634- io .Combo .Input (
635- "mode" ,
636- options = ["stretch" , "crop_center" , "pad" ],
637- default = "stretch" ,
638- tooltip = "Resize mode." ,
639- ),
640- ]
641-
642- @classmethod
643- def _process (cls , image , width , height , mode ):
644- img = tensor_to_pil (image )
645-
646- if mode == "stretch" :
647- img = img .resize ((width , height ), Image .Resampling .LANCZOS )
648- elif mode == "crop_center" :
649- left = max (0 , (img .width - width ) // 2 )
650- top = max (0 , (img .height - height ) // 2 )
651- right = min (img .width , left + width )
652- bottom = min (img .height , top + height )
653- img = img .crop ((left , top , right , bottom ))
654- if img .width != width or img .height != height :
655- img = img .resize ((width , height ), Image .Resampling .LANCZOS )
656- elif mode == "pad" :
657- img .thumbnail ((width , height ), Image .Resampling .LANCZOS )
658- new_img = Image .new ("RGB" , (width , height ), (0 , 0 , 0 ))
659- paste_x = (width - img .width ) // 2
660- paste_y = (height - img .height ) // 2
661- new_img .paste (img , (paste_x , paste_y ))
662- img = new_img
663-
664- return pil_to_tensor (img )
665-
666-
667- class ResizeImagesToPixelCountNode (ImageProcessingNode ):
668- node_id = "ResizeImagesToPixelCount"
669- display_name = "Resize Images to Pixel Count"
670- description = "Resize images so that the total pixel count matches the specified number while preserving aspect ratio."
671- extra_inputs = [
672- io .Int .Input (
673- "pixel_count" ,
674- default = 512 * 512 ,
675- min = 1 ,
676- max = 8192 * 8192 ,
677- tooltip = "Target pixel count." ,
678- ),
679- io .Int .Input (
680- "steps" ,
681- default = 64 ,
682- min = 1 ,
683- max = 128 ,
684- tooltip = "The stepping for resize width/height." ,
685- ),
686- ]
687-
688- @classmethod
689- def _process (cls , image , pixel_count , steps ):
690- img = tensor_to_pil (image )
691- w , h = img .size
692- pixel_count_ratio = math .sqrt (pixel_count / (w * h ))
693- new_w = int (w * pixel_count_ratio / steps ) * steps
694- new_h = int (h * pixel_count_ratio / steps ) * steps
695- logging .info (f"Resizing from { w } x{ h } to { new_w } x{ new_h } " )
696- img = img .resize ((new_w , new_h ), Image .Resampling .LANCZOS )
697- return pil_to_tensor (img )
698-
699-
700626class ResizeImagesByShorterEdgeNode (ImageProcessingNode ):
701627 node_id = "ResizeImagesByShorterEdge"
702628 display_name = "Resize Images by Shorter Edge"
@@ -801,29 +727,6 @@ def _process(cls, image, width, height, seed):
801727 return pil_to_tensor (img )
802728
803729
804- class FlipImagesNode (ImageProcessingNode ):
805- node_id = "FlipImages"
806- display_name = "Flip Images"
807- description = "Flip all images horizontally or vertically."
808- extra_inputs = [
809- io .Combo .Input (
810- "direction" ,
811- options = ["horizontal" , "vertical" ],
812- default = "horizontal" ,
813- tooltip = "Flip direction." ,
814- ),
815- ]
816-
817- @classmethod
818- def _process (cls , image , direction ):
819- img = tensor_to_pil (image )
820- if direction == "horizontal" :
821- img = img .transpose (Image .FLIP_LEFT_RIGHT )
822- else :
823- img = img .transpose (Image .FLIP_TOP_BOTTOM )
824- return pil_to_tensor (img )
825-
826-
827730class NormalizeImagesNode (ImageProcessingNode ):
828731 node_id = "NormalizeImages"
829732 display_name = "Normalize Images"
@@ -1470,7 +1373,7 @@ def execute(cls, folder_name):
14701373 shard_path = os .path .join (dataset_dir , shard_file )
14711374
14721375 with open (shard_path , "rb" ) as f :
1473- shard_data = torch .load (f )
1376+ shard_data = torch .load (f , weights_only = True )
14741377
14751378 all_latents .extend (shard_data ["latents" ])
14761379 all_conditioning .extend (shard_data ["conditioning" ])
@@ -1496,13 +1399,10 @@ async def get_node_list(self) -> list[type[io.ComfyNode]]:
14961399 SaveImageDataSetToFolderNode ,
14971400 SaveImageTextDataSetToFolderNode ,
14981401 # Image transform nodes
1499- ResizeImagesToSameSizeNode ,
1500- ResizeImagesToPixelCountNode ,
15011402 ResizeImagesByShorterEdgeNode ,
15021403 ResizeImagesByLongerEdgeNode ,
15031404 CenterCropImagesNode ,
15041405 RandomCropImagesNode ,
1505- FlipImagesNode ,
15061406 NormalizeImagesNode ,
15071407 AdjustBrightnessNode ,
15081408 AdjustContrastNode ,
0 commit comments