Save a batch of data into the cache dictionary. Args: batch_data: target batch data content that save into cache. meta_data: every key-value in the meta_data is corresponding to 1 batch of data.
(self, batch_data: torch.Tensor | np.ndarray, meta_data: dict | None = None)
| 99 | self._cache_dict[save_key] = np.asarray(data, dtype=float) |
| 100 | |
| 101 | def save_batch(self, batch_data: torch.Tensor | np.ndarray, meta_data: dict | None = None) -> None: |
| 102 | """Save a batch of data into the cache dictionary. |
| 103 | |
| 104 | Args: |
| 105 | batch_data: target batch data content that save into cache. |
| 106 | meta_data: every key-value in the meta_data is corresponding to 1 batch of data. |
| 107 | |
| 108 | """ |
| 109 | for i, data in enumerate(batch_data): # save a batch of files |
| 110 | self.save(data, {k: meta_data[k][i] for k in meta_data} if meta_data else None) |
| 111 | |
| 112 | if self.flush: |
| 113 | self.finalize() |
| 114 | |
| 115 | def get_cache(self) -> OrderedDict: |
| 116 | """Get the cache dictionary, key is filename and value is the corresponding data""" |