• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_RESIZE_BILINEAR_TESTER_H_
17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_RESIZE_BILINEAR_TESTER_H_
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include <gtest/gtest.h>
23 #include "tensorflow/lite/c/common.h"
24 #include "tensorflow/lite/schema/schema_generated.h"
25 
26 namespace tflite {
27 namespace xnnpack {
28 
29 class ResizeBilinearTester {
30  public:
31   ResizeBilinearTester() = default;
32   ResizeBilinearTester(const ResizeBilinearTester&) = delete;
33   ResizeBilinearTester& operator=(const ResizeBilinearTester&) = delete;
34 
BatchSize(int32_t batch_size)35   inline ResizeBilinearTester& BatchSize(int32_t batch_size) {
36     EXPECT_GT(batch_size, 0);
37     batch_size_ = batch_size;
38     return *this;
39   }
40 
BatchSize()41   inline int32_t BatchSize() const { return batch_size_; }
42 
Channels(int32_t channels)43   inline ResizeBilinearTester& Channels(int32_t channels) {
44     EXPECT_GT(channels, 0);
45     channels_ = channels;
46     return *this;
47   }
48 
Channels()49   inline int32_t Channels() const { return channels_; }
50 
InputHeight(int32_t input_height)51   inline ResizeBilinearTester& InputHeight(int32_t input_height) {
52     EXPECT_GT(input_height, 0);
53     input_height_ = input_height;
54     return *this;
55   }
56 
InputHeight()57   inline int32_t InputHeight() const { return input_height_; }
58 
InputWidth(int32_t input_width)59   inline ResizeBilinearTester& InputWidth(int32_t input_width) {
60     EXPECT_GT(input_width, 0);
61     input_width_ = input_width;
62     return *this;
63   }
64 
InputWidth()65   inline int32_t InputWidth() const { return input_width_; }
66 
OutputHeight(int32_t output_height)67   inline ResizeBilinearTester& OutputHeight(int32_t output_height) {
68     EXPECT_GT(output_height, 0);
69     output_height_ = output_height;
70     return *this;
71   }
72 
OutputHeight()73   inline int32_t OutputHeight() const { return output_height_; }
74 
OutputWidth(int32_t output_width)75   inline ResizeBilinearTester& OutputWidth(int32_t output_width) {
76     EXPECT_GT(output_width, 0);
77     output_width_ = output_width;
78     return *this;
79   }
80 
OutputWidth()81   inline int32_t OutputWidth() const { return output_width_; }
82 
AlignCorners(bool align_corners)83   ResizeBilinearTester& AlignCorners(bool align_corners) {
84     align_corners_ = align_corners;
85     return *this;
86   }
87 
AlignCorners()88   bool AlignCorners() const { return align_corners_; }
89 
HalfPixelCenters(bool half_pixel_centers)90   ResizeBilinearTester& HalfPixelCenters(bool half_pixel_centers) {
91     half_pixel_centers_ = half_pixel_centers;
92     return *this;
93   }
94 
HalfPixelCenters()95   bool HalfPixelCenters() const { return half_pixel_centers_; }
96 
97   void Test(TfLiteDelegate* delegate) const;
98 
99  private:
100   std::vector<char> CreateTfLiteModel() const;
101 
102   int32_t batch_size_ = 1;
103   int32_t channels_ = 1;
104   int32_t input_height_ = 1;
105   int32_t input_width_ = 1;
106   int32_t output_height_ = 1;
107   int32_t output_width_ = 1;
108   bool align_corners_ = false;
109   bool half_pixel_centers_ = false;
110 };
111 
112 }  // namespace xnnpack
113 }  // namespace tflite
114 
115 #endif  // TENSORFLOW_LITE_DELEGATES_XNNPACK_RESIZE_BILINEAR_TESTER_H_
116