![]() |
ImFusion SDK 4.3
|
#include <ImFusion/ML/DataLoaders/CacheDataLoader.h>
Caches the dataset loaded until now. More...
Caches the dataset loaded until now.
Public Member Functions | |
CacheDataLoader (std::unique_ptr< DataLoader > loader, bool makeExclusiveCPU=true, bool lazy=true, int compressionLevel=0, bool shuffle=false, int num_threads=1, bool verbose=false) | |
Constructs the caching. | |
CacheDataLoader (DataLoaderList dataLoaders, const Properties &prop) | |
std::optional< DataItem > | next () override |
Advance the loader by one iteration. | |
std::optional< size_t > | size () const override |
The size of the loader is always known after the cache is fully generated (either lazily or not) If caching lazily, the size is the same as that of the underlying loader (unknown if Dynamic), until the cache is fully generated. | |
void | reset () override |
Resets the loader index but not the held cache This is to avoid reloading and caching the entire data set every time the iteration is consumed. | |
void | reinit () override |
Forces a cache destruction. | |
Cardinality | cardinality () const override |
After caching, the number of items in the cache is known, and thus the cardinality is Fixed. | |
![]() | |
DataLoader (std::string name, bool verbose=false) | |
Constructor to be used by DataReaders, as they are the first elements in the chain. | |
DataLoader (std::string name, std::unique_ptr< DataLoader > loader, bool verbose=false) | |
Constructor to be used by all other derived DataLoaders. | |
DataLoader (std::string name, DataLoaderList &&dataLoaders, bool verbose=false) | |
Constructor to be used by all other derived DataLoaders. | |
const std::string & | name () const |
Name of the loader. | |
DataLoader * | singleUnderlyingLoader () const |
Return a single underlying dataloader Expects there to be only one, returns a nullptr otherwise. | |
std::unique_ptr< DataLoader > | extractDataloader () |
Return a single underlying dataloader Expects there to be only one, throws an exception otherwise. | |
DataLoaderList & | loaders () |
DataLoaderList const & | loaders () const |
bool | verbose () const |
virtual void | setRandomSeed (unsigned int seed) |
void | configure (const Properties *properties) override |
Configure this object instance by de-serializing the given Properties. | |
virtual Status | canBePrefetched () const |
Indicates whether a loader is eligible for prefetching. | |
const std::string & | logDomain () const |
Log domain for AdvancedParameter. | |
![]() | |
virtual void | configuration (Properties *p) const |
Serialize the current object configuration into the given Properties object. | |
virtual void | configureDefaults () |
Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
void | registerParameter (ParameterBase *param) |
Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
void | unregisterParameter (const ParameterBase *param) |
Remove the given Parameter or SubProperty from the list of registered parameters. | |
Configurable (const Configurable &rhs) | |
Configurable (Configurable &&rhs) noexcept | |
Configurable & | operator= (const Configurable &) |
Configurable & | operator= (Configurable &&) noexcept |
Additional Inherited Members | |
![]() | |
LoaderParam< bool > | m_verbose = {"verbose", false, this, ParamRequired::No} |
If enabled, print log messages with extra information like timings. | |
![]() | |
Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
![]() | |
NotCopyable (NotCopyable &&) noexcept=default | |
NotCopyable & | operator= (NotCopyable &&) noexcept=default |
NotCopyable (const NotCopyable &)=delete | |
NotCopyable & | operator= (const NotCopyable &)=delete |
![]() | |
std::string | m_name |
Cardinality | m_cardinality = Cardinality::Fixed |
Random::Generator | m_randGenerator |
DataLoaderList | m_dataLoaders |
![]() | |
std::vector< Param > | m_params |
List of all registered Parameter and SubProperty instances. | |
|
explicit |
Constructs the caching.
loader | previous loader |
makeExclusiveCPU | releases the GPU memory if true |
lazy | caches items when requested (otherwise caches the whole dataset at initialization) |
compressionLevel | controls compression. Higher means more compression, but slower. 0 disables compression |
shuffle | reshuffle the order of the cache every epoch |
num_threads | the number of items to prefetch from the cache in the background. The cache needs to create copies of the data so fetching is more expensive than one may anticipate. Only has an effect if makeExclusiveCPU is true. |
DataLoaderException | if the nested loader is uncountable |
std::bad_alloc | if the system runs out of memory while caching the dataset |
|
overridevirtual |
Advance the loader by one iteration.
The function must pull an item from the underlying node, process it and return it. If the underlyng loader is exhausted, returns an empty optional.
Implements DataLoader.
|
overridevirtual |
The size of the loader is always known after the cache is fully generated (either lazily or not) If caching lazily, the size is the same as that of the underlying loader (unknown if Dynamic), until the cache is fully generated.
After that, the size is known regardless of the underlying loader size.
Implements DataLoader.
|
overridevirtual |
Resets the loader index but not the held cache This is to avoid reloading and caching the entire data set every time the iteration is consumed.
To force clear the cache, use reinit.
Reimplemented from DataLoader.
|
overridevirtual |
Forces a cache destruction.
The cache is created at the next call of next
.
Reimplemented from DataLoader.
|
overridevirtual |
After caching, the number of items in the cache is known, and thus the cardinality is Fixed.
When caching lazily, the cardinality is the same of the underlying loader until the cache is fully generated (first epoch typically), then is Fixed.
Reimplemented from DataLoader.