(self, segmented_images, segmented_masks, unique_id=None,
iteration_count=0, previous_image=None)
| 86 | return image |
| 87 | |
| 88 | def while_loop_open(self, segmented_images, segmented_masks, unique_id=None, |
| 89 | iteration_count=0, previous_image=None): |
| 90 | print(f"while_loop_open Processing iteration {iteration_count}") |
| 91 | |
| 92 | # 标准化输入 |
| 93 | segmented_images, segmented_masks = self.standardize_input(segmented_images, segmented_masks) |
| 94 | |
| 95 | # 获取最大迭代次数 |
| 96 | max_iterations = segmented_images.shape[0] |
| 97 | if max_iterations == 0: |
| 98 | raise ValueError("No images provided in segmented_images") |
| 99 | |
| 100 | # 验证迭代计数 |
| 101 | if iteration_count >= max_iterations: |
| 102 | raise ValueError(f"Iteration count {iteration_count} exceeds max iterations {max_iterations}") |
| 103 | |
| 104 | # 处理上一次循环传回的图片 |
| 105 | if previous_image is not None and iteration_count > 0: |
| 106 | # 确保previous_image维度正确 |
| 107 | if len(previous_image.shape) == 3: |
| 108 | previous_image = previous_image.unsqueeze(0) |
| 109 | |
| 110 | # 调整尺寸以匹配batch中的图片 |
| 111 | previous_image = self.resize_to_match(previous_image, segmented_images.shape) |
| 112 | |
| 113 | # 替换下一次要处理的图片 |
| 114 | next_idx = min(iteration_count, max_iterations - 1) |
| 115 | segmented_images[next_idx:next_idx+1] = previous_image |
| 116 | |
| 117 | # 获取当前迭代的图片和蒙版 |
| 118 | current_image = segmented_images[iteration_count:iteration_count+1] |
| 119 | current_mask = segmented_masks[iteration_count:iteration_count+1] |
| 120 | |
| 121 | return tuple(["stub", current_image, current_mask, max_iterations, iteration_count]) |
| 122 | |
| 123 | |
| 124 | @VariantSupport() |
nothing calls this directly
no test coverage detected