Skip to content

Instantly share code, notes, and snippets.

@hewumars
Last active April 10, 2019 09:41
Show Gist options
  • Save hewumars/5c6ca42c4e34928ac0a1509de68093fb to your computer and use it in GitHub Desktop.
Save hewumars/5c6ca42c4e34928ac0a1509de68093fb to your computer and use it in GitHub Desktop.
图像矩阵维度索引,变换,permute

四维索引: Mat[((b*channels+c)*height+h)*width+w] Mat[B*channels*height*width+C*height*width+H*width+W]

要变换维度时,只有调换for循环位置到不同的循环层,例如yolo里面访问网格对应通道,代码如下 例如CHW-->HWC

//permute
        u32Offset = 0;
        ps32InputBlob = pps32InputData[i];
        u32ChnOffset = au32GridNumHeight[i]*au32Stride[i]/sizeof(HI_S32);
        u32HeightOffset = au32Stride[i]/sizeof(HI_S32);
        for (h = 0; h < au32GridNumHeight[i]; h++)
        {
            for (w = 0; w < au32GridNumWidth[i]; w++)
            {
                for (c = 0; c < SAMPLE_SVP_NNIE_YOLOV3_EACH_BBOX_INFER_RESULT_NUM*u32EachGridBbox; c++)
                {
                    pf32Permute[u32Offset++] = (HI_FLOAT)(ps32InputBlob[c*u32ChnOffset+h*u32HeightOffset+w]) / SAMPLE_SVP_NNIE_QUANT_BASE;
                }
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment