20#include <allheaders.h>
33 :
Network(
NT_INPUT, name, shape.height(), shape.depth()), shape_(shape), cached_x_scale_(1) {
59 cached_x_scale_ = factor;
73 tprintf(
"Input::Backward should not be called!!\n");
82 TRand *randomizer,
float *image_scale) {
89 tprintf(
"Bad pix from ImageData!\n");
92 if (width < min_width || height < min_width) {
93 tprintf(
"Image too small to scale!! (%dx%d vs min width of %d)\n", width, height, min_width);
109 bool color = shape.
depth() == 3;
111 int depth = pixGetDepth(var_pix);
112 Image normed_pix =
nullptr;
118 normed_pix = var_pix.
clone();
120 normed_pix = pixConvertTo32(var_pix);
125 normed_pix = var_pix.
clone();
127 normed_pix = pixConvertTo8(var_pix,
false);
130 int height = pixGetHeight(normed_pix);
131 int target_height = shape.
height();
132 if (target_height == 1) {
133 target_height = shape.
depth();
135 if (target_height != 0 && target_height != height) {
137 float im_factor =
static_cast<float>(target_height) / height;
138 Image scaled_pix = pixScale(normed_pix, im_factor, im_factor);
140 normed_pix = scaled_pix;
142 input->
FromPix(shape, normed_pix, randomizer);
void tprintf(const char *format,...)
const int kMaxInputHeight
Image PreScale(int target_height, int max_height, float *scale_factor, int *scaled_width, int *scaled_height, std::vector< TBOX > *boxes) const
TESS_API Input(const std::string &name, int ni, int no)
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
int XScaleFactor() const override
static Image PrepareLSTMInputs(const ImageData &image_data, const Network *network, int min_width, TRand *randomizer, float *image_scale)
void CacheXScaleFactor(int factor) override
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
static void PreparePixInput(const StaticShape &shape, const Image pix, TRand *randomizer, NetworkIO *input)
bool Serialize(TFile *fp) const override
bool DeSerialize(TFile *fp) override
virtual bool Serialize(TFile *fp) const
void FromPix(const StaticShape &shape, const Image pix, TRand *randomizer)
bool Serialize(TFile *fp) const
bool DeSerialize(TFile *fp)