20#include "allheaders.h"
59 cached_x_scale_ = factor;
75 tprintf(
"Input::Backward should not be called!!\n");
84 const Network* network,
int min_width,
85 TRand* randomizer,
float* image_scale) {
90 &width, &height,
nullptr);
92 tprintf(
"Bad pix from ImageData!\n");
95 if (width < min_width || height < min_width) {
96 tprintf(
"Image too small to scale!! (%dx%d vs min width of %d)\n", width,
113 bool color = shape.
depth() == 3;
114 Pix* var_pix =
const_cast<Pix*
>(pix);
115 int depth = pixGetDepth(var_pix);
116 Pix* normed_pix =
nullptr;
122 normed_pix = pixClone(var_pix);
124 normed_pix = pixConvertTo32(var_pix);
128 normed_pix = pixClone(var_pix);
130 normed_pix = pixConvertTo8(var_pix,
false);
132 int height = pixGetHeight(normed_pix);
133 int target_height = shape.
height();
134 if (target_height == 1) target_height = shape.
depth();
135 if (target_height != 0 && target_height != height) {
137 float im_factor =
static_cast<float>(target_height) / height;
138 Pix* scaled_pix = pixScale(normed_pix, im_factor, im_factor);
139 pixDestroy(&normed_pix);
140 normed_pix = scaled_pix;
142 input->
FromPix(shape, normed_pix, randomizer);
143 pixDestroy(&normed_pix);
DLLSYM void tprintf(const char *format,...)
const int kMaxInputHeight
Pix * PreScale(int target_height, int max_height, float *scale_factor, int *scaled_width, int *scaled_height, GenericVector< TBOX > *boxes) const
void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output) override
Input(const STRING &name, int ni, int no)
static void PreparePixInput(const StaticShape &shape, const Pix *pix, TRand *randomizer, NetworkIO *input)
int XScaleFactor() const override
static Pix * 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
bool Serialize(TFile *fp) const override
bool DeSerialize(TFile *fp) override
virtual bool Serialize(TFile *fp) const
void FromPix(const StaticShape &shape, const Pix *pix, TRand *randomizer)
bool Serialize(TFile *fp) const
bool DeSerialize(TFile *fp)