NPZCache
- class hybrid_learning.datasets.caching.NPZCache(cache_root=None)[source]
Bases:
FileCache
File cache that uses numpy compressed saving and loading mechanism to cache
torch.Tensor
objects. For further details see super class.Public Data Attributes:
The file ending to append to descriptors to get the file path.
The key within the compressed ZIP archive under which to store and find the object.
Inherited from : py: class:FileCache
The file ending to append to descriptors to get the file path.
Public Methods:
put_file
(filepath, obj)Save
obj
to .npz archive atfilepath
usingnumpy.savez_compressed()
.load_file
(filepath)Load
obj
from .npz archive atfilepath
usingnumpy.load()
.Inherited from : py: class:FileCache
put
(descriptor, obj)Store
obj
under the cache root usingput_file()
.load
(descriptor)Load object from file
descriptor
+FILE_ENDING
under cache root.clear
()Remove all files from cache root.
descriptors
()Provide paths of all cached files with ending stripped and relative to cache root.
descriptor_to_fp
(descriptor)Return the file path of the cache file for a given
descriptor
.put_file
(filepath, obj)Save
obj
to .npz archive atfilepath
usingnumpy.savez_compressed()
.load_file
(filepath)Load
obj
from .npz archive atfilepath
usingnumpy.load()
.Inherited from : py: class:Cache
put
(descriptor, obj)Store
obj
under the cache root usingput_file()
.load
(descriptor)Load object from file
descriptor
+FILE_ENDING
under cache root.put_batch
(descriptors, objs)Store a batch of
objs
in this cache using accordingdescriptors
.load_batch
(descriptors[, return_none_if])Load a batch of objects.
clear
()Remove all files from cache root.
descriptors
()Provide paths of all cached files with ending stripped and relative to cache root.
as_dict
()Return a dict with all cached descriptors and objects.
wrap
(getitem[, descriptor_map])Add this cache to the deterministic function
getitem
(which should have no side effects).Special Methods:
Inherited from : py: class:FileCache
__init__
([cache_root])Init.
__repr__
()Return repr(self).
Inherited from : py: class:Cache
__repr__
()Return repr(self).
__add__
(other)Return a (cascaded) cache which will first lookup
self
thenother
with default sync mode.__radd__
(other)Return a (cascaded) cache which will first lookup
other
thenself
with default sync mode.
- Parameters
cache_root (str) –
- put_file(filepath, obj)[source]
Save
obj
to .npz archive atfilepath
usingnumpy.savez_compressed()
.
- FILE_ENDING = '.npz'
The file ending to append to descriptors to get the file path. See
FileCache.descriptor_to_fp()
. This is the standard fornumpy.savez_compressed()
.
- OBJ_KEY = 'obj'
The key within the compressed ZIP archive under which to store and find the object.