23 using namespace NNets;
30 const std::string&
name,
39 op(
op), padding(padding),
40 ready(false), program(nullptr)
59 code.
line(
"void main() {");
73 code.
line(
" vec4 r;");
79 code(i == 0 ?
"r = (" :
"r = max(r, ");
83 code.
line(
"gl_FragColor = r;");
129 for (
int channel = 0; channel <
input.
getDepth(); channel += 4) {
154 if (outputIndex == 0) {
167 this->
input = std::move(view);
173 this->
output = std::move(storage);
180 {
"_type",
"pooling2d" },
192 Pooling2DDeserializer() : Deserializer(
"pooling2d") {}
208 block.
get<
int>(
"size"),
209 block.
get<
int>(
"stride", 1),
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Basic class: task and memory management, any kind of static data.
static const CustomPoint ZERO
void enable(const GraphicPipeline &gpu)
Stores linked GLSL programs and their associated fragment shader codes.
void release(GraphicPipeline &gpu, GL::RenderingProgram *program)
Marks a program as unused any more.
void blend(bool onScreen)
static const char * DECLARE_TEXTURE_COORDINATES_IN_FRAG
Declaring texture coordinates in fragment shader.
Internal low-level GPU control API.
void setTextureCoordinates(const Rectangle &coords)
Specifies texture coordinates for the next rendering pass.
static void insanity(const char *message)
static void check(const bool condition, const std::string &message)
T get(const std::string &key) const
Returns a value by key casted to a given type.
Enables construction of an operation from its serialized representation.
Abstract neural net operation (layer).
std::string getName() const
Operator
Pooling operator specification.
void setOutput(Storage::View &&storage, int outputIndex=0)
void getSampledChannels(int index, int &min, int &max) const
Retrieves range of input features channels sampled at the same time for a specific input.
Size getOutputSize(int outputIndex=0) const
Returns full size of a specific operation output.
std::map< std::string, std::string > serialize() const
Returns a serialized representation of th operation;.
void setInput(Storage::View &&storage, int inputIndex=0)
Pooling2D(const std::string &name, const Operator op, const int size, const int stride=1, const Size::Padding padding=Size::Padding::VALID)
2D pooling layer.
void disconnect()
Assigns empty inputs and outputs.
int getInputPadding(int index=0) const
Retrieves minimum required size of zero padding for a given input.
const Size::Padding padding
static Operator operatorFromString(const std::string &str)
Returns a pooling operator from string.
void execute(TaskThread &thread, GraphicPipeline &gpu)
Executes the operation.
GL::RenderingProgram * program
static bool initDeserializer()
Sets up deserialization of the operation.
void prepare(GraphicPipeline &gpu, ChunkCollection &data, GL::ProgramBank &bank)
Compiles GLSL shaders.
unsigned long countTexelFetches() const
Counts (approximate) number of texels fetches.
Operation 3D input/output size.
Padding
Zero padding specification.
@ SAME
operation output size matches its input size for unit strides
Size transform(Size kernel, Size stride, Padding padding, int depth=0) const
Computes operation output size in function of operation kernel, padding, stride and depth,...
Generates GLSL fragment shader code sampling a local neighborhood around the current texture coordina...
void sampleInline(StringBuilder &code, const char *inputName, const int inputIndex, const IntPoint &position, const Point &shift, const char *suffix="")
void setup(const int width, const int height)
Prepares the spatial filtering operation execution.
void writeHeader(StringBuilder &code, bool useUniformShift)
Writes out the very GLSL fragment shader header required for spatial neighborhood sampling.
void declare(StringBuilder &code, const char *datatype, bool inlineSampling=false)
Declares GLSL fragment shader main(..) code part required for spatial neighborhood sampling.
void setupProgram(GL::Program &program)
Prepares a given program for spatial filtering.
IntRectangle getSamplingArea(const IntPoint &size, const IntPoint &stride, const Size::Padding padding) const
Implements common padding policies by computing a rectangular area of positions the sampling kernel t...
void setUniformShift(GL::Program &program, const IntPoint &shift, const IntPoint &inputSize)
Applies an offset to the sampling position at runtime.
Binding of different input/output storages/texture handlers to a GLSL program.
Maps a 3D tensor onto a storage.
int getTextureHeight() const
Returns height in pixels of all the textures.
IntPoint getChannelOrigin(int channel) const
Returns origin in pixels of a given channel within the texture containing it.
IntPoint getTextureSize() const
IntPoint getSpatialSize() const
Returns the spatial size (width and height) of the storage in pixels.
int getTextureWidth() const
Returns width in pixels of all the textures.
static void checkMin(const datatype value, const datatype min, const char *message)
static void check(const datatype value, const datatype min, const datatype max, const char *message)
static void check(const bool condition, const std::string &message)
StringBuilder & line(const std::string &append)
StringBuilder & printf(const char *format,...)
StringBuilder including a string container.
Size::Padding paddingFromString(const std::string &str)
Returns a zero padding value from a string.
std::string lowercase(const std::string &str)
Converts a string to lower case (latin letters only).
CustomPoint< int > IntPoint
std::string to_string(Beatmup::NNets::ActivationFunction function)
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
static const char * UNIFORM_INPUT
return(jlong) new Beatmup jlong jstring name
JNIEnv jobject jstring str