Beatmup
|
Image preprocessing operation. More...
#include <image_sampler.h>
Public Member Functions | |
ImageSampler (const std::string &name, const IntPoint &size, bool centerCrop=true, bool linearInterp=true) | |
Creates an instance of image preprocessing operation. More... | |
void | setCenterCrop (bool enable) |
Enables / disables center crop. More... | |
bool | getCenterCrop () const |
void | setLinearInterpolation (bool enable) |
Enables / disables linear interpolation. More... | |
bool | getLinearInterpolation () const |
void | setRotation (int quarterTurns) |
Specifies a rotation to apply to the input image. More... | |
int | getRotation () const |
Returns rotation applied to the input image. More... | |
int | getInputCount () const |
Returns number of operation inputs. More... | |
int | getOutputCount () const |
Returns number of operation outputs. More... | |
bool | acceptsTextureInput (int index=0) const |
Returns true if the operation can take a GL::TextureHandler at a specific input. More... | |
bool | acceptsTextureOutput (int index=0) const |
Returns true if the operation can take a GL::TextureHandler at a specific output. More... | |
Size | getOutputSize (int outputIndex=0) const |
Returns full size of a specific operation output. More... | |
void | getOutput (GL::TextureHandler *&texture, int index=0) |
Returns a GL::TextureHandler bound to a specific operation output. More... | |
void | setInput (GL::TextureHandler &texture, int inputIndex=0) |
void | setOutput (GL::TextureHandler &texture, int outputIndex=0) |
std::map< std::string, std::string > | serialize () const |
Returns a serialized representation of th operation;. More... | |
void | disconnect () |
Assigns empty inputs and outputs. More... | |
unsigned long | countTexelFetches () const |
Counts (approximate) number of texels fetches. More... | |
Public Member Functions inherited from Beatmup::NNets::AbstractOperation | |
virtual | ~AbstractOperation () |
virtual bool | usesGpu () const |
Returns true if the operation is run on GPU. More... | |
virtual bool | acceptsStorageInput (int index=0) const |
Returns true if the operation can take a Storage::View at a specific input. More... | |
virtual bool | acceptsVectorInput (int index=0) const |
Returns true if the operation can take a GL::Vector at a specific input. More... | |
virtual bool | acceptsStorageOutput (int index=0) const |
Returns true if the operation can take a Storage::View at a specific output. More... | |
virtual bool | acceptsVectorOutput (int index=0) const |
Returns true if the operation can take a GL::Vector at a specific output. More... | |
virtual Storage::View | getOutput (int index=0) |
Returns a storage view bound to a specific operation output. More... | |
virtual void | getOutput (GL::Vector *&vector, int index=0) |
Returns a GL::Vector bound to a specific operation output. More... | |
virtual void | setInput (Storage::View &&storage, int index=0) |
virtual void | setOutput (Storage::View &&storage, int index=0) |
virtual void | setInput (GL::Vector &vector, int index=0) |
virtual void | setOutput (GL::Vector &vector, int index=0) |
virtual unsigned long | countMultiplyAdds () const |
Counts (approximate) number of multiply-adds used by this operation. More... | |
std::string | getName () const |
Static Public Member Functions | |
static bool | initDeserializer () |
Sets up deserialization of the operation. More... | |
Private Member Functions | |
void | prepare (GraphicPipeline &gpu, ChunkCollection &data, GL::ProgramBank &bank) |
Compiles GLSL shaders. More... | |
void | execute (TaskThread &thread, GraphicPipeline &gpu) |
Executes the operation. More... | |
int | getInputPadding (int index=0) const |
Retrieves minimum required size of zero padding for a given input. More... | |
void | getSampledChannels (int index, int &min, int &max) const |
Retrieves range of input features channels sampled at the same time for a specific input. More... | |
Private Attributes | |
const IntPoint | size |
GL::TextureHandler * | input |
GL::TextureHandler * | output |
GL::RenderingProgram * | program |
bool | linearInterpolation |
if true , the input image is linearly interpolated when possible More... | |
bool | centerCrop |
if true , a center crop is performed to sample the output image from the input; otherwise the input is stretched to match the output shape More... | |
int | rotation |
clockwise rotation to apply to the input image; 1 unit = 90 degrees More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Beatmup::NNets::AbstractOperation | |
AbstractOperation (const std::string &name) | |
virtual void | execute (TaskThread &thread) |
Executes the operation within a specific CPU thread. More... | |
Image preprocessing operation.
Samples an image of a fixed size from an arbitrary size texture. Has three key missions. If enabled, performs a center crop keeping the output aspect ratio (otherwise the input is stretched to fit the output). If enabled, uses linear interpolation when possible to reduce aliasing (otherwise nearest neighbor sampling is used). Brings support of OES textures. This allows for example to read data directly from camera in Android.
Definition at line 32 of file image_sampler.h.
ImageSampler::ImageSampler | ( | const std::string & | name, |
const IntPoint & | size, | ||
bool | centerCrop = true , |
||
bool | linearInterp = true |
||
) |
Creates an instance of image preprocessing operation.
[in] | name | Layer name |
[in] | size | Output image size in pixels |
[in] | centerCrop | If true , the center crop is enabled |
[in] | linearInterp | If true , the linear interpolation is enabled |
Definition at line 28 of file image_sampler.cpp.
|
privatevirtual |
Compiles GLSL shaders.
[in,out] | gpu | A graphic pipeline instance |
[in,out] | data | Chunkfile containing operation data (e.g. weights and biases) |
[in,out] | bank | A program bank with existing GLSL programs to be reused when possible. If a new program is built, it is added to the bank. |
Implements Beatmup::NNets::AbstractOperation.
Definition at line 113 of file image_sampler.cpp.
|
privatevirtual |
Executes the operation.
The operation should be prepared.
[in,out] | thread | Calling CPU thread descriptor |
[in,out] | gpu | A graphic pipeline instance |
Implements Beatmup::NNets::AbstractOperation.
Definition at line 139 of file image_sampler.cpp.
|
inlineprivatevirtual |
Retrieves minimum required size of zero padding for a given input.
Operations that sample a neighborhood of a pixel may need the input to be padded with zeros, if some of the neighboring samples fall out of the are containing data. In Beatmup the zero padding is handled by allocating a bigger input and putting zeros around the area that is actually filled with data.
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 45 of file image_sampler.h.
|
inlineprivatevirtual |
Retrieves range of input features channels sampled at the same time for a specific input.
The operation would typically take the entire storage and sample it at once, if needed. If the number of textures in a storage exceeds the number of texture samplers that the GPU may use simultaneously, an exception occurs. This function provides the necessary information to limit the number of textures in the storage when allocating it. When the limit is reached, multiple channels are packed into a single texture in the storage.
[in] | index | The input index. Expected to fall in the valid range, i.e. from zero to getInputCount() - 1 inclusive. |
[out] | min | The minimum number of channels that can be sampled at once |
[out] | max | The maximum number of channels that can be sampled at once |
Implements Beatmup::NNets::AbstractOperation.
Definition at line 46 of file image_sampler.h.
|
inline |
|
inline |
Definition at line 67 of file image_sampler.h.
|
inline |
|
inline |
Definition at line 73 of file image_sampler.h.
|
inline |
Specifies a rotation to apply to the input image.
quarterTurns | Number of times a clockwise rotation by 90 degree is applied to the input image. |
Definition at line 79 of file image_sampler.h.
|
inline |
Returns rotation applied to the input image.
Definition at line 85 of file image_sampler.h.
|
inlinevirtual |
Returns number of operation inputs.
Inputs are then indexed from zero to the returned value minus one inclusive.
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 87 of file image_sampler.h.
|
inlinevirtual |
Returns number of operation outputs.
Outputs are then indexed from zero to the returned value minus one inclusive.
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 88 of file image_sampler.h.
|
inlinevirtual |
Returns true
if the operation can take a GL::TextureHandler at a specific input.
Neural network operations may accept different kinds of data containers on inputs and outputs, namely Storage::View, GL::Vector and textures. This function is used to check whether a given operation accepts a texture on input.
[in] | index | The input index. Expected to fall in the valid range, i.e. from zero to getInputCount() - 1 inclusive. |
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 90 of file image_sampler.h.
|
inlinevirtual |
Returns true
if the operation can take a GL::TextureHandler at a specific output.
Neural network operations may accept different kinds of data containers on outputs and outputs, namely Storage::View, GL::Vector and textures. This function is used to check whether a given operation accepts a texture on output.
[in] | index | The output index. Expected to fall in the valid range, i.e. from zero to getOutputCount() - 1 inclusive. |
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 91 of file image_sampler.h.
|
inlinevirtual |
Returns full size of a specific operation output.
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 93 of file image_sampler.h.
|
virtual |
Returns a GL::TextureHandler bound to a specific operation output.
[out] | vector | Pointer to the GL::TextureHandler. If no texture is bound, becomes null. |
[in] | index | The output index. Expected to fall in the valid range, i.e. from zero to getOutputCount() - 1 inclusive. |
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 41 of file image_sampler.cpp.
|
virtual |
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 47 of file image_sampler.cpp.
|
virtual |
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 53 of file image_sampler.cpp.
|
virtual |
Returns a serialized representation of th operation;.
Implements Beatmup::NNets::AbstractOperation.
Definition at line 90 of file image_sampler.cpp.
|
virtual |
Assigns empty inputs and outputs.
Implements Beatmup::NNets::AbstractOperation.
Definition at line 102 of file image_sampler.cpp.
|
virtual |
Counts (approximate) number of texels fetches.
Reimplemented from Beatmup::NNets::AbstractOperation.
Definition at line 108 of file image_sampler.cpp.
|
static |
Sets up deserialization of the operation.
|
private |
Definition at line 34 of file image_sampler.h.
|
private |
Definition at line 35 of file image_sampler.h.
|
private |
Definition at line 35 of file image_sampler.h.
|
private |
Definition at line 36 of file image_sampler.h.
|
private |
if true
, the input image is linearly interpolated when possible
Definition at line 37 of file image_sampler.h.
|
private |
if true
, a center crop is performed to sample the output image from the input; otherwise the input is stretched to match the output shape
Definition at line 38 of file image_sampler.h.
|
private |
clockwise rotation to apply to the input image; 1 unit = 90 degrees
Definition at line 41 of file image_sampler.h.