15#ifdef INCLUDE_TENSORFLOW
16# include <tensorflow/compiler/xla/array2d.h>
24 std::locale::global(std::locale(
""));
27#ifdef INCLUDE_TENSORFLOW
30 std::unique_ptr<xla::Array2D<int>> SetupArray(
int ysize,
int xsize,
int start) {
31 std::unique_ptr<xla::Array2D<int>> a(
new xla::Array2D<int>(ysize, xsize));
33 for (
int y = 0; y < ysize; ++y) {
34 for (
int x = 0; x < xsize; ++x) {
41 void SetupNetworkIO(NetworkIO *nio) {
42 std::vector<std::unique_ptr<xla::Array2D<int>>> arrays;
43 arrays.push_back(SetupArray(3, 4, 0));
44 arrays.push_back(SetupArray(4, 5, 12));
45 std::vector<std::pair<int, int>> h_w_sizes;
46 for (
size_t i = 0; i < arrays.size(); ++i) {
47 h_w_sizes.emplace_back(arrays[i].get()->height(), arrays[i].get()->width());
50 stride_map.SetStride(h_w_sizes);
51 nio->ResizeToMap(
true, stride_map, 2);
53 StrideMap::Index index(stride_map);
56 nio->SetPixel(index.t(), 0, 128 + value, 0.0f, 128.0f);
57 nio->SetPixel(index.t(), 1, 128 - value, 0.0f, 128.0f);
58 }
while (index.Increment());
66#ifdef INCLUDE_TENSORFLOW
69 int width = nio.
Width();
70 for (
int t = 0; t < width; ++t) {
83 int value = nio.
i(t)[0];
84 EXPECT_EQ(value, pos);
86 EXPECT_EQ(value, -pos);
89 EXPECT_EQ(nio.
i(next_t)[0], 0);
90 EXPECT_EQ(nio.
i(next_t)[1], 0);
97 EXPECT_EQ(next_t, 40);
99 LOG(
INFO) <<
"Skip test because of missing xla::Array2D";
106#ifdef INCLUDE_TENSORFLOW
108 SetupNetworkIO(&nio);
114 std::vector<int> expected_values = {8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2,
115 3, 27, 28, 29, 30, 31, 22, 23, 24, 25, 26,
116 17, 18, 19, 20, 21, 12, 13, 14, 15, 16};
120 int value = copy.
i(t)[0];
121 EXPECT_EQ(value, expected_values[pos]);
122 value = copy.
i(t)[1];
123 EXPECT_EQ(value, -expected_values[pos]);
126 EXPECT_EQ(copy.
i(next_t)[0], 0) <<
"Failure t = " << next_t;
127 EXPECT_EQ(copy.
i(next_t)[1], 0) <<
"Failure t = " << next_t;
134 EXPECT_EQ(next_t, 40);
136 LOG(
INFO) <<
"Skip test because of missing xla::Array2D";
143#ifdef INCLUDE_TENSORFLOW
145 SetupNetworkIO(&nio);
151 std::vector<int> expected_values = {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9,
152 8, 16, 15, 14, 13, 12, 21, 20, 19, 18, 17,
153 26, 25, 24, 23, 22, 31, 30, 29, 28, 27};
157 int value = copy.
i(t)[0];
158 EXPECT_EQ(value, expected_values[pos]);
159 value = copy.
i(t)[1];
160 EXPECT_EQ(value, -expected_values[pos]);
163 EXPECT_EQ(copy.
i(next_t)[0], 0) <<
"Failure t = " << next_t;
164 EXPECT_EQ(copy.
i(next_t)[1], 0) <<
"Failure t = " << next_t;
171 EXPECT_EQ(next_t, 40);
173 LOG(
INFO) <<
"Skip test because of missing xla::Array2D";
180#ifdef INCLUDE_TENSORFLOW
182 SetupNetworkIO(&nio);
188 std::vector<int> expected_values = {0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7,
189 11, 12, 17, 22, 27, 13, 18, 23, 28, 14, 19,
190 24, 29, 15, 20, 25, 30, 16, 21, 26, 31};
194 int value = copy.
i(t)[0];
195 EXPECT_EQ(value, expected_values[pos]);
196 value = copy.
i(t)[1];
197 EXPECT_EQ(value, -expected_values[pos]);
200 EXPECT_EQ(copy.
i(next_t)[0], 0);
201 EXPECT_EQ(copy.
i(next_t)[1], 0);
208 EXPECT_EQ(next_t, 40);
210 LOG(
INFO) <<
"Skip test because of missing xla::Array2D";
TEST_F(EuroText, FastLatinOCR)
void ZeroInvalidElements()
void CopyWithXReversal(const NetworkIO &src)
void CopyWithXYTranspose(const NetworkIO &src)
void Resize2d(bool int_mode, int width, int num_features)
void CopyWithYReversal(const NetworkIO &src)
const StrideMap & stride_map() const
const int8_t * i(int t) const
void SetPixel(int t, int f, int pixel, float black, float contrast)