21 #include "allheaders.h" 60 cached_x_scale_ = factor;
76 tprintf(
"Input::Backward should not be called!!\n");
85 const Network* network,
int min_width,
86 TRand* randomizer,
float* image_scale) {
91 &width, &height,
nullptr);
93 tprintf(
"Bad pix from ImageData!\n");
96 if (width <= min_width || height < min_width) {
97 tprintf(
"Image too small to scale!! (%dx%d vs min width of %d)\n", width,
114 bool color = shape.
depth() == 3;
115 Pix* var_pix =
const_cast<Pix*
>(pix);
116 int depth = pixGetDepth(var_pix);
117 Pix* normed_pix =
nullptr;
123 normed_pix = pixClone(var_pix);
125 normed_pix = pixConvertTo32(var_pix);
129 normed_pix = pixClone(var_pix);
131 normed_pix = pixConvertTo8(var_pix,
false);
133 int height = pixGetHeight(normed_pix);
134 int target_height = shape.
height();
135 if (target_height == 1) target_height = shape.
depth();
136 if (target_height != 0 && target_height != height) {
138 float im_factor =
static_cast<float>(target_height) / height;
139 Pix* scaled_pix = pixScale(normed_pix, im_factor, im_factor);
140 pixDestroy(&normed_pix);
141 normed_pix = scaled_pix;
143 input->
FromPix(shape, normed_pix, randomizer);
144 pixDestroy(&normed_pix);
bool Serialize(TFile *fp) const override
Input(const STRING &name, int ni, int no)
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Pix * PreScale(int target_height, int max_height, float *scale_factor, int *scaled_width, int *scaled_height, GenericVector< TBOX > *boxes) const
virtual bool Serialize(TFile *fp) const
bool Serialize(TFile *fp) const
void CacheXScaleFactor(int factor) override
DLLSYM void tprintf(const char *format,...)
const int kMaxInputHeight
bool Backward(bool debug, const NetworkIO &fwd_deltas, NetworkScratch *scratch, NetworkIO *back_deltas) override
int XScaleFactor() const override
static void PreparePixInput(const StaticShape &shape, const Pix *pix, TRand *randomizer, NetworkIO *input)
void FromPix(const StaticShape &shape, const Pix *pix, TRand *randomizer)
bool DeSerialize(TFile *fp)
bool DeSerialize(TFile *fp) override
static Pix * PrepareLSTMInputs(const ImageData &image_data, const Network *network, int min_width, TRand *randomizer, float *image_scale)