结果发现,在deconvolution中没有MPS这样的操作。tensorflow中最接近的类似物是conv2d_transpose。
是否可以在MPS默认操作之间进行某种类型的插件自定义操作?
发布于 2017-08-15 21:57:32
MPS现在在MPSCNNConvolutionTranspose X.13和tvOS/iOS 11中提供macOS。
发布于 2017-02-20 20:51:24
您可以编写自己的金属计算内核,并在MPS操作之间执行这些内核。
例如:
let commandBuffer = commandQueue.makeCommandBuffer()
. . .
// Do something with an MPSCNN layer:
layer1.encode(commandBuffer: commandBuffer, sourceImage: img1, destinationImage: img2)
// Perform your own compute kernel:
let encoder = commandBuffer.makeComputeCommandEncoder()
encoder.setComputePipelineState(yourOwnComputePipeline)
encoder.setTexture(img2.texture, at: 0)
encoder.setTexture(img3.texture, at: 1)
let threadGroupSize = MTLSizeMake(. . .)
let threadGroups = MTLSizeMake(img2.texture.width / threadGroupSize.width,
img2.texture.height / threadGroupSize.height, 1)
encoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupSize)
encoder.endEncoding()
// Do something with another MPSCNN layer:
layer2.encode(commandBuffer: commandBuffer, sourceImage: img3, destinationImage: img4)
. . .
commandBuffer.commit()您必须用金属阴影语言编写自己的计算内核,并将其加载到yourOwnComputePipeline对象中。然后,您可以随时将其编码到当前命令缓冲区中。
发布于 2017-03-23 19:00:58
我把这作为一个新的答案,因为这是一个不同的解决方案。
请注意,深度学习中的反褶积也被称为“转置卷积”,这意味着它与常规卷积相同,但其内核水平和垂直翻转。
因此,您应该能够使用一个常规的MPSCNNConvolution层,该层将您希望解压缩的MPSImage作为输入,并且使用与“前向”卷积步骤相同的内核,但水平和垂直地翻转。
与编写自己的计算内核相比,这样做的好处是可以使用来自MPS的非常快速的内核。
编辑:就是一个例子。假设您的conv内核权重如下所示:
1, 2, 3
4, 5, 6
7, 8, 9然后,在翻转内核之后,权重如下所示:
9, 8, 7
6, 5, 4
3, 2, 1换句话说,您需要复制权重数组并将其反转。记忆中的第一个权重如下所示:
1, 2, 3, 4, 5, 6, 7, 8, 9翻转的内核在内存中看起来是这样的,所以它只是原始内核,但顺序相反:
9, 8, 7, 6, 5, 4, 3, 2, 1然后你用那个反转的阵列做一个新的卷积层。这是你的解锁层。
我没有金属样例代码向您展示,但这与创建一个常规的MPSCNNConvolution层并没有什么不同。你只需要倒转层的重量。
https://stackoverflow.com/questions/42012337
复制相似问题