| 81 | } |
| 82 | |
| 83 | void Expect(const Tensor& input, float x_min, float x_max, |
| 84 | bool output_range_given, float give_y_min, float given_y_max) { |
| 85 | Scope root = Scope::NewRootScope(); |
| 86 | |
| 87 | auto input_ph = Placeholder(root, DT_QUINT8); |
| 88 | |
| 89 | const float variance_eps = 1e-5; |
| 90 | auto instance_norm = QuantizedInstanceNorm( |
| 91 | root, input_ph, x_min, x_max, |
| 92 | QuantizedInstanceNorm::Attrs().VarianceEpsilon(variance_eps)); |
| 93 | |
| 94 | Status s = root.status(); |
| 95 | EXPECT_TRUE(s.ok()); |
| 96 | |
| 97 | ClientSession session(root); |
| 98 | std::vector<Tensor> outputs; |
| 99 | |
| 100 | s = session.Run({{input_ph, input}}, |
| 101 | {instance_norm.y, instance_norm.y_min, instance_norm.y_max}, |
| 102 | &outputs); |
| 103 | |
| 104 | EXPECT_TRUE(s.ok()); |
| 105 | Tensor expected(DT_FLOAT, input.shape()); |
| 106 | |
| 107 | ReferenceImpl(input.flat<quint8>().data(), x_min, x_max, input.shape(), |
| 108 | variance_eps, expected.flat<float>().data()); |
| 109 | |
| 110 | auto out = outputs[0].flat<quint8>(); |
| 111 | |
| 112 | float out_min = outputs[1].flat<float>()(0); |
| 113 | float out_max = outputs[2].flat<float>()(0); |
| 114 | float out_scale = (out_max - out_min) / 255.0f; |
| 115 | |
| 116 | Eigen::Tensor<float, 0, Eigen::RowMajor> max_diff = |
| 117 | (expected.flat<float>() - (out_min + out_scale * out.cast<float>())) |
| 118 | .abs() |
| 119 | .maximum(); |
| 120 | EXPECT_LE(max_diff(), 0.1); |
| 121 | LOG(INFO) << "max diff " << max_diff(); |
| 122 | } |
| 123 | |
| 124 | void TestBasic() { |
| 125 | Tensor input_tensor(DT_QUINT8, {1, 4, 4, 32}); |
no test coverage detected