Save data into the cache dictionary. The metadata should have the following key: - ``'filename_or_obj'`` -- save the data corresponding to file name or object. If meta_data is None, use the default index from 0 to save data instead. Args: data: target data co
(self, data: torch.Tensor | np.ndarray, meta_data: dict | None = None)
| 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: |
| 87 | - ``'filename_or_obj'`` -- save the data corresponding to file name or object. |
| 88 | If meta_data is None, use the default index from 0 to save data instead. |
| 89 | |
| 90 | Args: |
| 91 | data: target data content that save into cache. |
| 92 | meta_data: the metadata information corresponding to the data. |
| 93 | |
| 94 | """ |
| 95 | save_key = meta_data[Key.FILENAME_OR_OBJ] if meta_data else str(self._data_index) |
| 96 | self._data_index += 1 |
| 97 | if isinstance(data, torch.Tensor): |
| 98 | data = data.detach().cpu().numpy() |
| 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. |
no outgoing calls