def test_yaml_save_load_roundtrip(extension): data = {"some": ["data"]} with NamedTemporaryFile() as f: path = Path(f.name).with_suffix(extension) save_to_yaml(data, path) f.flush() data_deserialized = load_yaml(path) assert data == data_deserialized
def to_yaml(self, path: Pathlike): data = self.to_dict() # Some feature extractors might have a "device" field: # to make sure they get nicely serialized to YAML, we will convert # the torch.device object to its string type. # Note: we don't store the device ID (e.g. we change "cuda:1" to "cuda") # so that the config remains valid even if we use it in a separate run # on a different device. if "device" in data and isinstance(data["device"], torch.device): data["device"] = data["device"].type save_to_yaml(data, path=path)
def to_yaml(self, path: Pathlike): data = asdict(self.config) data['feature_type'] = self.name # Insert the typename for config readability save_to_yaml(data, path=path)