Beatmup
cnn.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 #include "../cnn_interface.h"
21 
22 namespace Beatmup {
23 
24  /**
25  x2 image upsampler using a convolutional neural network.
26  Implements a neural net inference using OpenGL ES 2.0-conformant shaders.
27  Used by Bitmap::Resampler. Only usable inside an AbstractTask, not intended to be directly used by the application.
28  */
30  private:
31  class Layer {
32  public:
34  private:
37  public:
38  Layer(GL::RecycleBin& recycleBin, GraphicPipeline& gpu, Storage& outputStorage, const char* sourceCode);
39 
41  void process(Context& ctx, GraphicPipeline& gpu, Layer** inputs, int inputsCount);
42 
44  return *output;
45  }
46  };
47 
48  static const int
49  L1_SIZE = 12,
50  L2_SIZE = 8,
51  L3_SIZE = 6,
52  L4_SIZE = 4,
53  STORAGE_SIZE = 14; // min number of recyclable textures to cover the entire dataflow during the inference
54 
56 
57  Layer
63 
65 
66  Layer::Storage& nextStorage(int& i) { return storage[i++ % STORAGE_SIZE]; }
67 
68  public:
71 
72  void process(GraphicPipeline& gpu, GL::TextureHandler& input, AbstractBitmap& output);
73  bool usesEs31Backend() const { return false; }
74  };
75 
76 }
A very basic class for any image.
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
Layer(GL::RecycleBin &recycleBin, GraphicPipeline &gpu, Storage &outputStorage, const char *sourceCode)
Definition: cnn.cpp:29
InternalBitmap & getOutput()
Definition: cnn.h:43
void process(Context &ctx, GraphicPipeline &gpu, GL::TextureHandler &input)
Definition: cnn.cpp:36
x2 image upsampler using a convolutional neural network.
Definition: cnn.h:29
GLES20X2UpsamplingNetwork(GL::RecycleBin &recycleBin, GraphicPipeline &gpu)
Definition: cnn.cpp:163
static const int L1_SIZE
Definition: cnn.h:49
void process(GraphicPipeline &gpu, GL::TextureHandler &input, AbstractBitmap &output)
Definition: cnn.cpp:87
Layer * layer1[L1_SIZE]
Definition: cnn.h:58
bool usesEs31Backend() const
Definition: cnn.h:73
InternalBitmap * storage[STORAGE_SIZE]
Definition: cnn.h:55
static const int L2_SIZE
Definition: cnn.h:50
static const int STORAGE_SIZE
Definition: cnn.h:53
static const int L4_SIZE
Definition: cnn.h:52
Layer * layer3[L3_SIZE]
Definition: cnn.h:60
Layer * layer2[L2_SIZE]
Definition: cnn.h:59
Layer * layer4[L4_SIZE]
Definition: cnn.h:61
static const int L3_SIZE
Definition: cnn.h:51
Layer::Storage & nextStorage(int &i)
Definition: cnn.h:66
Stores references to GPU resources that will not be used anymore and needed to be recycled in a threa...
Definition: recycle_bin.h:34
Internal low-level GPU control API.
Definition: pipeline.h:33
A GLSL program to process images.
Definition: image_shader.h:34
Bitmap whose memory is managed by the Beatmup engine.
Interface of x2 image upsampling using a convolutional neural network on GPU.
Definition: cnn_interface.h:29
Beatmup::Context * ctx