提交 250bf7fd 编写于 作者: L liuruilong

fomart files

上级 0ca8fdea
...@@ -108,15 +108,14 @@ class ViewController: UIViewController { ...@@ -108,15 +108,14 @@ class ViewController: UIViewController {
guard let sSelf = self else { guard let sSelf = self else {
fatalError() fatalError()
} }
if success { if let inResultHolder = resultHolder, success {
if i == max - 1 { if i == max - 1 {
let time = Date.init().timeIntervalSince(startDate) let time = Date.init().timeIntervalSince(startDate)
print(Array<Any>.floatArrWithBuffer(floatArrBuffer: resultHolder!.result!, count: resultHolder!.capacity).strideArray())
print(inResultHolder.result.floatArr(count: inResultHolder.capacity).strideArray())
DispatchQueue.main.async { DispatchQueue.main.async {
// print(resultHolder!.result![0])
sSelf.resultTextView.text = sSelf.runner.net.resultStr(res: resultHolder!) sSelf.resultTextView.text = sSelf.runner.net.resultStr(res: resultHolder!)
sSelf.elapsedTimeLabel.text = "平均耗时: \(time/Double(max) * 1000.0) ms" sSelf.elapsedTimeLabel.text = "平均耗时: \(time/Double(max) * 1000.0) ms"
} }
} }
} }
......
...@@ -120,9 +120,17 @@ extension Array { ...@@ -120,9 +120,17 @@ extension Array {
} }
} }
extension UnsafeMutablePointer {
public func floatArr(count: Int) -> [Pointee]{
var arr: [Pointee] = []
for i in 0..<count {
arr.append(self[i])
}
return arr
}
}
extension String {
extension String{
func cStr() -> UnsafePointer<Int8>? { func cStr() -> UnsafePointer<Int8>? {
return (self as NSString).utf8String return (self as NSString).utf8String
} }
......
...@@ -48,7 +48,7 @@ public class Genet: Net { ...@@ -48,7 +48,7 @@ public class Genet: Net {
override public func resultStr(res: ResultHolder) -> String { override public func resultStr(res: ResultHolder) -> String {
// fatalError() // fatalError()
return " \(res.result![0]) ... " return " \(res.result[0]) ... "
} }
} }
...@@ -43,9 +43,7 @@ public class MobileNet: Net{ ...@@ -43,9 +43,7 @@ public class MobileNet: Net{
let labels = PreWords.init(fileName: "synset") let labels = PreWords.init(fileName: "synset")
override public func resultStr(res: ResultHolder) -> String { override public func resultStr(res: ResultHolder) -> String {
guard let resPointer = res.result else { let resPointer = res.result
fatalError()
}
var s: [String] = [] var s: [String] = []
(0..<res.capacity).map { resPointer[$0] }.top(r: 5).enumerated().forEach{ (0..<res.capacity).map { resPointer[$0] }.top(r: 5).enumerated().forEach{
s.append(String(format: "%d: %@ (%3.2f%%)", $0 + 1, labels[$1.0], $1.1 * 100)) s.append(String(format: "%d: %@ (%3.2f%%)", $0 + 1, labels[$1.0], $1.1 * 100))
......
...@@ -41,7 +41,7 @@ public class MobileNetCombined: Net { ...@@ -41,7 +41,7 @@ public class MobileNetCombined: Net {
override public func resultStr(res: ResultHolder) -> String { override public func resultStr(res: ResultHolder) -> String {
// fatalError() // fatalError()
return " \(res.result![0]) ... " return " \(res.result[0]) ... "
} }
} }
...@@ -47,7 +47,7 @@ public class MobileNet_ssd_AR: Net{ ...@@ -47,7 +47,7 @@ public class MobileNet_ssd_AR: Net{
} }
override public func resultStr(res: ResultHolder) -> String { override public func resultStr(res: ResultHolder) -> String {
return " \(res.result![0])" return " \(res.result[0])"
} }
override func fetchResult(paddleMobileRes: GPUResultHolder) -> ResultHolder { override func fetchResult(paddleMobileRes: GPUResultHolder) -> ResultHolder {
......
...@@ -43,8 +43,7 @@ public class YoloNet: Net { ...@@ -43,8 +43,7 @@ public class YoloNet: Net {
// } // }
override public func resultStr(res: ResultHolder) -> String { override public func resultStr(res: ResultHolder) -> String {
// fatalError() return " \(res.result[0]) ... "
return " \(res.result![0]) ... "
} }
} }
...@@ -17,17 +17,17 @@ import Foundation ...@@ -17,17 +17,17 @@ import Foundation
import Metal import Metal
public class ResultHolder: NSObject { public class ResultHolder: NSObject {
@objc public let result: UnsafeMutablePointer<Float32>? @objc public let result: UnsafeMutablePointer<Float32>
@objc public let capacity: Int @objc public let capacity: Int
init(inResult: UnsafeMutablePointer<Float32>?, inCapacity: Int) { init(inResult: UnsafeMutablePointer<Float32>, inCapacity: Int) {
result = inResult result = inResult
capacity = inCapacity capacity = inCapacity
} }
@objc public func releasePointer() { @objc public func releasePointer() {
result?.deinitialize(count: capacity) result.deinitialize(count: capacity)
result?.deallocate() result.deallocate()
} }
} }
...@@ -86,7 +86,11 @@ public class Net: NSObject { ...@@ -86,7 +86,11 @@ public class Net: NSObject {
} }
func fetchResult(paddleMobileRes: GPUResultHolder) -> ResultHolder { func fetchResult(paddleMobileRes: GPUResultHolder) -> ResultHolder {
return ResultHolder.init(inResult: paddleMobileRes.resultPointer, inCapacity: paddleMobileRes.capacity) guard let inResPointer = paddleMobileRes.resultPointer else {
fatalError()
}
return ResultHolder.init(inResult: inResPointer, inCapacity: paddleMobileRes.capacity)
} }
func updateProgram(program: Program) { func updateProgram(program: Program) {
......
...@@ -83,7 +83,7 @@ class FetchOp<P: PrecisionType>: Operator< FetchKernel<P>, FetchParam<P>>, Runab ...@@ -83,7 +83,7 @@ class FetchOp<P: PrecisionType>: Operator< FetchKernel<P>, FetchParam<P>>, Runab
func delogOutput() { func delogOutput() {
print("fetch output: ") print("fetch output: ")
let resArr = Array<Any>.floatArrWithBuffer(floatArrBuffer: self.para.output.result, count: self.para.output.capacity) let resArr = self.para.output.result.floatArr(count: self.para.output.capacity)
print(resArr.strideArray()) print(resArr.strideArray())
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册