| 220 | } |
| 221 | |
| 222 | void warp_perspective::run_int8_test(Handle* handle) { |
| 223 | using Param = WarpPerspective::Param; |
| 224 | Checker<WarpPerspectiveForward> checker(handle); |
| 225 | UniformIntRNG input_rng{-128, 127}; |
| 226 | WarpPerspectiveMatRNG mat_rng; |
| 227 | class ResizeBy2xMatRNG : public RNG { |
| 228 | void gen(const TensorND& tensor_) override { |
| 229 | float* ptr = tensor_.ptr<float>(); |
| 230 | auto N = tensor_.layout.shape[0]; |
| 231 | megdnn_assert( |
| 232 | tensor_.layout.is_contiguous() && tensor_.layout.ndim == 3 && |
| 233 | tensor_.layout[1] == 3 && tensor_.layout[2] == 3); |
| 234 | for (size_t n = 0; n < N; ++n) { |
| 235 | // | 1 0 0 | |
| 236 | // mat = | 0 1 0 | |
| 237 | // | 0 0 2 | |
| 238 | // resize_2x |
| 239 | ptr[0] = ptr[4] = 1; |
| 240 | ptr[8] = 2; |
| 241 | ptr[1] = ptr[2] = ptr[3] = ptr[5] = ptr[6] = ptr[7] = 0; |
| 242 | ptr += 9; |
| 243 | } |
| 244 | } |
| 245 | } resize_2x_mat_rng; |
| 246 | if (handle->type() == Handle::HandleType::CUDA) { |
| 247 | // As currently the computation is performed in floating points instead |
| 248 | // of full int, it could be slightly different on GPU. |
| 249 | checker.set_epsilon(1.1).set_max_avg_error(7e-5); |
| 250 | } |
| 251 | checker.set_rng(0, &input_rng) |
| 252 | .set_rng(1, &mat_rng) |
| 253 | .set_dtype(0, dtype::Int8()) |
| 254 | .set_dtype(1, dtype::Float32()) |
| 255 | .set_dtype(2, dtype::Int8()) |
| 256 | .set_param( |
| 257 | {Param::InterpolationMode::LINEAR, Param::BorderMode::CONSTANT, |
| 258 | Param::Format::NCHW, 0.f}); |
| 259 | checker.execs({{99, 48, 17, 17}, {99, 3, 3}, {99, 48, 22, 22}}) |
| 260 | .execs({{12, 3, 224, 224}, {12, 3, 3}, {12, 3, 256, 256}}); |
| 261 | |
| 262 | checker.set_rng(1, &resize_2x_mat_rng); |
| 263 | checker.execs({{98, 48, 17, 17}, {98, 3, 3}, {98, 48, 34, 34}}) |
| 264 | .execs({{13, 3, 224, 224}, {13, 3, 3}, {13, 3, 448, 448}}); |
| 265 | } |
| 266 | |
| 267 | void warp_perspective::run_quint8_test(Handle* handle) { |
| 268 | using Param = WarpPerspective::Param; |