Beatmup
classifier.h
Go to the documentation of this file.
1
/*
2
Beatmup image and signal processing library
3
Copyright (C) 2020, lnstadrum
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#pragma once
20
21
#include "
model.h
"
22
#include "
inference_task.h
"
23
#include "../bitmap/abstract_bitmap.h"
24
#include "
softmax.h
"
25
#include <vector>
26
#include <initializer_list>
27
28
29
namespace
Beatmup
{
30
namespace
NNets {
31
/**
32
Image classifier base class.
33
Combines a runnable InferenceTask with a Model assuming Conv2D and Softmax are its first and last operations respectively.
34
*/
35
class
Classifier
:
public
Model
,
public
InferenceTask
{
36
protected
:
37
Context
&
context
;
38
39
public
:
40
/**
41
Creates a Classifier instance.
42
\param context A context instance Classifier will use to store its internal data
43
\param data A ChunkCollection to access to the classifier model data
44
*/
45
Classifier
(
Context
&
context
,
ChunkCollection
&
data
);
46
~Classifier
();
47
48
/**
49
Classifies an image (blocking).
50
The very first call includes the model preparation and might be slow as hell. Subsequent calls only run the inference and are likely
51
much faster.
52
\param[in] input The input image
53
\return a vector of probabilities per class.
54
*/
55
const
std::vector<float>&
operator()
(
AbstractBitmap
& input);
56
57
/**
58
Initiates the classification of a given image.
59
The call is non-blocking.
60
\param[in] input The input image
61
\return a job corresponding to the submitted task.
62
*/
63
Job
start
(
AbstractBitmap
& input);
64
65
/**
66
Returns the last classification results.
67
\return a vector of probabilities per class.
68
*/
69
inline
const
std::vector<float>&
getProbabilities
()
const
{
70
return
static_cast<
const
Softmax
&
>
(
getLastOperation
()).
getProbabilities
();
71
}
72
};
73
}
74
}
Beatmup::AbstractBitmap
A very basic class for any image.
Definition:
abstract_bitmap.h:87
Beatmup::ChunkCollection
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Definition:
chunkfile.h:36
Beatmup::Context
Basic class: task and memory management, any kind of static data.
Definition:
context.h:59
Beatmup::NNets::Classifier
Image classifier base class.
Definition:
classifier.h:35
Beatmup::NNets::Classifier::getProbabilities
const std::vector< float > & getProbabilities() const
Returns the last classification results.
Definition:
classifier.h:69
Beatmup::NNets::Classifier::Classifier
Classifier(Context &context, ChunkCollection &data)
Creates a Classifier instance.
Definition:
classifier.cpp:29
Beatmup::NNets::Classifier::operator()
const std::vector< float > & operator()(AbstractBitmap &input)
Classifies an image (blocking).
Definition:
classifier.cpp:43
Beatmup::NNets::Classifier::context
Context & context
Definition:
classifier.h:37
Beatmup::NNets::Classifier::~Classifier
~Classifier()
Definition:
classifier.cpp:36
Beatmup::NNets::Classifier::start
Job start(AbstractBitmap &input)
Initiates the classification of a given image.
Definition:
classifier.cpp:50
Beatmup::NNets::InferenceTask
Task running inference of a Model.
Definition:
inference_task.h:33
Beatmup::NNets::InferenceTask::data
ChunkCollection & data
Definition:
inference_task.h:44
Beatmup::NNets::Model
Neural net model.
Definition:
model.h:92
Beatmup::NNets::Model::getLastOperation
AbstractOperation & getLastOperation()
Definition:
model.h:294
Beatmup::NNets::Softmax
Softmax layer.
Definition:
softmax.h:32
inference_task.h
model.h
Beatmup
Definition:
basic_types.h:22
Beatmup::Job
int Job
Definition:
parallelism.h:69
softmax.h
core
nnets
classifier.h
Generated on Tue Nov 21 2023 13:54:27 for Beatmup by
1.9.1