From 01aea0414b13162cff30b23d8d498e90f1debd81 Mon Sep 17 00:00:00 2001 From: liuruilong Date: Fri, 7 Sep 2018 15:36:17 +0800 Subject: [PATCH] add objc interface --- .../project.pbxproj | 18 ------ .../paddle-mobile.xcodeproj/project.pbxproj | 14 ++++- .../paddle-mobile}/CPUCompute.h | 0 .../paddle-mobile}/CPUCompute.mm | 0 .../paddle-mobile}/Genet.swift | 28 +++++---- .../paddle-mobile}/MobileNet.swift | 6 +- .../paddle-mobile}/MobileNetSSD.swift | 38 ++++++------ .../paddle-mobile/PaddleMobile.swift | 61 ++++++++++--------- .../paddle-mobile/PaddleMobileGPU.h | 4 +- .../paddle-mobile/PaddleMobileGPU.m | 19 ++++++ .../paddle-mobile/paddle_mobile.h | 2 +- 11 files changed, 101 insertions(+), 89 deletions(-) rename metal/{paddle-mobile-demo/paddle-mobile-demo/Net => paddle-mobile/paddle-mobile}/CPUCompute.h (100%) rename metal/{paddle-mobile-demo/paddle-mobile-demo/Net => paddle-mobile/paddle-mobile}/CPUCompute.mm (100%) rename metal/{paddle-mobile-demo/paddle-mobile-demo/Net => paddle-mobile/paddle-mobile}/Genet.swift (74%) rename metal/{paddle-mobile-demo/paddle-mobile-demo/Net => paddle-mobile/paddle-mobile}/MobileNet.swift (95%) rename metal/{paddle-mobile-demo/paddle-mobile-demo/Net => paddle-mobile/paddle-mobile}/MobileNetSSD.swift (84%) diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj b/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj index 5cdb9dfd7b..4e9fcf8e74 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj +++ b/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj @@ -14,10 +14,6 @@ FC039B8720E11C550081E9F8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FC039B8520E11C550081E9F8 /* Main.storyboard */; }; FC039B8920E11C560081E9F8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FC039B8820E11C560081E9F8 /* Assets.xcassets */; }; FC039B8C20E11C560081E9F8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FC039B8A20E11C560081E9F8 /* LaunchScreen.storyboard */; }; - FC27991321343A3A000B6BAD /* CPUCompute.mm in Sources */ = {isa = PBXBuildFile; fileRef = FC27991221343A3A000B6BAD /* CPUCompute.mm */; }; - FC3C800F2133F46600D1295E /* MobileNetSSD.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC3C800E2133F46600D1295E /* MobileNetSSD.swift */; }; - FC3C80112133F4AB00D1295E /* MobileNet.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC3C80102133F4AB00D1295E /* MobileNet.swift */; }; - FC8CFEE2213524EA0094D569 /* Genet.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC8CFEE1213524EA0094D569 /* Genet.swift */; }; FC8CFEE62135452C0094D569 /* genet_params in Resources */ = {isa = PBXBuildFile; fileRef = FC8CFEE42135452B0094D569 /* genet_params */; }; FC8CFEE72135452C0094D569 /* genet_model in Resources */ = {isa = PBXBuildFile; fileRef = FC8CFEE52135452B0094D569 /* genet_model */; }; FC8CFEF8213551D10094D569 /* params in Resources */ = {isa = PBXBuildFile; fileRef = FC8CFEF6213551D00094D569 /* params */; }; @@ -61,12 +57,7 @@ FC039B8B20E11C560081E9F8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; FC039B8D20E11C560081E9F8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; FC27991121343A39000B6BAD /* paddle-mobile-demo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "paddle-mobile-demo-Bridging-Header.h"; sourceTree = ""; }; - FC27991221343A3A000B6BAD /* CPUCompute.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CPUCompute.mm; sourceTree = ""; }; - FC27991421343A46000B6BAD /* CPUCompute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPUCompute.h; sourceTree = ""; }; - FC3C800E2133F46600D1295E /* MobileNetSSD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileNetSSD.swift; sourceTree = ""; }; - FC3C80102133F4AB00D1295E /* MobileNet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileNet.swift; sourceTree = ""; }; FC4FD97B2140EE250073E130 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; }; - FC8CFEE1213524EA0094D569 /* Genet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Genet.swift; sourceTree = ""; }; FC8CFEE42135452B0094D569 /* genet_params */ = {isa = PBXFileReference; lastKnownFileType = file; path = genet_params; sourceTree = ""; }; FC8CFEE52135452B0094D569 /* genet_model */ = {isa = PBXFileReference; lastKnownFileType = file; path = genet_model; sourceTree = ""; }; FC8CFEF6213551D00094D569 /* params */ = {isa = PBXFileReference; lastKnownFileType = file; path = params; sourceTree = ""; }; @@ -178,11 +169,6 @@ children = ( FC013927210204A3008100E3 /* PreProcessKernel.metal */, FCBCCC542122EF5400D94F7E /* MetalHelper.swift */, - FC3C800E2133F46600D1295E /* MobileNetSSD.swift */, - FC3C80102133F4AB00D1295E /* MobileNet.swift */, - FC27991221343A3A000B6BAD /* CPUCompute.mm */, - FC27991421343A46000B6BAD /* CPUCompute.h */, - FC8CFEE1213524EA0094D569 /* Genet.swift */, ); path = Net; sourceTree = ""; @@ -341,11 +327,7 @@ files = ( FC039B8420E11C550081E9F8 /* ViewController.swift in Sources */, FC013928210204A3008100E3 /* PreProcessKernel.metal in Sources */, - FC8CFEE2213524EA0094D569 /* Genet.swift in Sources */, FCBCCC552122EF5500D94F7E /* MetalHelper.swift in Sources */, - FC27991321343A3A000B6BAD /* CPUCompute.mm in Sources */, - FC3C80112133F4AB00D1295E /* MobileNet.swift in Sources */, - FC3C800F2133F46600D1295E /* MobileNetSSD.swift in Sources */, FC039B8220E11C550081E9F8 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj b/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj index d0f4b38df6..37b29b65bb 100644 --- a/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj +++ b/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj @@ -41,8 +41,11 @@ FC0E2DBE20EE460D009C1FAC /* BatchNormKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E2DBD20EE460D009C1FAC /* BatchNormKernel.swift */; }; FC0E2DC020EE461F009C1FAC /* ElementwiseAddKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E2DBF20EE461F009C1FAC /* ElementwiseAddKernel.swift */; }; FC1B16B320EC9A4F00678B91 /* Kernels.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC1B16B220EC9A4F00678B91 /* Kernels.metal */; }; - FC292C5421421B2F00CF622F /* PaddleMobileGPU.h in Headers */ = {isa = PBXBuildFile; fileRef = FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */; }; + FC292C5421421B2F00CF622F /* PaddleMobileGPU.h in Headers */ = {isa = PBXBuildFile; fileRef = FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */; settings = {ATTRIBUTES = (Public, ); }; }; FC292C5621421B4600CF622F /* PaddleMobileGPU.m in Sources */ = {isa = PBXBuildFile; fileRef = FC292C5521421B4600CF622F /* PaddleMobileGPU.m */; }; + FC292C81214255BD00CF622F /* CPUCompute.mm in Sources */ = {isa = PBXBuildFile; fileRef = FC292C7C214255BC00CF622F /* CPUCompute.mm */; }; + FC292C82214255BD00CF622F /* MobileNetSSD.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC292C7E214255BC00CF622F /* MobileNetSSD.swift */; }; + FC292C85214257CB00CF622F /* CPUCompute.h in Headers */ = {isa = PBXBuildFile; fileRef = FC292C7D214255BC00CF622F /* CPUCompute.h */; settings = {ATTRIBUTES = (Public, ); }; }; FC3602CC2108819F00FACB58 /* PaddleMobileUnitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC3602CB2108819F00FACB58 /* PaddleMobileUnitTest.swift */; }; FC4CB74920F0B954007C0C6D /* ConvKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC4CB74820F0B954007C0C6D /* ConvKernel.metal */; }; FC4CB74B20F12C30007C0C6D /* ProgramOptimize.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4CB74A20F12C30007C0C6D /* ProgramOptimize.swift */; }; @@ -141,6 +144,9 @@ FC27990D21341016000B6BAD /* BoxCoder.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = BoxCoder.metal; sourceTree = ""; }; FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaddleMobileGPU.h; sourceTree = ""; }; FC292C5521421B4600CF622F /* PaddleMobileGPU.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PaddleMobileGPU.m; sourceTree = ""; }; + FC292C7C214255BC00CF622F /* CPUCompute.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CPUCompute.mm; sourceTree = ""; }; + FC292C7D214255BC00CF622F /* CPUCompute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPUCompute.h; sourceTree = ""; }; + FC292C7E214255BC00CF622F /* MobileNetSSD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileNetSSD.swift; sourceTree = ""; }; FC3602CB2108819F00FACB58 /* PaddleMobileUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddleMobileUnitTest.swift; sourceTree = ""; }; FC4CB74820F0B954007C0C6D /* ConvKernel.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = ConvKernel.metal; sourceTree = ""; }; FC4CB74A20F12C30007C0C6D /* ProgramOptimize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramOptimize.swift; sourceTree = ""; }; @@ -250,6 +256,9 @@ FC039B6C20E11C3C0081E9F8 /* paddle-mobile */ = { isa = PBXGroup; children = ( + FC292C7E214255BC00CF622F /* MobileNetSSD.swift */, + FC292C7C214255BC00CF622F /* CPUCompute.mm */, + FC292C7D214255BC00CF622F /* CPUCompute.h */, FC292C5521421B4600CF622F /* PaddleMobileGPU.m */, FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */, FC4FD9762140E4920073E130 /* CPU */, @@ -424,6 +433,7 @@ buildActionMask = 2147483647; files = ( FC4FD9792140E4980073E130 /* PaddleMobile.h in Headers */, + FC292C85214257CB00CF622F /* CPUCompute.h in Headers */, FC292C5421421B2F00CF622F /* PaddleMobileGPU.h in Headers */, FC039B6F20E11C3C0081E9F8 /* paddle_mobile.h in Headers */, ); @@ -540,6 +550,7 @@ FCDDC6C6212F9FB800E5EF74 /* PreluKernel.swift in Sources */, FCA67CD52138272900BD58AA /* ConvAddMetal.metal in Sources */, FCBCCC5B2122F66F00D94F7E /* ConvBNReluKernel.swift in Sources */, + FC292C81214255BD00CF622F /* CPUCompute.mm in Sources */, FCEBC0F420F1FDD90099DBAF /* ConvAddBatchNormReluOp.swift in Sources */, FC0E2DC020EE461F009C1FAC /* ElementwiseAddKernel.swift in Sources */, 4AF928772133F1DB005B6C3A /* BoxCoder.metal in Sources */, @@ -584,6 +595,7 @@ FC0E2DBE20EE460D009C1FAC /* BatchNormKernel.swift in Sources */, FC039BAB20E11CBC0081E9F8 /* Operator.swift in Sources */, FCD04E6A20F319EC0007374F /* SoftmaxOp.swift in Sources */, + FC292C82214255BD00CF622F /* MobileNetSSD.swift in Sources */, FCBCCC612122FBDF00D94F7E /* PriorBoxKernel.swift in Sources */, FCBCCC5F2122FB3B00D94F7E /* PriorBoxOp.swift in Sources */, FC9D038220E2312E000F735A /* FetchOp.swift in Sources */, diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.h b/metal/paddle-mobile/paddle-mobile/CPUCompute.h similarity index 100% rename from metal/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.h rename to metal/paddle-mobile/paddle-mobile/CPUCompute.h diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.mm b/metal/paddle-mobile/paddle-mobile/CPUCompute.mm similarity index 100% rename from metal/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.mm rename to metal/paddle-mobile/paddle-mobile/CPUCompute.mm diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/Genet.swift b/metal/paddle-mobile/paddle-mobile/Genet.swift similarity index 74% rename from metal/paddle-mobile-demo/paddle-mobile-demo/Net/Genet.swift rename to metal/paddle-mobile/paddle-mobile/Genet.swift index a7c678ea18..8f9c909ad7 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/Genet.swift +++ b/metal/paddle-mobile/paddle-mobile/Genet.swift @@ -17,12 +17,13 @@ import paddle_mobile class Genet: Net { - var means: [Float] = [128.0, 128.0, 128.0] - - var scale: Float = 0.017 - - let except: Int = 0 +// var means: [Float] = [128.0, 128.0, 128.0] +// +// var scale: Float = 0.017 +// +// let except: Int = 0 +// class GenetPreProccess: CusomKernel { init(device: MTLDevice) { let s = CusomKernel.Shape.init(inWidth: 128, inHeight: 128, inChannel: 3) @@ -30,21 +31,22 @@ class Genet: Net { } } - func resultStr(res: [Float]) -> String { + override func resultStr(res: [Float]) -> String { + return " \(Array(res.suffix(10))) ... " } - var preprocessKernel: CusomKernel - let dim = (n: 1, h: 128, w: 128, c: 3) - let modelPath: String - let paramPath: String - let modelDir: String +// var preprocessKernel: CusomKernel +// let dim = (n: 1, h: 128, w: 128, c: 3) +// let modelPath: String +// let paramPath: String +// let modelDir: String - init() { + init(device: MTLDevice) { modelPath = Bundle.main.path(forResource: "genet_model", ofType: nil) ?! "model null" paramPath = Bundle.main.path(forResource: "genet_params", ofType: nil) ?! "para null" modelDir = "" - preprocessKernel = GenetPreProccess.init(device: MetalHelper.shared.device) + preprocessKernel = GenetPreProccess.init(device: device) } } diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNet.swift b/metal/paddle-mobile/paddle-mobile/MobileNet.swift similarity index 95% rename from metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNet.swift rename to metal/paddle-mobile/paddle-mobile/MobileNet.swift index 2766c14bfd..6c2487b0b1 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNet.swift +++ b/metal/paddle-mobile/paddle-mobile/MobileNet.swift @@ -15,8 +15,6 @@ import Foundation import paddle_mobile - - class MobileNet: Net{ var means: [Float] = [123.68, 116.78, 103.94] @@ -65,11 +63,11 @@ class MobileNet: Net{ let paramPath: String let modelDir: String - init() { + init(device: MTLDevice) { modelPath = Bundle.main.path(forResource: "model", ofType: nil) ?! "model null" paramPath = Bundle.main.path(forResource: "params", ofType: nil) ?! "para null" modelDir = "" - preprocessKernel = MobilenetPreProccess.init(device: MetalHelper.shared.device) + preprocessKernel = MobilenetPreProccess.init(device: device) } } diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNetSSD.swift b/metal/paddle-mobile/paddle-mobile/MobileNetSSD.swift similarity index 84% rename from metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNetSSD.swift rename to metal/paddle-mobile/paddle-mobile/MobileNetSSD.swift index 4483f5882f..9213bea125 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNetSSD.swift +++ b/metal/paddle-mobile/paddle-mobile/MobileNetSSD.swift @@ -13,15 +13,24 @@ limitations under the License. */ import Foundation -import paddle_mobile +//import +//import pad + class MobileNet_ssd_hand: Net{ - var means: [Float] = [123.68, 116.78, 103.94] - - var scale: Float = 0.017 + @objc override init(device: MTLDevice) { + super.init(device: device) + means = [123.68, 116.78, 103.94] + scale = 0.017 + except = 2 + modelPath = Bundle.main.path(forResource: "ssd_hand_model", ofType: nil) ?! "model null" + paramPath = Bundle.main.path(forResource: "ssd_hand_params", ofType: nil) ?! "para null" + modelDir = "" + preprocessKernel = MobilenetssdPreProccess.init(device: device) + dim = (n: 1, h: 300, w: 300, c: 3) + } - let except: Int = 2 class MobilenetssdPreProccess: CusomKernel { init(device: MTLDevice) { let s = CusomKernel.Shape.init(inWidth: 300, inHeight: 300, inChannel: 3) @@ -29,11 +38,11 @@ class MobileNet_ssd_hand: Net{ } } - func resultStr(res: [Float]) -> String { + override func resultStr(res: [Float]) -> String { return " \(res)" } - func fetchResult(paddleMobileRes: ResultHolder) -> [Float32] { + override func fetchResult(paddleMobileRes: ResultHolder) -> [Float32] { guard let interRes = paddleMobileRes.intermediateResults else { fatalError(" need have inter result ") @@ -76,18 +85,7 @@ class MobileNet_ssd_hand: Net{ return output } - var preprocessKernel: CusomKernel - let dim: (n: Int, h: Int, w: Int, c: Int) = (n: 1, h: 300, w: 300, c: 3) - let modelPath: String - let paramPath: String - let modelDir: String - - - init() { - modelPath = Bundle.main.path(forResource: "ssd_hand_model", ofType: nil) ?! "model null" - paramPath = Bundle.main.path(forResource: "ssd_hand_params", ofType: nil) ?! "para null" - modelDir = "" - preprocessKernel = MobilenetssdPreProccess.init(device: MetalHelper.shared.device) - } + + } diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift b/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift index 44cccea90f..d3f089e902 100644 --- a/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift @@ -10,7 +10,7 @@ import Metal import MetalKit import Foundation -public enum Platform{ +@objc public enum Platform: Int{ case CPU, GPU } @@ -20,30 +20,31 @@ class ScaleKernel: CusomKernel { } } -public protocol Net { - var except: Int { get } - var means: [Float] { get } - var scale: Float { get } - var dim: (n: Int, h: Int, w: Int, c: Int) { get } - var preprocessKernel: CusomKernel { get } -// var paramPointer: UnsafeMutableRawPointer { get } -// var paramSize: Int { get } -// var modelPointer: UnsafeMutableRawPointer { get } -// var modelSize: Int { get } - var modelPath: String { get } - var paramPath: String { get } - var modelDir: String { get } - func resultStr(res: [Float]) -> String - func fetchResult(paddleMobileRes: ResultHolder) -> [Float32] -} - -extension Net { - public func fetchResult(paddleMobileRes: ResultHolder) -> [Float32] { - return paddleMobileRes.resultArr +public class Net: NSObject { + var except: Int = 0 + var means: [Float] = [] + var scale: Float = 0.0 + var dim: (n: Int, h: Int, w: Int, c: Int) = (n: 0, h: 0, w: 0, c: 0) + var preprocessKernel: CusomKernel? = nil + var paramPointer: UnsafeMutableRawPointer? = nil + var paramSize: Int = 0 + var modelPointer: UnsafeMutableRawPointer? = nil + var modelSize: Int = 0 + var modelPath: String = "" + var paramPath: String = "" + var modelDir: String = "" + func resultStr(res: [Float]) -> String { + fatalError() + } + func fetchResult(paddleMobileRes: ResultHolder) -> [Float32] { + fatalError() + } + @objc public init(device: MTLDevice) { + super.init() } } -public class Runner { +public class Runner: NSObject { var program: Program? var executor: Executor? var queue: MTLCommandQueue? @@ -62,7 +63,7 @@ public class Runner { * commandQueue: GPU 是需要传入 * inPlatform: 需要使用的平台, GPU or CPU */ - public init(inNet: Net, commandQueue: MTLCommandQueue?, inPlatform: Platform) { + @objc public init(inNet: Net, commandQueue: MTLCommandQueue?, inPlatform: Platform) { net = inNet queue = commandQueue device = queue?.device @@ -84,7 +85,7 @@ public class Runner { /** * load 模型, 返回 true 可进行预测 */ - public func load() -> Bool { + @objc public func load() -> Bool { if platform == .GPU { guard let inDevice = device, let inQueue = queue else { print(" paddle mobile gpu load error, need MTLCommandQueue") @@ -104,7 +105,7 @@ public class Runner { return true } - public func predict(inputPointer: UnsafeMutablePointer, completion: @escaping ( _ success: Bool, _ resultArray: [Float32]) -> Void) { + @objc public func predict(inputPointer: UnsafeMutablePointer, completion: @escaping ( _ success: Bool, _ resultArray: [Float32]) -> Void) { guard let res = cpuPaddleMobile?.predictInput(inputPointer, dim: dimsNum, means: meansNumber, scale: net.scale) else { completion(false, []) return @@ -117,7 +118,7 @@ public class Runner { * texture: 需要预测的 texture 需要做过预处理 * ( _ success: Bool, _ time:TimeInterval, _ resultArray: [Float32]) -> Void : 回调闭包, 三个参数分别为: 是否成功, 预测耗时, 结果数组 */ - public func predict(texture: MTLTexture, completion: @escaping ( _ success: Bool, _ resultArray: [Float32]) -> Void) { + @objc public func predict(texture: MTLTexture, completion: @escaping ( _ success: Bool, _ resultArray: [Float32]) -> Void) { do { try self.executor?.predict(input: texture, dim: [self.net.dim.n, self.net.dim.h, self.net.dim.w, self.net.dim.c], completionHandle: { [weak self] (res) in guard let SSelf = self else { @@ -138,7 +139,7 @@ public class Runner { * cgImage: 需要预测的图片 * ( _ success: Bool, _ time:TimeInterval, _ resultArray: [Float32]) -> Void : 回调闭包, 三个参数分别为: 是否成功, 预测耗时, 结果数组 */ - public func predict(cgImage: CGImage, completion: @escaping ( _ success: Bool, _ resultArray: [Float32]) -> Void) { + @objc public func predict(cgImage: CGImage, completion: @escaping ( _ success: Bool, _ resultArray: [Float32]) -> Void) { if platform == .GPU { getTexture(image: cgImage) { [weak self] (texture) in guard let SSelf = self else { @@ -157,7 +158,7 @@ public class Runner { /* * 清理内存, 调用此函数后, 不能再使用, 需重新 load */ - public func clear() { + @objc public func clear() { if platform == .GPU { executor?.clear() executor = nil @@ -167,7 +168,7 @@ public class Runner { } } - public func preproccess(image: CGImage) -> UnsafeMutablePointer { + @objc public func preproccess(image: CGImage) -> UnsafeMutablePointer { let output = UnsafeMutablePointer.allocate(capacity: numel) let means = net.means.map { NSNumber.init(value: $0) } let dims = [NSNumber.init(value: net.dim.n), @@ -181,7 +182,7 @@ public class Runner { /* * 获取 texture, 对 texture 进行预处理, GPU 预测时使用 */ - public func getTexture(image: CGImage, getTexture: @escaping (MTLTexture) -> Void) { + @objc public func getTexture(image: CGImage, getTexture: @escaping (MTLTexture) -> Void) { let texture = try? textureLoader?.newTexture(cgImage: image, options: [:]) ?! " texture loader error" scaleTexture(input: texture!, size: (net.dim.w, net.dim.h), complete: getTexture) } diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h index b2bc293084..459a5b4bc1 100644 --- a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h @@ -19,7 +19,7 @@ typedef enum : NSUInteger { MobileNet, MobileNetSSD, Genet, -} Net; +} NetType; @interface ModelConfig: NSObject @@ -64,7 +64,7 @@ typedef enum : NSUInteger { /* * 初始化 */ --(instancetype)initWithCommandQueue:(id)queue net:(Net)netType modelConfig:(ModelConfig *)config; +-(instancetype)initWithCommandQueue:(id)queue net:(NetType)netType modelConfig:(ModelConfig *)config; /* * paramPointer 模型参数内存地址 diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m index fd98dbc866..34b926a8e5 100644 --- a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m @@ -7,3 +7,22 @@ // #import + +#import "PaddleMobileGPU.h" +#import "paddle_mobile/paddle_mobile-Swift.h" + +@implementation PaddleMobileGPU + +-(void)clrear { + +// [[ResultHolder alloc] init]; +// [[TestClass alloc] init]; +// [[TestClass alloc] initWithI:<#(NSInteger)#>] +// ResultHolder; + +} + +@end + + + diff --git a/metal/paddle-mobile/paddle-mobile/paddle_mobile.h b/metal/paddle-mobile/paddle-mobile/paddle_mobile.h index b657679715..25952c75df 100644 --- a/metal/paddle-mobile/paddle-mobile/paddle_mobile.h +++ b/metal/paddle-mobile/paddle-mobile/paddle_mobile.h @@ -14,8 +14,8 @@ #pragma once - #import "PaddleMobile.h" +#import "CPUCompute.h" #import //! Project version number for paddle_mobile. -- GitLab