Beatmup
|
Image classifier base class. More...
#include <classifier.h>
Public Member Functions | |
Classifier (Context &context, ChunkCollection &data) | |
Creates a Classifier instance. More... | |
~Classifier () | |
const std::vector< float > & | operator() (AbstractBitmap &input) |
Classifies an image (blocking). More... | |
Job | start (AbstractBitmap &input) |
Initiates the classification of a given image. More... | |
const std::vector< float > & | getProbabilities () const |
Returns the last classification results. More... | |
Public Member Functions inherited from Beatmup::NNets::Model | |
Model (Context &context, std::initializer_list< AbstractOperation * > ops) | |
Instantiates a model from a list of operations interconnecting them in a feedforward fashion. More... | |
Model (Context &context) | |
Instantiates an empty model. More... | |
~Model () | |
void | append (AbstractOperation *newOp, bool connect=false) |
Adds a new operation to the model. More... | |
void | append (std::initializer_list< AbstractOperation * > newOps, bool connect=false) |
Adds new operations to the model. More... | |
void | addOperation (const std::string &opName, AbstractOperation *newOp) |
Adds a new operation to the model before another operation in the execution order. More... | |
void | addOperation (const AbstractOperation &operation, AbstractOperation *newOp) |
void | addConnection (const std::string &sourceOpName, const std::string &destOpName, int output=0, int input=0, int shuffle=0) |
Adds a connection between two given ops. More... | |
void | addOutput (const std::string &operation, int output=0) |
Enables reading output data from the model memory through getOutputData(). More... | |
void | addOutput (const AbstractOperation &operation, int output=0) |
const float * | getOutputData (size_t &numSamples, const std::string &operation, int output=0) const |
Reads data from the model memory. More... | |
const float * | getOutputData (size_t &numSamples, const AbstractOperation &operation, int output=0) const |
virtual void | prepare (GraphicPipeline &gpu, ChunkCollection &data) |
Prepares all operations: reads the model data from chunks and builds GPU programs. More... | |
bool | isReady () const |
void | execute (TaskThread &thread, GraphicPipeline *gpu) |
Runs the inference. More... | |
bool | isOperationInModel (const AbstractOperation &operation) const |
Checks if a specific operation makes part of the model. More... | |
AbstractOperation & | getFirstOperation () |
AbstractOperation & | getLastOperation () |
const AbstractOperation & | getFirstOperation () const |
const AbstractOperation & | getLastOperation () const |
size_t | getNumberOfOperations () const |
template<class OperationClass = AbstractOperation> | |
OperationClass & | getOperation (const std::string &operationName) |
Retrieves an operation by its name. More... | |
const ProgressTracking & | getPreparingProgress () const |
Returns model preparation progress tracking. More... | |
const ProgressTracking & | getInferenceProgress () const |
Returns inference progress tracking. More... | |
unsigned long | countMultiplyAdds () const |
Provides an estimation of the number of multiply-adds characterizing the model complexity. More... | |
unsigned long | countTexelFetches () const |
Provides an estimation of the total number of texels fetched by all the operations in the model per image. More... | |
size_t | getMemorySize () const |
Returns the amount of texture memory in bytes currently allocated by the model to run the inference. More... | |
Listing | serialize () const |
Returns serialized representation of the model as a Listing. More... | |
std::string | serializeToString () const |
Returns serialized representation of the model as a string. More... | |
void | setProfiler (Profiler *profiler) |
Attaches a profiler instance to meter the execution time per operation during the inference. More... | |
Public Member Functions inherited from Beatmup::GL::ProgramBank | |
ProgramBank (Context &context) | |
~ProgramBank () | |
GL::RenderingProgram * | operator() (GraphicPipeline &gpu, const std::string &code, bool enableExternalTextures=false) |
Provides a program given a fragment shader source code. More... | |
void | release (GraphicPipeline &gpu, GL::RenderingProgram *program) |
Marks a program as unused any more. More... | |
Public Member Functions inherited from Beatmup::Object | |
virtual | ~Object () |
Public Member Functions inherited from Beatmup::NNets::InferenceTask | |
InferenceTask (Model &model, ChunkCollection &data) | |
void | connect (AbstractBitmap &image, AbstractOperation &operation, int inputIndex=0) |
Connects an image to a specific operation input. More... | |
void | connect (AbstractBitmap &image, const std::string &operation, int inputIndex=0) |
Protected Attributes | |
Context & | context |
Protected Attributes inherited from Beatmup::NNets::Model | |
std::vector< AbstractOperation * > | ops |
model operations More... | |
ProgressTracking | preparingProgress |
model preparation progress More... | |
ProgressTracking | inferenceProgress |
inference progress More... | |
bool | ready |
if true , ops are connected to each other and storages are allocated More... | |
Protected Attributes inherited from Beatmup::GL::ProgramBank | |
Context & | context |
Protected Attributes inherited from Beatmup::NNets::InferenceTask | |
ChunkCollection & | data |
Model & | model |
Additional Inherited Members | |
Public Types inherited from Beatmup::AbstractTask | |
enum class | TaskDeviceRequirement { CPU_ONLY , GPU_OR_CPU , GPU_ONLY } |
Specifies which device (CPU and/or GPU) is used to run the task. More... | |
Static Public Member Functions inherited from Beatmup::AbstractTask | |
static ThreadIndex | validThreadCount (int number) |
Valid thread count from a given integer value. More... | |
Protected Member Functions inherited from Beatmup::NNets::Model | |
void | freeMemory () |
Frees all allocated storages. More... | |
Storage & | allocateStorage (GraphicPipeline &gpu, const Size size, bool forGpu=true, bool forCpu=false, const int pad=0, const int reservedChannels=0) |
Allocates a new storage. More... | |
Storage & | allocateFlatStorage (GraphicPipeline &gpu, const int size) |
Allocates a new flat storage. More... | |
GL::Vector & | allocateVector (GraphicPipeline &gpu, const int size) |
Allocates a vector that can be used as operation input or output. More... | |
InternalBitmap & | allocateTexture (GraphicPipeline &gpu, const Size size) |
Allocates a texture that can be used as operation input or output. More... | |
bool | isPreceding (const AbstractOperation &first, const AbstractOperation &second) const |
Checks whether an operation goes before another operation in the model according the ops execution order. More... | |
AbstractOperation * | operator[] (const std::string &operationName) |
const AbstractOperation * | operator[] (const std::string &operationName) const |
void | addConnection (AbstractOperation &source, AbstractOperation &dest, int output=0, int input=0, int shuffle=0) |
Image classifier base class.
Combines a runnable InferenceTask with a Model assuming Conv2D and Softmax are its first and last operations respectively.
Definition at line 35 of file classifier.h.
Classifier::Classifier | ( | Context & | context, |
ChunkCollection & | data | ||
) |
Creates a Classifier instance.
context | A context instance Classifier will use to store its internal data |
data | A ChunkCollection to access to the classifier model data |
Definition at line 29 of file classifier.cpp.
Classifier::~Classifier | ( | ) |
Definition at line 36 of file classifier.cpp.
const std::vector< float > & Classifier::operator() | ( | AbstractBitmap & | input | ) |
Classifies an image (blocking).
The very first call includes the model preparation and might be slow as hell. Subsequent calls only run the inference and are likely much faster.
[in] | input | The input image |
Definition at line 43 of file classifier.cpp.
Job Classifier::start | ( | AbstractBitmap & | input | ) |
Initiates the classification of a given image.
The call is non-blocking.
[in] | input | The input image |
Definition at line 50 of file classifier.cpp.
|
inline |
Returns the last classification results.
Definition at line 69 of file classifier.h.
|
protected |
Definition at line 37 of file classifier.h.