espressif / esp-dl

Espressif deep-learning library for AIoT applications
MIT License
519 stars 116 forks source link

Matrix Slicing #18

Closed caleb221 closed 4 years ago

caleb221 commented 4 years ago

Hello! I would like to make sure I am using the dl_matrix3d_slice_copy() function correctly.

Suppose I have a matrix with the shape (1,1,1,48) And I would like to slice the second half into a copy. Proper usage would look like this: input shape = (1,1,1,48) output shape = (1,1,1,24)

dl_matrix3d_slice_copy(output,input,24,2,1,1);

This code does execute, but i believe it is poisoning my heap as I will get an error later. I have tried multiple combinations of numbers but one thing remains unclear. is the x-offset the end point and w the start point? Thanks!

--if it helps, this error occurs when using light impact heap debugging does NOT occur when using basic (no debugging) both using

heap_caps_check_integrity_all(true) and looks like

CORRUPT HEAP: Bad tail at 0x3fff63fc. Expected 0xbaad5678 got 0xbb819f89 Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. Core 1 register dump: PC : 0x4008ad3c PS : 0x00060633 A0 : 0x8008a6fd A1 : 0x3ffc1180
0x4008ad3c: is_free at /home/caleb/esp/esp-idf/components/heap/multi_heap.c:131 (inlined by) multi_heap_malloc_impl at /home/caleb/esp/esp-idf/components/heap/multi_heap.c:432

XiaochaoGONG commented 4 years ago

This slice only works on planar, i.e. slicing in width and height dimension, all channels remain.

caleb221 commented 4 years ago

Oh I think i see, so if i wanted half of a 3dmatrix (same channels) it would be something like input shape: (1,12,12,28)

    dl_matrix3d_t *half_1 = dl_matrix3d_alloc(1,6,6,28);
    dl_matrix3d_t *half_2 = dl_matrix3d_alloc(1,6,6,28);
    int x = (input->h)/2;
    int y = (input->w)/2;
    dl_matrix3du_slice_copy(half_1, input, x, y, 6, 6);
    dl_matrix3du_slice_copy(half_2, input, x*2, y*2, 6, 6);
XiaochaoGONG commented 4 years ago

dl_matrix3du_slice_copy(half_1, input, x, y, 6, 6); dl_matrix3du_slice_copy(half_2, input, x2, y2, 6, 6);

dl_matrix3du_slice_copy(half_1, input, 0, 0, 6, 6);
dl_matrix3du_slice_copy(half_2, input, x, y, 6, 6);
caleb221 commented 4 years ago

oh ok awesome! Thank you!