ImFusion SDK 4.3
PersistentCacheDataLoader Class Reference

#include <ImFusion/ML/DataLoaders/PersistentCacheDataLoader.h>

Caches the dataset loaded until now in a persistent manner (on a disk location) More...

+ Inheritance diagram for PersistentCacheDataLoader:

Detailed Description

Caches the dataset loaded until now in a persistent manner (on a disk location)

Public Member Functions

 PersistentCacheDataLoader (std::unique_ptr< DataLoader > loader, const std::string &location, bool lazy=true, bool reload=false, bool compression=false, bool shuffle=false, bool verbose=false)
 Constructs the caching data loader.
 
 PersistentCacheDataLoader (DataLoaderList dataLoaders, const Properties &prop)
 
std::optional< DataItemnext () 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 and not reloading, 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 store 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, i.e.
 
Cardinality cardinality () const override
 After caching, the number of items in the cache is known, and thus the cardinality is Fixed.
 
- Public Member Functions inherited from DataLoader
 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::stringname () const
 Name of the loader.
 
DataLoadersingleUnderlyingLoader () const
 Return a single underlying dataloader Expects there to be only one, returns a nullptr otherwise.
 
std::unique_ptr< DataLoaderextractDataloader ()
 Return a single underlying dataloader Expects there to be only one, throws an exception otherwise.
 
DataLoaderListloaders ()
 
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::stringlogDomain () const
 Log domain for AdvancedParameter.
 
- Public Member Functions inherited from Configurable
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
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Additional Inherited Members

- Public Attributes inherited from DataLoader
LoaderParam< bool > m_verbose = {"verbose", false, this, ParamRequired::No}
 If enabled, print log messages with extra information like timings.
 
- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 
- Protected Member Functions inherited from NotCopyable
 NotCopyable (NotCopyable &&) noexcept=default
 
NotCopyableoperator= (NotCopyable &&) noexcept=default
 
 NotCopyable (const NotCopyable &)=delete
 
NotCopyableoperator= (const NotCopyable &)=delete
 
- Protected Attributes inherited from DataLoader
std::string m_name
 
Cardinality m_cardinality = Cardinality::Fixed
 
Random::Generator m_randGenerator
 
DataLoaderList m_dataLoaders
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Constructor & Destructor Documentation

◆ PersistentCacheDataLoader()

PersistentCacheDataLoader ( std::unique_ptr< DataLoader > loader,
const std::string & location,
bool lazy = true,
bool reload = false,
bool compression = false,
bool shuffle = false,
bool verbose = false )
explicit

Constructs the caching data loader.

Parameters
loaderprevious loader
locationpath to the folder where all the data will be cached
lazycaches items when requested (otherwise caches the whole dataset at initialization)
reloadtry to reload the cache from a previous session
compressioncompresses the data when saving on disk
shufflereshuffle the order of the cache every epoch
Exceptions
DataLoaderExceptionif the nested loader is uncountable

Member Function Documentation

◆ next()

std::optional< DataItem > next ( )
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.

◆ size()

std::optional< size_t > size ( ) const
overridevirtual

The size of the loader is always known after the cache is fully generated (either lazily or not) If caching lazily and not reloading, 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.

◆ reset()

void reset ( )
overridevirtual

Resets the loader index but not the store cache This is to avoid reloading and caching the entire data set every time the iteration is consumed.

To force clear the cache, use PersistentCacheDataLoader::clearCache().

Reimplemented from DataLoader.

◆ reinit()

void reinit ( )
overridevirtual

Forces a cache destruction, i.e.

delete all files from the folder The cache is created at the next call of next.

Reimplemented from DataLoader.

◆ cardinality()

Cardinality cardinality ( ) const
overridevirtual

After caching, the number of items in the cache is known, and thus the cardinality is Fixed.

When caching lazily and not reloading, the cardinality is the same of the underlying loader until the cache is fully generated (first epoch typically), then is Fixed.

Reimplemented from DataLoader.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close