19 #ifndef TESSERACT_LSTM_NETWORKIO_H_ 20 #define TESSERACT_LSTM_NETWORKIO_H_ 26 #include "genericvector.h" 28 #include "static_shape.h" 29 #include "stridemap.h" 30 #include "weightmatrix.h" 85 void Copy2DImage(
int batch, Pix* pix,
float black,
float contrast,
100 void SetPixel(
int t,
int f,
int pixel,
float black,
float contrast);
104 void Print(
int num)
const;
119 const float*
f(
int t)
const {
123 const int8_t*
i(
int t)
const {
146 const NetworkIO& src,
int src_t,
int src_offset);
151 void Randomize(
int t,
int offset,
int num_features,
TRand* randomizer);
155 float* rating,
float* certainty)
const;
158 float* rating,
float* certainty)
const;
167 int BestLabel(
int t,
int not_this,
int not_that,
float* score)
const;
199 void AddTimeStepPart(
int t,
int offset,
int num_features,
float* inout)
const;
205 const double* input);
258 template <
class Func>
265 const int8_t* u =
i_[t];
266 const int8_t* v = v_io.
i_[t];
267 for (
int i = 0;
i < dim; ++
i) {
268 product[
i] =
f(u[
i] / static_cast<double>(INT8_MAX)) * v[
i] /
269 static_cast<double>(INT8_MAX);
272 const float* u =
f_[t];
273 const float* v = v_io.
f_[t];
274 for (
int i = 0;
i < dim; ++
i) {
275 product[
i] =
f(u[
i]) * v[
i];
282 template <
class Func>
284 double* product)
const {
288 const float* u =
f_[u_t];
289 const float* v = v_io.
f_[v_t];
291 for (
int i = 0;
i < dim; ++
i) {
292 product[
i] =
f(u[
i]) * v[
i] * w[
i];
298 template <
class Func>
300 double* product)
const {
304 const float* u =
f_[t];
305 const float* v = v_io.
f_[t];
307 for (
int i = 0;
i < dim; ++
i) {
308 product[
i] +=
f(u[
i]) * v[
i] * w[
i];
314 template <
class Func1,
class Func2>
316 double* product)
const {
321 const float* u =
f_[t];
322 const float* v = v_io.
f_[t];
324 for (
int i = 0;
i < dim; ++
i) {
325 product[
i] =
f(u[
i]) * g(v[i]) * w[
i];
349 #endif // TESSERACT_LSTM_NETWORKIO_H_ Definition: intsimdmatrix.h:61
float Max() const
Definition: networkio.h:215
void MaxpoolBackward(const NetworkIO &fwd, const GENERIC_2D_ARRAY< int > &maxes)
Definition: networkio.cpp:700
void FromPixes(const StaticShape &shape, const std::vector< const Pix *> &pixes, TRand *randomizer)
Definition: networkio.cpp:175
void Randomize(int t, int offset, int num_features, TRand *randomizer)
Definition: networkio.cpp:421
void CopyAll(const NetworkIO &src)
Definition: networkio.cpp:816
void ZeroTimeStep(int t)
Definition: networkio.h:148
void ScoresOverRange(int t_start, int t_end, int choice, int null_ch, float *rating, float *certainty) const
Definition: networkio.cpp:455
void SetPixel(int t, int f, int pixel, float black, float contrast)
Definition: networkio.cpp:280
void SetActivations(int t, int label, float ok_score)
Definition: networkio.cpp:542
void FuncMultiply3Add(const NetworkIO &v_io, int t, const double *w, double *product) const
Definition: networkio.h:299
Definition: static_shape.h:38
void FuncMultiply(const NetworkIO &v_io, int t, double *product)
Definition: networkio.h:259
float MinOfMaxes() const
Definition: networkio.cpp:717
GENERIC_2D_ARRAY< float > f_
Definition: networkio.h:335
void ZeroTimeStepGeneral(int t, int offset, int num_features)
Definition: networkio.cpp:412
static float ProbToCertainty(float prob)
Definition: networkio.cpp:573
void Func2Multiply3(const NetworkIO &v_io, int t, const double *w, double *product) const
Definition: networkio.h:315
void Copy1DGreyImage(int batch, Pix *pix, float black, float contrast, TRand *randomizer)
Definition: networkio.cpp:251
int BestLabel(int t, float *score) const
Definition: networkio.h:161
int NumFeatures() const
Definition: networkio.h:111
void ClipVector(int t, float range)
Definition: networkio.cpp:976
void ResizeScaled(const NetworkIO &src, int x_scale, int y_scale, int num_features)
Definition: networkio.cpp:67
void ResizeXTo1(const NetworkIO &src, int num_features)
Definition: networkio.cpp:75
int dim1() const
Definition: matrix.h:206
void AddTimeStepPart(int t, int offset, int num_features, float *inout) const
Definition: networkio.cpp:634
void WriteTimeStepPart(int t, int offset, int num_features, const double *input)
Definition: networkio.cpp:656
void FuncMultiply3(int u_t, const NetworkIO &v_io, int v_t, const double *w, double *product) const
Definition: networkio.h:283
const GENERIC_2D_ARRAY< float > & float_array() const
Definition: networkio.h:139
void AddAllToFloat(const NetworkIO &src)
Definition: networkio.cpp:822
Definition: baseapi.cpp:94
GENERIC_2D_ARRAY< int8_t > i_
Definition: networkio.h:336
void CopyWithXYTranspose(const NetworkIO &src)
Definition: networkio.cpp:896
void EnsureBestLabel(int t, int label)
Definition: networkio.cpp:554
int dim2() const
Definition: matrix.h:207
static int GetPadding(int num_features)
Definition: networkio.cpp:987
Pix * ToPix() const
Definition: networkio.cpp:291
GENERIC_2D_ARRAY< float > * mutable_float_array()
Definition: networkio.h:140
bool int_mode() const
Definition: networkio.h:127
void ReadTimeStep(int t, double *output) const
Definition: networkio.cpp:603
int Width() const
Definition: networkio.h:107
Definition: weightmatrix.h:33
NetworkIO()
Definition: networkio.h:41
void CopyWithNormalization(const NetworkIO &src, const NetworkIO &scale)
Definition: networkio.cpp:836
void set_stride_map(const StrideMap &map)
Definition: networkio.h:136
void CopyTimeStepFrom(int dest_t, const NetworkIO &src, int src_t)
Definition: networkio.cpp:388
void CopyTimeStepGeneral(int dest_t, int dest_offset, int num_features, const NetworkIO &src, int src_t, int src_offset)
Definition: networkio.cpp:398
void Copy2DImage(int batch, Pix *pix, float black, float contrast, TRand *randomizer)
Definition: networkio.cpp:213
const float * f(int t) const
Definition: networkio.h:119
void FromPix(const StaticShape &shape, const Pix *pix, TRand *randomizer)
Definition: networkio.cpp:166
float * f(int t)
Definition: networkio.h:115
void ResizeFloat(const NetworkIO &src, int num_features)
Definition: networkio.h:52
void MaxpoolTimeStep(int dest_t, const NetworkIO &src, int src_t, int *max_line)
Definition: networkio.cpp:673
static IntSimdMatrix * multiplier_
Definition: networkio.h:344
void CopyWithYReversal(const NetworkIO &src)
Definition: networkio.cpp:858
void ScaleFloatBy(float factor)
Definition: networkio.h:234
void Zero()
Definition: networkio.cpp:82
T Max() const
Definition: matrix.h:342
void Print(int num) const
Definition: networkio.cpp:371
void Resize2d(bool int_mode, int width, int num_features)
Definition: networkio.cpp:40
int CopyPacking(const NetworkIO &src, int feature_offset)
Definition: networkio.cpp:922
void set_int_mode(bool is_quantized)
Definition: networkio.h:130
void ZeroInvalidElements()
Definition: networkio.cpp:93
StrideMap stride_map_
Definition: networkio.h:340
void Resize(const NetworkIO &src, int num_features)
Definition: networkio.h:45
void ComputeCombinerDeltas(const NetworkIO &fwd_deltas, const NetworkIO &base_output)
Definition: networkio.cpp:775
double ScoreOfLabels(const GenericVector< int > &labels, int start) const
Definition: networkio.cpp:530
void CombineOutputs(const NetworkIO &base_output, const NetworkIO &combiner_output)
Definition: networkio.cpp:741
void AddTimeStep(int t, double *inout) const
Definition: networkio.cpp:618
Definition: stridemap.h:43
Definition: networkio.h:39
void CopyUnpacking(const NetworkIO &src, int feature_offset, int num_features)
Definition: networkio.cpp:950
int BestChoiceOverRange(int t_start, int t_end, int not_this, int null_ch, float *rating, float *certainty) const
Definition: networkio.cpp:436
void CopyWithXReversal(const NetworkIO &src)
Definition: networkio.cpp:877
void SubtractAllFromFloat(const NetworkIO &src)
Definition: networkio.cpp:829
void WriteTimeStep(int t, const double *input)
Definition: networkio.cpp:650
int PositionOfBestMatch(const GenericVector< int > &labels, int start, int end) const
Definition: networkio.cpp:512
bool int_mode_
Definition: networkio.h:338
const StrideMap & stride_map() const
Definition: networkio.h:133
void ResizeToMap(bool int_mode, const StrideMap &stride_map, int num_features)
Definition: networkio.cpp:51
void Transpose(TransposedArray *dest) const
Definition: networkio.cpp:969
const int8_t * i(int t) const
Definition: networkio.h:123
bool AnySuspiciousTruth(float confidence_thr) const
Definition: networkio.cpp:584