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

fomart files

上级 0ca8fdea
......@@ -108,15 +108,14 @@ class ViewController: UIViewController {
guard let sSelf = self else {
fatalError()
}
if success {
if let inResultHolder = resultHolder, success {
if i == max - 1 {
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 {
// print(resultHolder!.result![0])
sSelf.resultTextView.text = sSelf.runner.net.resultStr(res: resultHolder!)
sSelf.elapsedTimeLabel.text = "平均耗时: \(time/Double(max) * 1000.0) ms"
}
}
}
......
......@@ -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>? {
return (self as NSString).utf8String
}
......
......@@ -48,7 +48,7 @@ public class Genet: Net {
override public func resultStr(res: ResultHolder) -> String {
// fatalError()
return " \(res.result![0]) ... "
return " \(res.result[0]) ... "
}
}
......@@ -43,9 +43,7 @@ public class MobileNet: Net{
let labels = PreWords.init(fileName: "synset")
override public func resultStr(res: ResultHolder) -> String {
guard let resPointer = res.result else {
fatalError()
}
let resPointer = res.result
var s: [String] = []
(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))
......
......@@ -41,7 +41,7 @@ public class MobileNetCombined: Net {
override public func resultStr(res: ResultHolder) -> String {
// fatalError()
return " \(res.result![0]) ... "
return " \(res.result[0]) ... "
}
}
......@@ -47,7 +47,7 @@ public class MobileNet_ssd_AR: Net{
}
override public func resultStr(res: ResultHolder) -> String {
return " \(res.result![0])"
return " \(res.result[0])"
}
override func fetchResult(paddleMobileRes: GPUResultHolder) -> ResultHolder {
......
......@@ -43,8 +43,7 @@ public class YoloNet: Net {
// }
override public func resultStr(res: ResultHolder) -> String {
// fatalError()
return " \(res.result![0]) ... "
return " \(res.result[0]) ... "
}
}
......@@ -17,17 +17,17 @@ import Foundation
import Metal
public class ResultHolder: NSObject {
@objc public let result: UnsafeMutablePointer<Float32>?
@objc public let result: UnsafeMutablePointer<Float32>
@objc public let capacity: Int
init(inResult: UnsafeMutablePointer<Float32>?, inCapacity: Int) {
init(inResult: UnsafeMutablePointer<Float32>, inCapacity: Int) {
result = inResult
capacity = inCapacity
}
@objc public func releasePointer() {
result?.deinitialize(count: capacity)
result?.deallocate()
result.deinitialize(count: capacity)
result.deallocate()
}
}
......@@ -86,7 +86,11 @@ public class Net: NSObject {
}
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) {
......
......@@ -83,7 +83,7 @@ class FetchOp<P: PrecisionType>: Operator< FetchKernel<P>, FetchParam<P>>, Runab
func delogOutput() {
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())
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册