Ios 如何在MPSNNGRAPHER的输入端使用两个MPS图像
我试图在MPSNNGraph上输入两幅图像 然而,即使我在“withSourceImages”上输入类似[input1,input2]的数组,我也只能输入“input1”作为输入图像。理想情况下,在创建下图时,我希望将“inputImage1”设置为“input1”,将“inputImage2”设置为“input2” 事实上,当我像这样运行它并查看“concat”的结果时,我能够看到连接的是什么“input1”,而不是“input2” 图表如下所示:Ios 如何在MPSNNGRAPHER的输入端使用两个MPS图像,ios,swift,metal,metal-performance-shaders,Ios,Swift,Metal,Metal Performance Shaders,我试图在MPSNNGraph上输入两幅图像 然而,即使我在“withSourceImages”上输入类似[input1,input2]的数组,我也只能输入“input1”作为输入图像。理想情况下,在创建下图时,我希望将“inputImage1”设置为“input1”,将“inputImage2”设置为“input2” 事实上,当我像这样运行它并查看“concat”的结果时,我能够看到连接的是什么“input1”,而不是“input2” 图表如下所示: let inputImage1 = MPSN
let inputImage1 = MPSNNImageNode(handle: nil)
let inputImage2 = MPSNNImageNode(handle: nil)
let scale = MPSNNBilinearScaleNode(source: inputImage1,
outputSize: MTLSize(width:256,
height: 256,
depth: 3))
let scale2 = MPSNNBilinearScaleNode(source: inputImage1,
outputSize: MTLSize(width:64,
height: 64,
depth: 3))
...
let concat = MPSNNConcatenationNode(sources: [conv3.resultImage, scale2.resultImage])
...
if let graph = MPSNNGraph(device: commandQueue.device,
resultImage: tanh.resultImage,
resultImageIsNeeded: true){
self.graph = graph
}
let input1 = MPSImage(texture: texture, ...)
let input2 = MPSImage(texture: texture2, ...)
graph.executeAsync(withSourceImages: [input1, input2]) { outputImage, error in
...
}
编码图的一部分如下所示:
let inputImage1 = MPSNNImageNode(handle: nil)
let inputImage2 = MPSNNImageNode(handle: nil)
let scale = MPSNNBilinearScaleNode(source: inputImage1,
outputSize: MTLSize(width:256,
height: 256,
depth: 3))
let scale2 = MPSNNBilinearScaleNode(source: inputImage1,
outputSize: MTLSize(width:64,
height: 64,
depth: 3))
...
let concat = MPSNNConcatenationNode(sources: [conv3.resultImage, scale2.resultImage])
...
if let graph = MPSNNGraph(device: commandQueue.device,
resultImage: tanh.resultImage,
resultImageIsNeeded: true){
self.graph = graph
}
let input1 = MPSImage(texture: texture, ...)
let input2 = MPSImage(texture: texture2, ...)
graph.executeAsync(withSourceImages: [input1, input2]) { outputImage, error in
...
}
如何输入第二个输入,图形如何接收
你能给我一些建议吗?你提供的代码实际上看起来是正确的。此处引用MPSNNGraph.h标题:
* @param sourceImages A list of MPSImages to use as the source images for the graph.
* These should be in the same order as the list returned from
* MPSNNGraph.sourceImageHandles. They should be allocated against
* the same MTLDevice. There must be at least one source image.
* Note: this array is intended to handle the case where multiple
* input images are required to generate a single graph result.
* That is, the graph itself has multiple inputs. If you need to
* execute the graph multiple times, then call this API multiple
* times, or better yet use [encodeToCommandBuffer:sourceImages:]
* multiple times.
不过我想指出,MPSNNConcatenationNode的行为方式非常独特。它始终与深度(通道)尺寸有关。当用不同的空间尺寸浓缩图像时,它将尊重较小的图像(即2x2x10浓缩4x4x15->2x2x25)。可能这就是问题的来源。Scale2使用与本例中Scale1相同的输入图像。当MPSNNGraph分析这组节点时,它从未遇到inputImage2,因为它不被图使用。因为它不在图形中,所以图形接口将不接受第二个输入。它不知道该怎么办 在我看来,如果您将scale2初始化更改为使用inputImage2,那么它将按照您的预期工作