(self, samples: List[np.ndarray], pos_prompt: str, neg_prompt: str)
| 210 | self.save(samples, pos_prompt, neg_prompt) |
| 211 | |
| 212 | def save(self, samples: List[np.ndarray], pos_prompt: str, neg_prompt: str) -> None: |
| 213 | file_stem = self.loop_ctx["file_stem"] |
| 214 | assert len(samples) == self.args.n_samples |
| 215 | for i, sample in enumerate(samples): |
| 216 | file_name = ( |
| 217 | f"{file_stem}_{i}.png" |
| 218 | if self.args.n_samples > 1 |
| 219 | else f"{file_stem}.png" |
| 220 | ) |
| 221 | save_path = os.path.join(self.save_dir, file_name) |
| 222 | Image.fromarray(sample).save(save_path) |
| 223 | print(f"save result to {save_path}") |
| 224 | csv_path = os.path.join(self.save_dir, "prompt.csv") |
| 225 | df = pd.DataFrame( |
| 226 | { |
| 227 | "file_name": [file_stem], |
| 228 | "pos_prompt": [pos_prompt], |
| 229 | "neg_prompt": [neg_prompt], |
| 230 | } |
| 231 | ) |
| 232 | if os.path.exists(csv_path): |
| 233 | df.to_csv(csv_path, index=None, mode="a", header=None) |
| 234 | else: |
| 235 | df.to_csv(csv_path, index=None) |
no outgoing calls
no test coverage detected