PriorBoxOp.swift 2.9 KB
Newer Older
L
update  
liuruilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License. */
L
liuruilong 已提交
14 15 16

import Foundation

L
liuruilong 已提交
17
class PriorBoxParam<P: PrecisionProtocol>: OpParam {
L
liuruilong 已提交
18 19 20 21 22 23 24
    //typealias ParamPrecisionType = P
    required init(opDesc: PMOpDesc, inScope: Scope) throws {
        do {
            min_max_aspect_ratios_order = try PriorBoxParam.getAttr(key: "min_max_aspect_ratios_order", attrs: opDesc.attrs)
        } catch _ {
        }
        
25 26 27 28 29 30 31 32 33 34 35 36 37
        input = try PriorBoxParam.input(inputs: opDesc.inputs, from: inScope)
        output = try PriorBoxParam.outputBoxes(outputs: opDesc.outputs, from: inScope)
        inputImage = try PriorBoxParam.inputImage(inputs: opDesc.inputs, from: inScope)
        outputVariances = try PriorBoxParam.outputVariances(outputs: opDesc.outputs, from: inScope)
        minSizes = try PriorBoxParam.getAttr(key: "min_sizes", attrs: opDesc.attrs)
        maxSizes = try PriorBoxParam.getAttr(key: "max_sizes", attrs: opDesc.attrs)
        aspectRatios = try PriorBoxParam.getAttr(key: "aspect_ratios", attrs: opDesc.attrs)
        variances = try PriorBoxParam.getAttr(key: "variances", attrs: opDesc.attrs)
        flip = try PriorBoxParam.getAttr(key: "flip", attrs: opDesc.attrs)
        clip = try PriorBoxParam.getAttr(key: "clip", attrs: opDesc.attrs)
        stepW = try PriorBoxParam.getAttr(key: "step_w", attrs: opDesc.attrs)
        stepH = try PriorBoxParam.getAttr(key: "step_h", attrs: opDesc.attrs)
        offset = try PriorBoxParam.getAttr(key: "offset", attrs: opDesc.attrs)
L
liuruilong 已提交
38 39
    }
    
L
liuruilong 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    var min_max_aspect_ratios_order: Bool = false
    let minSizes: [Float32]
    let maxSizes: [Float32]
    let aspectRatios: [Float32]
    var newAspectRatios: MTLBuffer?
    let variances: [Float32]
    let flip: Bool
    let clip: Bool
    var stepW: Float32
    var stepH: Float32
    let offset: Float32
    
    let input: Texture
    let inputImage: Texture
    var output: Texture
    let outputVariances: Texture
L
liuruilong 已提交
56 57
}

L
liuruilong 已提交
58
class PriorBoxOp<P: PrecisionProtocol>: Operator<PriorBoxKernel<P>, PriorBoxParam<P>>, Runable, Creator, InferShaperable{
D
xx  
dolphin8 已提交
59
    
L
liuruilong 已提交
60
    typealias OpType = PriorBoxOp<P>
D
xx  
dolphin8 已提交
61
    
L
liuruilong 已提交
62 63
    func inferShape() {
    }
L
liuruilong 已提交
64
    
L
liuruilong 已提交
65
    func runImpl(device: MTLDevice, buffer: MTLCommandBuffer) throws {
66
        try kernel.compute(commandBuffer: buffer, param: para)
L
liuruilong 已提交
67
    }
L
liuruilong 已提交
68
    
L
liuruilong 已提交
69 70
    func delogOutput() {
        print(" \(type) output: ")
71
        para.output.delog()
L
liuruilong 已提交
72
    }
L
liuruilong 已提交
73 74 75 76
}