2
금속 CNN 코드를 작성하고 있습니다. Metal은 MPSCNNLocalContrastNormalization, 을 제공합니다. 인스턴스 정규화의 개념이 약간 다르므로이를 커널 기능으로 구현하려고합니다.인스턴스 정규화를 구현하려고합니다.
그러나 문제는 각 R, G, B에 대한 평균 및 분산은 커널 기능에서 입력에서 수신 한 텍스처의 특징이 R, G, B 일 때 얻어야한다는 것입니다. 이것을 구현하는 방법에 대한 힌트를 얻고 싶습니다.
kernel void instance_normalization_2darray(texture2d_array<float, access::sample> src [[ texture(0) ]],
texture2d_array<float, access::write> dst [[ texture(1) ]],
uint3 tid [[thread_position_in_grid]]) {
}
kernel void calculate_avgA(texture2d_array<float, access::read> texture_in [[texture(0)]],
texture2d_array<float, access::write> texture_out [[texture(1)]],
uint3 tid [[thread_position_in_grid]])
{
int width = texture_in.get_width();
int height = texture_in.get_height();
int depth = texture_in.get_array_size();
float4 outColor;
uint3 kernelIndex(0,0,0);
uint3 textureIndex(0,0,0);
for(int k = 0; k < depth; k++) {
outColor = (0.0, 0.0, 0.0, 0.0);
for (int i=0; i < width; i++)
{
for (int j=0; j < height; j++)
{
kernelIndex = uint3(i, j, k);
textureIndex = uint3(tid.x + i, tid.y + j, tid.z + k);
float4 color = texture_in.read(textureIndex.xy, textureIndex.z).rgba;
outColor += color;
}
}
outColor = outColor/(width * height);
texture_out.write(float4(outColor.rgba), tid.xy, textureIndex.z);
}
}
와우! 좋은 생각..!! mpscnnpoolingaverage로 평균 한 후에, 분산을 얻는 방법에 대한 몇 가지 힌트를 줄 수 있습니까? –
mpscnnpoolingaverage 다음에는 nchannelx1x1 (1x1 pixle)을 사용하여 mpstemporary 이미지를 얻을 수 있습니다. 그리고 나서 커널을 사용하여 원본 이미지의 서브 이미지의 서브 및 파워를 계산할 수 있으며 평균을 다시 풀면 분산이 발생합니다. – Ericking
그리고 Github의 MetalImage 프로젝트에서 INVIDA 최적화 알고리즘을 참조하여 감축 총계가있는 다른 알고리즘을 제공 할 것입니다. (https://github.com/erickingxu/MetalImage.git) – Ericking