Beatmup
classifier.cpp
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 #include "classifier.h"
20 #include "conv2d.h"
21 #include "dense.h"
22 #include "pooling2d.h"
23 #include "softmax.h"
24 
25 using namespace Beatmup;
26 using namespace NNets;
27 
28 
30  Model(context),
31  InferenceTask(*this, data),
32  context(context)
33 {}
34 
35 
37  for (auto op : ops)
38  delete op;
39  ops.clear();
40 }
41 
42 
43 const std::vector<float>& Classifier::operator()(AbstractBitmap& input) {
44  connect(input, *ops[0], 0);
45  context.performTask(*this);
46  return getProbabilities();
47 }
48 
49 
51  connect(input, *ops[0], 0);
52  return context.submitTask(*this);
53 }
A very basic class for any image.
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Definition: chunkfile.h:36
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Definition: context.cpp:240
Job submitTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Adds a new task to the jobs queue.
Definition: context.cpp:248
const std::vector< float > & getProbabilities() const
Returns the last classification results.
Definition: classifier.h:69
Classifier(Context &context, ChunkCollection &data)
Creates a Classifier instance.
Definition: classifier.cpp:29
const std::vector< float > & operator()(AbstractBitmap &input)
Classifies an image (blocking).
Definition: classifier.cpp:43
Job start(AbstractBitmap &input)
Initiates the classification of a given image.
Definition: classifier.cpp:50
Task running inference of a Model.
void connect(AbstractBitmap &image, AbstractOperation &operation, int inputIndex=0)
Connects an image to a specific operation input.
Neural net model.
Definition: model.h:92
std::vector< AbstractOperation * > ops
model operations
Definition: model.h:122
int Job
Definition: parallelism.h:69
jlong jint op