【发布时间】:2022-04-06 14:27:46
【问题描述】:
我对 CoreML 的自定义层的 MTLTexture 数组感到困惑。 在我的 mlmodel 中,自定义层的输入 MTLTexture 有 32 个通道,输出有 8 个通道。 MTLTexture 的数据类型是 16 位浮点数,或一半。所以输入的 texture_array 由 8 个切片组成,输出由 2 个切片组成。
func encode(commandBuffer: MTLCommandBuffer, inputs: [MTLTexture], outputs: [MTLTexture]) throws {
print(#function, inputs.count, outputs.count)
if let encoder = commandBuffer.makeComputeCommandEncoder() {
for i in 0..<inputs.count {
encoder.setTexture(inputs[i], index: 0)
encoder.setTexture(outputs[i], index: 1)
encoder.dispatch(pipeline: psPipeline, texture: inputs[i])
encoder.endEncoding()
}
}
}
在我的计算内核函数中
kernel void pixelshuffle(
texture2d_array<half, access::read> inTexture [[texture(0)]],
texture2d_array<half, access::write> outTexture [[texture(1)]],
ushort3 gid [[thread_position_in_grid]])
{
if (gid.x >= inTexture.get_width() || gid.y >= inTexture.get_height()
|| gid.z>=inTexture.get_array_size()){
return;
}
const half4 src = half4(inTexture.read(gid.xy, gid.z));
//do other things
}
)
如果输入输出的纹理数组是[C][H][W],对于gid=(0,0,0),src.rgba存放在哪些通道中,其通道中的rgba坐标是什么?
是 src.r [0][0][0], src.g[1][0][0], src.b [2][0][0], src.a [3][ 0][0] ? 或者 是 src.r [0][0][0], src.g[0][0][1], src.b [0][0][2], src.a [0][0][ 3] ?
如何在编码函数中获取输入纹理的原始数据并打印出来?
【问题讨论】:
-
cormel的自定义层没有commits,然后我commitencoder buffer,但是结果好像不稳定,可能每次都不一样,为什么? 'code'commandBuffer.commit() commandBuffer.waitUntilCompleted( )'代码'
标签: coreml