MCPcopy Create free account
hub / github.com/Francis-Rings/StableAnimator / save_combined_frames

Function save_combined_frames

train_single.py:99–126  ·  view source on GitHub ↗
(batch_output, validation_images, validation_control_images, output_folder)

Source from the content-addressed store, hash-verified

97
98
99def save_combined_frames(batch_output, validation_images, validation_control_images, output_folder):
100 # Flatten batch_output, which is a list of lists of PIL Images
101 flattened_batch_output = [img for sublist in batch_output for img in sublist]
102
103 # Combine frames into a list without converting (since they are already PIL Images)
104 combined_frames = validation_images + validation_control_images + flattened_batch_output
105
106 # Calculate rows and columns for the grid
107 num_images = len(combined_frames)
108 cols = 3 # adjust number of columns as needed
109 rows = (num_images + cols - 1) // cols
110 timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
111
112 filename = f"combined_frames_{timestamp}.png"
113 # Create and save the grid image
114 grid = create_image_grid(combined_frames, rows, cols)
115 output_folder = os.path.join(output_folder, "validation_images")
116 os.makedirs(output_folder, exist_ok=True)
117
118 # Now define the full path for the file
119 timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
120 filename = f"combined_frames_{timestamp}.png"
121 output_loc = os.path.join(output_folder, filename)
122
123 if grid is not None:
124 grid.save(output_loc)
125 else:
126 print("Failed to create image grid")
127
128
129# def load_images_from_folder(folder):

Callers

nothing calls this directly

Calls 1

create_image_gridFunction · 0.70

Tested by

no test coverage detected