From 8376eb7d3d890342a163e44290a1d4e7941fbfe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=B0=E9=98=85?= <43716063+Baiyuetribe@users.noreply.github.com> Date: Mon, 13 Jan 2025 22:39:59 +0800 Subject: [PATCH] ctest 6 --- src/layer/flip.cpp | 20 ++++++++++++-------- tests/test_flip.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/layer/flip.cpp b/src/layer/flip.cpp index 1013a72a5..7c571ea7e 100644 --- a/src/layer/flip.cpp +++ b/src/layer/flip.cpp @@ -458,7 +458,6 @@ int Flip::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) cons } else if (axis.w == 3) { - return 0; // 在线debug // dch3、dcw4、chw6 int axis0 = axis_ptr[0] < 0 ? 4 + axis_ptr[0] : axis_ptr[0]; int axis1 = axis_ptr[1] < 0 ? 4 + axis_ptr[1] : axis_ptr[1]; @@ -469,17 +468,19 @@ int Flip::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) cons // 对应dch,除w外,其余全翻转 for (int c = 0; c < channels; c++) { - int flipped_c = channels - 1 - c; // 翻转c维度 + int flipped_c = channels - 1 - c; for (int z = 0; z < d; z++) { - int flipped_d = d - 1 - z; // 翻转d维度 + int flipped_d = d - 1 - z; for (int i = 0; i < h; i++) { - const float* ptr = bottom_blob.channel(c).row(z * h + i); - float* outptr = const_cast(top_blob.channel(flipped_c).row(flipped_d * h + (h - 1 - i))); // 翻转h维度 - memcpy(outptr, ptr, w * sizeof(float)); // w维度保持不变 + // 修改前:const float* ptr = bottom_blob.channel(c).row(z * h + i); + // 修改为:使用depth()访问方式 + const float* ptr = bottom_blob.channel(c).depth(z).row(i); + float* outptr = const_cast(top_blob.channel(flipped_c).depth(flipped_d).row(h - 1 - i)); + memcpy(outptr, ptr, w * sizeof(float)); } } } @@ -520,9 +521,12 @@ int Flip::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) cons for (int i = 0; i < h; i++) { - const float* ptr = bottom_blob.channel(c).row(z * h + i); - float* outptr = const_cast(top_blob.channel(c).row(flipped_d * h + (h - 1 - i))); // 翻转h维度 + // const float* ptr = bottom_blob.channel(c).row(z * h + i); + // float* outptr = const_cast(top_blob.channel(c).row(flipped_d * h + (h - 1 - i))); // 翻转h维度 + // 修改为使用depth()访问方式 + const float* ptr = bottom_blob.channel(c).depth(z).row(i); + float* outptr = const_cast(top_blob.channel(c).depth(flipped_d).row(h - 1 - i)); // 翻转h维度 // 翻转w维度 for (int k = 0; k < w; k++) { diff --git a/tests/test_flip.cpp b/tests/test_flip.cpp index 7ebf787a4..e3097321b 100644 --- a/tests/test_flip.cpp +++ b/tests/test_flip.cpp @@ -124,9 +124,41 @@ static int test_flip_3() int main() { SRAND(7767517); - return 0 - || test_flip_0() - || test_flip_1() - || test_flip_2() - || test_flip_3(); + // return 0 + // || test_flip_0() + // || test_flip_1() + // || test_flip_2() + // || test_flip_3(); + + // debug 测出所有异常 + test_flip(RandomMat(2, 3, 4, 5), IntArrayMat(0)); + test_flip(RandomMat(3, 2, 4, 5), IntArrayMat(1)); + test_flip(RandomMat(4, 3, 2, 5), IntArrayMat(2)); + test_flip(RandomMat(2, 3, 1, 5), IntArrayMat(3)); + test_flip(RandomMat(6, 3, 4, 5), IntArrayMat(0, 1)); + test_flip(RandomMat(2, 3, 1, 6), IntArrayMat(0, 2)); + test_flip(RandomMat(5, 1, 2, 5), IntArrayMat(0, 3)); + test_flip(RandomMat(5, 2, 1, 5), IntArrayMat(1, 2)); + test_flip(RandomMat(4, 5, 2, 3), IntArrayMat(1, 3)); + test_flip(RandomMat(2, 6, 4, 5), IntArrayMat(2, 3)); + test_flip(RandomMat(6, 1, 4, 5), IntArrayMat(0, 1, 2)); + test_flip(RandomMat(5, 2, 1, 5), IntArrayMat(0, 1, 3)); + test_flip(RandomMat(4, 3, 3, 5), IntArrayMat(0, 2, 3)); + test_flip(RandomMat(4, 3, 4, 5), IntArrayMat(1, 2, 3)); + test_flip(RandomMat(6, 3, 3, 2), IntArrayMat(0, 1, 2, 3)); + + test_flip(RandomMat(2, 3, 5), IntArrayMat(0)); + test_flip(RandomMat(3, 3, 5), IntArrayMat(1)); + test_flip(RandomMat(4, 3, 5), IntArrayMat(2)); + test_flip(RandomMat(3, 1, 5), IntArrayMat(0, 1)); + test_flip(RandomMat(3, 2, 5), IntArrayMat(0, 2)); + test_flip(RandomMat(3, 3, 4), IntArrayMat(1, 2)); + test_flip(RandomMat(4, 3, 2), IntArrayMat(0, 1, 2)); + + test_flip(RandomMat(8, 2), IntArrayMat(-2)); + test_flip(RandomMat(16, 3), IntArrayMat(-1)); + test_flip(RandomMat(7, 2), IntArrayMat(-2, -1)); + + test_flip(RandomMat(18), IntArrayMat(-1)); + return 0; } \ No newline at end of file