Writes the cached dict to a csv
(self)
| 67 | self._data_index = 0 |
| 68 | |
| 69 | def finalize(self) -> None: |
| 70 | """ |
| 71 | Writes the cached dict to a csv |
| 72 | |
| 73 | """ |
| 74 | if not self.output_dir.exists(): |
| 75 | self.output_dir.mkdir(parents=True, exist_ok=True) |
| 76 | with open(self._filepath, "a") as f: |
| 77 | for k, v in self._cache_dict.items(): |
| 78 | f.write(k) |
| 79 | for result in v.flatten(): |
| 80 | f.write(self.delimiter + str(result)) |
| 81 | f.write("\n") |
| 82 | # clear cache content after writing |
| 83 | self.reset_cache() |
| 84 | |
| 85 | def save(self, data: torch.Tensor | np.ndarray, meta_data: dict | None = None) -> None: |
| 86 | """Save data into the cache dictionary. The metadata should have the following key: |