(self, flow_control, current_image, current_mask, max_iterations,
pass_back=False, iteration_count=0, result_images=None, result_masks=None,
dynprompt=None, unique_id=None,)
| 236 | return result_images, result_masks |
| 237 | |
| 238 | def while_loop_close(self, flow_control, current_image, current_mask, max_iterations, |
| 239 | pass_back=False, iteration_count=0, result_images=None, result_masks=None, |
| 240 | dynprompt=None, unique_id=None,): |
| 241 | print(f"Iteration {iteration_count} of {max_iterations}") |
| 242 | |
| 243 | # 标准化输入,确保格式一致 |
| 244 | current_image, current_mask = self.standardize_input(current_image, current_mask) |
| 245 | |
| 246 | # 验证迭代计数 |
| 247 | if iteration_count >= max_iterations: |
| 248 | raise ValueError(f"Iteration count {iteration_count} exceeds max iterations {max_iterations}") |
| 249 | |
| 250 | # 结果初始化或验证 |
| 251 | if result_images is None or result_masks is None: |
| 252 | result_images, result_masks = self.initialize_results(max_iterations, current_image, current_mask) |
| 253 | else: |
| 254 | # 验证现有结果的维度和格式 |
| 255 | assert result_images.shape[0] == max_iterations and len(result_images.shape) == 4, \ |
| 256 | f"Result images must be 4D [B,H,W,C] with batch size {max_iterations}" |
| 257 | assert result_masks.shape[0] == max_iterations and len(result_masks.shape) == 3, \ |
| 258 | f"Result masks must be 3D [B,H,W] with batch size {max_iterations}" |
| 259 | |
| 260 | # 存储当前结果 |
| 261 | result_images[iteration_count:iteration_count+1] = current_image |
| 262 | result_masks[iteration_count:iteration_count+1] = current_mask |
| 263 | |
| 264 | # 检查是否继续循环 |
| 265 | if iteration_count == max_iterations - 1: |
| 266 | print(f"Loop finished with {iteration_count + 1} iterations") |
| 267 | return (result_images, result_masks) |
| 268 | |
| 269 | # 准备下一次循环 |
| 270 | this_node = dynprompt.get_node(unique_id) |
| 271 | upstream = {} |
| 272 | parent_ids = [] |
| 273 | self.explore_dependencies(unique_id, dynprompt, upstream, parent_ids) |
| 274 | parent_ids = list(set(parent_ids)) # 去重 |
| 275 | |
| 276 | # 获取并处理输出节点 |
| 277 | prompts = dynprompt.get_original_prompt() |
| 278 | output_nodes = {} |
| 279 | for id in prompts: |
| 280 | node = prompts[id] |
| 281 | if "inputs" not in node: |
| 282 | continue |
| 283 | class_type = node["class_type"] |
| 284 | if class_type in ALL_NODE_CLASS_MAPPINGS: |
| 285 | class_def = ALL_NODE_CLASS_MAPPINGS[class_type] |
| 286 | if hasattr(class_def, 'OUTPUT_NODE') and class_def.OUTPUT_NODE == True: |
| 287 | for k, v in node['inputs'].items(): |
| 288 | if is_link(v): |
| 289 | output_nodes[id] = v |
| 290 | |
| 291 | # 创建新图 |
| 292 | graph = GraphBuilder() |
| 293 | self.explore_output_nodes(dynprompt, upstream, output_nodes, parent_ids) |
| 294 | |
| 295 | contained = {} |
nothing calls this directly
no test coverage detected