2017-02-20 10 views
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); 
    } 
} 

답변

0

enter image description here

Mr.Bista 나는 사과가 빠른 속도로이에 대한 몇 가지 기능을 제공하지 않았다, 이것에 대한 동일한 문제가 있었다. 그리고 저는 커널 이전에 caculate mean을 위해서 MPSCNNPoolingAverage를 사용합니다. 아마도 임시적인 방법 일 수 있습니다. 그리고 다른 알고리즘은 코드로 테스트 한 후에 감산 합계 알고리즘과 같이 이것보다 좋지 않습니다. 그래서 더 나은 구현을 추적 할 것입니다.

+0

와우! 좋은 생각..!! mpscnnpoolingaverage로 평균 한 후에, 분산을 얻는 방법에 대한 몇 가지 힌트를 줄 수 있습니까? –

+0

mpscnnpoolingaverage 다음에는 nchannelx1x1 (1x1 pixle)을 사용하여 mpstemporary 이미지를 얻을 수 있습니다. 그리고 나서 커널을 사용하여 원본 이미지의 서브 이미지의 서브 및 파워를 계산할 수 있으며 평균을 다시 풀면 분산이 발생합니다. – Ericking

+0

그리고 Github의 MetalImage 프로젝트에서 INVIDA 최적화 알고리즘을 참조하여 감축 총계가있는 다른 알고리즘을 제공 할 것입니다. (https://github.com/erickingxu/MetalImage.git) – Ericking