tensorflow/lite/tools/evaluation/stages/image_preprocessing_stage.cc
// Pads the image to a pre-defined size.
Pads the image to a pre-defined size.
Pads the image to a pre - defined size .
inline void Pad(ImageData* image_data, const PaddingParams& params) {
  int output_width = params.target_size().width();
  int output_height = params.target_size().height();
  int pad_value = params.padding_value();
  tflite::PadParams pad_params;
  pad_params.left_padding_count = 4;
  std::uninitialized_fill_n(pad_params.left_padding, 4, 0);
  pad_params.left_padding[1] =
      static_cast<int>(round((output_height - image_data->height) / 2.0));
  pad_params.left_padding[2] =
      static_cast<int>(round((output_width - image_data->width) / 2.0));
  pad_params.right_padding_count = 4;
  std::uninitialized_fill_n(pad_params.right_padding, 4, 0);
  pad_params.right_padding[1] =
      output_height - pad_params.left_padding[1] - image_data->height;
  pad_params.right_padding[2] =
      output_width - pad_params.left_padding[2] - image_data->width;
  tflite::RuntimeShape input_shape({1, static_cast<int>(image_data->height),
                                    static_cast<int>(image_data->width),
                                    kNumChannels});
  tflite::RuntimeShape output_shape(
      {1, output_height, output_width, kNumChannels});
  int output_size = output_width * output_height * kNumChannels;
  std::vector<float>* output_data = new std::vector<float>(output_size, 0);
  tflite::reference_ops::Pad(pad_params, input_shape, image_data->data->data(),
                             &pad_value, output_shape, output_data->data());
  image_data->height = output_height;
  image_data->width = output_width;
  image_data->data.reset(output_data);
}
inline void Pad ( ImageData * image_data , const PaddingParams & params ) { int output_width = params . target_size ( ) . width ( ) ; int output_height = params . target_size ( ) . height ( ) ; int pad_value = params . padding_value ( ) ; tflite :: PadParams pad_params ; pad_params . left_padding_count = 4 ; std :: uninitialized_fill_n ( pad_params . left_padding , 4 , 0 ) ; pad_params . left_padding [ 1 ] = static_cast < int > ( round ( ( output_height - image_data -> height ) / 2.0 ) ) ; pad_params . left_padding [ 2 ] = static_cast < int > ( round ( ( output_width - image_data -> width ) / 2.0 ) ) ; pad_params . right_padding_count = 4 ; std :: uninitialized_fill_n ( pad_params . right_padding , 4 , 0 ) ; pad_params . right_padding [ 1 ] = output_height - pad_params . left_padding [ 1 ] - image_data -> height ; pad_params . right_padding [ 2 ] = output_width - pad_params . left_padding [ 2 ] - image_data -> width ; tflite :: RuntimeShape input_shape ( { 1 , static_cast < int > ( image_data -> height ) , static_cast < int > ( image_data -> width ) , kNumChannels } ) ; tflite :: RuntimeShape output_shape ( { 1 , output_height , output_width , kNumChannels } ) ; int output_size = output_width * output_height * kNumChannels ; std :: vector < float > * output_data = new std :: vector < float > ( output_size , 0 ) ; tflite :: reference_ops :: Pad ( pad_params , input_shape , image_data -> data -> data ( ) , & pad_value , output_shape , output_data -> data ( ) ) ; image_data -> height = output_height ; image_data -> width = output_width ; image_data -> data . reset ( output_data ) ; }
Pads the image to a pre-defined size.
Pads the image to a pre - defined size .