如何用边距初始化外部图像以进行卷积?

How to initialize External Image with Margins for convolution?

约束条件: 1. 有一个指向具有边距大小 (ImHeight,ImWidth) 的图像的指针 2.过滤器尺寸(FH,FW); FH,FW 为奇数 3.ActualImageHeight = ImHeight-2*(FH/2); ActualImageWidth = ImWidth-2*(FW/2);

如何:

  1. 使用指针初始化图像,使图像 (0,0) 为像素 (0,0) 而不是边距像素?
  2. 在不使用边界条件/钳位的情况下定义时间表 - 因为给定的图像指针内存已经占了边距

修改图片的最小坐标。您没有说明您使用的是 JIT 还是 AOT,但这是一个 JIT 实现。

Halide::Image input( ImWidth + 2 * FW, ImHeight + 2 * FH ), output;
input.set_min( -FW, -FH );
Func f;
f(x,y) = ( input( x - FW, y - FH ) + input( x + FW - 1, y + FH - 1 ) ) / 2;
output = f.realize( ImWidth, ImHeight );

对于 AOT:

  • input 使用 ImageParam
  • ImWidthImHeight 使用 Param<int> 使它们成为 AOT 函数的参数。
  • ImWidthImHeight 使用 int 将它们烘焙到 AOT 函数中。
  • inputf.output_buffer()的所有维度使用set_boundsset_stride。如果 ImWidthParam<int>.
  • ,这些需要 Exprs 所以将接受 ImWidth + 2 * FW