提交 94624b1d 编写于 作者: L liuruilong

add preprocess Kernel

上级 4f3ae703
...@@ -23,8 +23,11 @@ public class MobileNetCombined: Net { ...@@ -23,8 +23,11 @@ public class MobileNetCombined: Net {
paramPath = Bundle.main.path(forResource: "combined_mobilenet_params", ofType: nil) ?! "para null" paramPath = Bundle.main.path(forResource: "combined_mobilenet_params", ofType: nil) ?! "para null"
inputDim = Dim.init(inDim: [1, 224, 224, 3]) inputDim = Dim.init(inDim: [1, 224, 224, 3])
metalLoadMode = .LoadMetalInCustomMetalLib metalLoadMode = .LoadMetalInCustomMetalLib
metalLibPath = Bundle.main.path(forResource: "paddle-mobile-metallib", ofType: "metallib") let paddleMobileMetallib = Bundle.main.path(forResource: "paddle-mobile-metallib", ofType: "metallib")
metalLibPath = paddleMobileMetallib
useMPS = true useMPS = true
preprocessKernel = ScaleKernel.init(device: device, shape: Shape.init(inWidth: 224, inHeight: 224, inChannel: 3), metalLoadMode: .LoadMetalInCustomMetalLib, metalLibPath: paddleMobileMetallib)
} }
let labels = PreWords.init(fileName: "vision_synset") let labels = PreWords.init(fileName: "vision_synset")
......
...@@ -27,6 +27,8 @@ public class YoloNet: Net { ...@@ -27,6 +27,8 @@ public class YoloNet: Net {
metalLibPath = Bundle.main.path(forResource: "paddle-mobile-metallib", ofType: "metallib") metalLibPath = Bundle.main.path(forResource: "paddle-mobile-metallib", ofType: "metallib")
useMPS = true useMPS = true
paramPrecision = .Float16 paramPrecision = .Float16
preprocessKernel = ScaleKernel.init(device: device, shape: Shape.init(inWidth: 416, inHeight: 416, inChannel: 3), metalLoadMode: .LoadMetalInCustomMetalLib, metalLibPath: Bundle.main.path(forResource: "paddle-mobile-metallib", ofType: "metallib"))
} }
override public func resultStr(res: [ResultHolder]) -> String { override public func resultStr(res: [ResultHolder]) -> String {
......
...@@ -100,16 +100,15 @@ class ViewController: UIViewController { ...@@ -100,16 +100,15 @@ class ViewController: UIViewController {
if self.toPredictTexture == nil { if self.toPredictTexture == nil {
// runner.getTexture(inBuffer: buffer!) { [weak self] (texture) in
// self?.toPredictTexture = texture
// }
let beforeDate = Date.init() let beforeDate = Date.init()
runner.getTexture(image: selectImage!.cgImage!) { [weak self] (texture) in if modelType == .mobilenet_combined || modelType == .yolo {
let timeUse = Date.init().timeIntervalSince(beforeDate) self.toPredictTexture = try! MetalHelper.shared.textureLoader.newTexture(cgImage: selectImage!.cgImage!, options: nil)
print("get texture time use: \(timeUse)") } else {
self?.toPredictTexture = texture runner.getTexture(image: selectImage!.cgImage!) { [weak self] (texture) in
let timeUse = Date.init().timeIntervalSince(beforeDate)
print("get texture time use: \(timeUse)")
self?.toPredictTexture = texture
}
} }
} }
} else { } else {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
import Foundation import Foundation
class ScaleKernel: CusomKernel { public class ScaleKernel: CusomKernel {
init(device: MTLDevice, shape: Shape, metalLoadMode: MetalLoadMode, metalLibPath: String?) { public init(device: MTLDevice, shape: Shape, metalLoadMode: MetalLoadMode, metalLibPath: String?) {
if GlobalConfig.shared.computePrecision == .Float32 { if GlobalConfig.shared.computePrecision == .Float32 {
super.init(device: device, inFunctionName: "scale", outputDim: shape, metalLoadModel: metalLoadMode, metalLibPath: metalLibPath) super.init(device: device, inFunctionName: "scale", outputDim: shape, metalLoadModel: metalLoadMode, metalLibPath: metalLibPath)
} else if GlobalConfig.shared.computePrecision == .Float16 { } else if GlobalConfig.shared.computePrecision == .Float16 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册