tensorflow/lite/tools/evaluation/stages/image_preprocessing_stage.cc
// Performs billinear interpolation for 3-channel RGB image.
// See: https://en.wikipedia.org/wiki/Bilinear_interpolation
Performs billinear interpolation for 3-channel RGB image.
Performs billinear interpolation for 3 - channel RGB image .
inline void ResizeBilinear(ImageData* image_data,
                           const ResizingParams& params) {
  tflite::ResizeBilinearParams resize_params;
  resize_params.align_corners = false;
  resize_params.half_pixel_centers = false;
  tflite::RuntimeShape input_shape({1, static_cast<int>(image_data->height),
                                    static_cast<int>(image_data->width),
                                    kNumChannels});
  int output_height, output_width;
  if (params.aspect_preserving()) {
    float ratio_w =
        params.target_size().width() / static_cast<float>(image_data->width);
    float ratio_h =
        params.target_size().height() / static_cast<float>(image_data->height);
    if (ratio_w >= ratio_h) {
      output_width = params.target_size().width();
      output_height = static_cast<int>(round(image_data->height * ratio_w));
    } else {
      output_width = static_cast<int>(round(image_data->width * ratio_h));
      output_height = params.target_size().height();
    }
  } else {
    output_height = params.target_size().height();
    output_width = params.target_size().width();
  }
  tflite::RuntimeShape output_size_dims({1, 1, 1, 2});
  std::vector<int32_t> output_size_data = {output_height, output_width};
  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::ResizeBilinear(
      resize_params, input_shape, image_data->data->data(), output_size_dims,
      output_size_data.data(), output_shape, output_data->data());
  image_data->height = output_height;
  image_data->width = output_width;
  image_data->data.reset(output_data);
}
inline void ResizeBilinear ( ImageData * image_data , const ResizingParams & params ) { tflite :: ResizeBilinearParams resize_params ; resize_params . align_corners = false ; resize_params . half_pixel_centers = false ; tflite :: RuntimeShape input_shape ( { 1 , static_cast < int > ( image_data -> height ) , static_cast < int > ( image_data -> width ) , kNumChannels } ) ; int output_height , output_width ; if ( params . aspect_preserving ( ) ) { float ratio_w = params . target_size ( ) . width ( ) / static_cast < float > ( image_data -> width ) ; float ratio_h = params . target_size ( ) . height ( ) / static_cast < float > ( image_data -> height ) ; if ( ratio_w >= ratio_h ) { output_width = params . target_size ( ) . width ( ) ; output_height = static_cast < int > ( round ( image_data -> height * ratio_w ) ) ; } else { output_width = static_cast < int > ( round ( image_data -> width * ratio_h ) ) ; output_height = params . target_size ( ) . height ( ) ; } } else { output_height = params . target_size ( ) . height ( ) ; output_width = params . target_size ( ) . width ( ) ; } tflite :: RuntimeShape output_size_dims ( { 1 , 1 , 1 , 2 } ) ; std :: vector < int32_t > output_size_data = { output_height , output_width } ; 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 :: ResizeBilinear ( resize_params , input_shape , image_data -> data -> data ( ) , output_size_dims , output_size_data . data ( ) , output_shape , output_data -> data ( ) ) ; image_data -> height = output_height ; image_data -> width = output_width ; image_data -> data . reset ( output_data ) ; }
Performs billinear interpolation for 3-channel RGB image.
Performs billinear interpolation for 3 - channel RGB image .
// TODO(b/143292772): Set this to true for more accurate behavior? // Calculates output size.