19 #ifndef TESSERACT_LSTM_NETWORKIO_H_ 20 #define TESSERACT_LSTM_NETWORKIO_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;
108 return int_mode_ ? i_.
dim1() : f_.
dim1();
112 return int_mode_ ? i_.
dim2() : f_.
dim2();
119 const float*
f(
int t)
const {
123 const int8_t*
i(
int t)
const {
131 int_mode_ = is_quantized;
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);
215 float Max()
const {
return int_mode_ ? i_.
Max() : f_.
Max(); }
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];
332 static int GetPadding(
int num_features);
349 #endif // TESSERACT_LSTM_NETWORKIO_H_ void set_int_mode(bool is_quantized)
int BestLabel(int t, float *score) const
void ZeroTimeStepGeneral(int t, int offset, int num_features)
GENERIC_2D_ARRAY< float > * mutable_float_array()
void CopyWithXReversal(const NetworkIO &src)
void CombineOutputs(const NetworkIO &base_output, const NetworkIO &combiner_output)
void Print(int num) const
void AddTimeStepPart(int t, int offset, int num_features, float *inout) const
const float * f(int t) const
void SetActivations(int t, int label, float ok_score)
void set_stride_map(const StrideMap &map)
void MaxpoolBackward(const NetworkIO &fwd, const GENERIC_2D_ARRAY< int > &maxes)
void ClipVector(int t, float range)
void CopyTimeStepFrom(int dest_t, const NetworkIO &src, int src_t)
int CopyPacking(const NetworkIO &src, int feature_offset)
int BestChoiceOverRange(int t_start, int t_end, int not_this, int null_ch, float *rating, float *certainty) const
void MaxpoolTimeStep(int dest_t, const NetworkIO &src, int src_t, int *max_line)
void AddAllToFloat(const NetworkIO &src)
void WriteTimeStep(int t, const double *input)
void SubtractAllFromFloat(const NetworkIO &src)
void Copy2DImage(int batch, Pix *pix, float black, float contrast, TRand *randomizer)
const int8_t * i(int t) const
void Copy1DGreyImage(int batch, Pix *pix, float black, float contrast, TRand *randomizer)
void ResizeScaled(const NetworkIO &src, int x_scale, int y_scale, int num_features)
void Resize(const NetworkIO &src, int num_features)
void ZeroInvalidElements()
void Transpose(TransposedArray *dest) const
void CopyWithXYTranspose(const NetworkIO &src)
void CopyWithNormalization(const NetworkIO &src, const NetworkIO &scale)
void FromPixes(const StaticShape &shape, const std::vector< const Pix *> &pixes, TRand *randomizer)
void Func2Multiply3(const NetworkIO &v_io, int t, const double *w, double *product) const
void ComputeCombinerDeltas(const NetworkIO &fwd_deltas, const NetworkIO &base_output)
const StrideMap & stride_map() const
static float ProbToCertainty(float prob)
void ScoresOverRange(int t_start, int t_end, int choice, int null_ch, float *rating, float *certainty) const
void AddTimeStep(int t, double *inout) const
void WriteTimeStepPart(int t, int offset, int num_features, const double *input)
void CopyAll(const NetworkIO &src)
void FuncMultiply(const NetworkIO &v_io, int t, double *product)
void FuncMultiply3(int u_t, const NetworkIO &v_io, int v_t, const double *w, double *product) const
void FromPix(const StaticShape &shape, const Pix *pix, TRand *randomizer)
void CopyTimeStepGeneral(int dest_t, int dest_offset, int num_features, const NetworkIO &src, int src_t, int src_offset)
int PositionOfBestMatch(const GenericVector< int > &labels, int start, int end) const
void SetPixel(int t, int f, int pixel, float black, float contrast)
void CopyUnpacking(const NetworkIO &src, int feature_offset, int num_features)
void FuncMultiply3Add(const NetworkIO &v_io, int t, const double *w, double *product) const
double ScoreOfLabels(const GenericVector< int > &labels, int start) const
void ResizeToMap(bool int_mode, const StrideMap &stride_map, int num_features)
void ReadTimeStep(int t, double *output) const
void CopyWithYReversal(const NetworkIO &src)
void EnsureBestLabel(int t, int label)
void ScaleFloatBy(float factor)
void ResizeXTo1(const NetworkIO &src, int num_features)
void Resize2d(bool int_mode, int width, int num_features)
void ResizeFloat(const NetworkIO &src, int num_features)
bool AnySuspiciousTruth(float confidence_thr) const
const GENERIC_2D_ARRAY< float > & float_array() const
void Randomize(int t, int offset, int num_features, TRand *randomizer)