【问题标题】:Transforming MPSNNImageNode using Metal Performance Shader使用 Metal Performance Shader 转换 MPSNNImageNode
【发布时间】:2018-03-22 04:39:14
【问题描述】:

我目前正在使用 MPS 在 iOS (Swift4) 上复制 YOLOv2(不是小)。

一个问题是我很难实现 space_to_depth 函数 (https://www.tensorflow.org/api_docs/python/tf/space_to_depth) 和两个卷积结果的串联 (13x13x256 + 13x13x1024 -> 13x13x1280)。你能给我一些关于制作这些零件的建议吗?我的代码如下。

...



let conv19 = MPSCNNConvolutionNode(source: conv18.resultImage,

                                 weights: DataSource("conv19", 3, 3, 1024, 1024))



let conv20 = MPSCNNConvolutionNode(source: conv19.resultImage,

                                 weights: DataSource("conv20", 3, 3, 1024, 1024))



let conv21 = MPSCNNConvolutionNode(source: conv13.resultImage,

                                 weights: DataSource("conv21", 1, 1, 512, 64))



/*****

    1. space_to_depth with conv21

    2. concatenate the result of conv20(13x13x1024) to the result of 1 (13x13x256)

    I need your help to implement this part!

******/

【问题讨论】:

    标签: ios neural-network swift4 yolo metal-performance-shaders


    【解决方案1】:
    1. 我相信space_to_depth可以用卷积的形式表示: 例如,对于维度为[1,2,2,1] 的输入,使用4 个卷积核,每个核将一个数字输出到一个通道,即。 [[1,0],[0,0]] [[0,1],[0,0]] [[0,0],[1,0]] [[0,0],[0,1]],这应该把所有输入数字从空间维度放到深度维度。

    2. MPS 实际上有一个 concat 节点。见这里:https://developer.apple.com/documentation/metalperformanceshaders/mpsnnconcatenationnode

      你可以这样使用它: concatNode = [[MPSNNConcatenationNode alloc] initWithSources:@[layerA.resultImage, layerB.resultImage]];

    【讨论】:

      【解决方案2】:

      如果您正在使用高级接口和 MPSNNGraph,您应该只使用 MPSNNConcatenationNode,如上面刘天宇所述。

      如果您正在使用低级接口,对自己周围的 MPSKernel 进行人工处理,那么这是通过以下方式完成的:

      1. 创建一个 1280 通道目标图像来保存结果
      2. 正常运行第一个过滤器以生成结果的前 256 个通道
      3. 运行第二个过滤器以生成剩余通道,将 destinationFeatureChannelOffset 设置为 256。

      这在所有情况下都应该足够了,除非数据不是 MPSKernel 的产物。在这种情况下,您需要自己复制它或使用线性神经元 (a=1,b=0) 之类的东西来完成。

      【讨论】:

        猜你喜欢
        • 2019-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-08
        • 2019-01-27
        • 1970-01-01
        • 2016-04-24
        • 2017-01-25
        相关资源
        最近更新 更多