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 4e9fcf8e743a4bb209d8c719d997d1d9abe40139..78370395195c57e3fcab85a355eaafd6cc6d9021 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj +++ b/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ FC8CFEF9213551D10094D569 /* model in Resources */ = {isa = PBXBuildFile; fileRef = FC8CFEF7213551D00094D569 /* model */; }; FC918191211DBC3500B6F354 /* paddle-mobile.png in Resources */ = {isa = PBXBuildFile; fileRef = FC918190211DBC3500B6F354 /* paddle-mobile.png */; }; FC918193211DC70500B6F354 /* iphone.JPG in Resources */ = {isa = PBXBuildFile; fileRef = FC918192211DC70500B6F354 /* iphone.JPG */; }; + FC9A19E72148C38400CD9CBF /* ar_model in Resources */ = {isa = PBXBuildFile; fileRef = FC9A19E52148C38400CD9CBF /* ar_model */; }; + FC9A19E82148C38400CD9CBF /* ar_params in Resources */ = {isa = PBXBuildFile; fileRef = FC9A19E62148C38400CD9CBF /* ar_params */; }; FCA3A16121313E1F00084FE5 /* hand.jpg in Resources */ = {isa = PBXBuildFile; fileRef = FCA3A16021313E1F00084FE5 /* hand.jpg */; }; FCBCCC522122EEDC00D94F7E /* ssd_hand_params in Resources */ = {isa = PBXBuildFile; fileRef = FCBCCC502122EEDC00D94F7E /* ssd_hand_params */; }; FCBCCC532122EEDC00D94F7E /* ssd_hand_model in Resources */ = {isa = PBXBuildFile; fileRef = FCBCCC512122EEDC00D94F7E /* ssd_hand_model */; }; @@ -64,6 +66,8 @@ FC8CFEF7213551D00094D569 /* model */ = {isa = PBXFileReference; lastKnownFileType = file; path = model; sourceTree = ""; }; FC918190211DBC3500B6F354 /* paddle-mobile.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "paddle-mobile.png"; sourceTree = ""; }; FC918192211DC70500B6F354 /* iphone.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = iphone.JPG; sourceTree = ""; }; + FC9A19E52148C38400CD9CBF /* ar_model */ = {isa = PBXFileReference; lastKnownFileType = file; path = ar_model; sourceTree = ""; }; + FC9A19E62148C38400CD9CBF /* ar_params */ = {isa = PBXFileReference; lastKnownFileType = file; path = ar_params; sourceTree = ""; }; FCA3A16021313E1F00084FE5 /* hand.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = hand.jpg; sourceTree = ""; }; FCBCCC502122EEDC00D94F7E /* ssd_hand_params */ = {isa = PBXFileReference; lastKnownFileType = file; path = ssd_hand_params; sourceTree = ""; }; FCBCCC512122EEDC00D94F7E /* ssd_hand_model */ = {isa = PBXFileReference; lastKnownFileType = file; path = ssd_hand_model; sourceTree = ""; }; @@ -156,6 +160,7 @@ FC0E2C2020EDC03B009C1FAC /* models */ = { isa = PBXGroup; children = ( + FC9A19E42148C38400CD9CBF /* fluid_fssd_new_ar */, FC8CFEF5213551D00094D569 /* mobilenet */, FC8CFEE32135452B0094D569 /* genet */, FCBCCC4F2122EEDC00D94F7E /* mobilenet_ssd_hand */, @@ -191,6 +196,15 @@ path = mobilenet; sourceTree = ""; }; + FC9A19E42148C38400CD9CBF /* fluid_fssd_new_ar */ = { + isa = PBXGroup; + children = ( + FC9A19E52148C38400CD9CBF /* ar_model */, + FC9A19E62148C38400CD9CBF /* ar_params */, + ); + path = fluid_fssd_new_ar; + sourceTree = ""; + }; FCBCCC4F2122EEDC00D94F7E /* mobilenet_ssd_hand */ = { isa = PBXGroup; children = ( @@ -276,6 +290,8 @@ FCA3A16121313E1F00084FE5 /* hand.jpg in Resources */, FC8CFEE62135452C0094D569 /* genet_params in Resources */, FCBCCC532122EEDC00D94F7E /* ssd_hand_model in Resources */, + FC9A19E72148C38400CD9CBF /* ar_model in Resources */, + FC9A19E82148C38400CD9CBF /* ar_params in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/PreProcessKernel.metal b/metal/paddle-mobile-demo/paddle-mobile-demo/Net/PreProcessKernel.metal index edbb19c980102796a504252bf35ebc9a6d0513fb..ac07e449bc5919a37a57143aa6881f79507a45b4 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/PreProcessKernel.metal +++ b/metal/paddle-mobile-demo/paddle-mobile-demo/Net/PreProcessKernel.metal @@ -44,7 +44,6 @@ kernel void mobilenet_preprocess_half( outTexture.write(half4(inColor.z, inColor.y, inColor.x, 0.0f), gid); } - kernel void mobilenet_ssd_preprocess( texture2d inTexture [[texture(0)]], texture2d outTexture [[texture(1)]], @@ -73,7 +72,6 @@ kernel void mobilenet_ssd_preprocess_half( outTexture.write(half4(inColor.z, inColor.y, inColor.x, 0.0f), gid); } - kernel void genet_preprocess(texture2d inTexture [[texture(0)]], texture2d outTexture [[texture(1)]], uint2 gid [[thread_position_in_grid]]) { if (gid.x >= outTexture.get_width() || @@ -96,6 +94,28 @@ kernel void genet_preprocess_half(texture2d inTexture [[text outTexture.write(half4(inColor.z, inColor.y, inColor.x, 0.0f), gid); } +kernel void mobilent_ar_preprocess(texture2d inTexture [[texture(0)]], texture2d outTexture [[texture(1)]], uint2 gid [[thread_position_in_grid]]) +{ + if (gid.x >= outTexture.get_width() || + gid.y >= outTexture.get_height()) { + return; + } + const auto means = float4(128.0f, 128.0f, 128.0f, 0.0f); + const float4 inColor = (inTexture.read(gid) * 255.0 - means) * 0.017; + outTexture.write(float4(inColor.z, inColor.y, inColor.x, 0.0f), gid); +} + +kernel void mobilent_ar_preprocess_half(texture2d inTexture [[texture(0)]], texture2d outTexture [[texture(1)]], uint2 gid [[thread_position_in_grid]]) +{ + if (gid.x >= outTexture.get_width() || + gid.y >= outTexture.get_height()) { + return; + } + const auto means = half4(128.0f, 128.0f, 128.0f, 0.0f); + const half4 inColor = (inTexture.read(gid) * 255.0 - means) * 0.017; + outTexture.write(half4(inColor.z, inColor.y, inColor.x, 0.0f), gid); +} + kernel void scale(texture2d inTexture [[texture(0)]], texture2d outTexture [[texture(1)]], uint2 gid [[thread_position_in_grid]]) { if (gid.x >= outTexture.get_width() || gid.y >= outTexture.get_height()) return; @@ -115,4 +135,3 @@ kernel void scale_half(texture2d inTexture [[texture(0)]] float4 input = inTexture.sample(sample, float2(gid.x * w_stride, gid.y * h_stride), 0); outTexture.write(half4(input), gid); } - diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift b/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift index d8101d60880bdbbdf113d064a4631968d523f81f..3bc9e1668750af53d53bb14fd05c363c96e924c0 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift +++ b/metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift @@ -21,17 +21,20 @@ let platform: Platform = .GPU let threadSupport = [1] let modelHelperMap: [SupportModel : Runner] = [.mobilenet_ssd : Runner.init(inNet: MobileNet_ssd_hand.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform), - .genet : Runner.init(inNet: Genet.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform)] + .genet : Runner.init(inNet: Genet.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform), + .mobilenet_ssd_ar : Runner.init(inNet: MobileNet_ssd_AR.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform)] //, .genet : Genet.init() //let modelHelperMap: [SupportModel : Net] = [.mobilenet : MobileNet.init(), .mobilenet_ssd : MobileNet_ssd_hand.init()] enum SupportModel: String{ // case mobilenet = "mobilenet" - case mobilenet_ssd = "mobilenetssd" - case genet = "genet" + case mobilenet_ssd = "mobilenetssd" + case genet = "genet" + case mobilenet_ssd_ar = "mobilenetssd_ar" + static func supportedModels() -> [SupportModel] { //.mobilenet, - return [.mobilenet_ssd, .genet] + return [.mobilenet_ssd, .genet, .mobilenet_ssd_ar] } } @@ -78,7 +81,7 @@ class ViewController: UIViewController { } @IBAction func predictAct(_ sender: Any) { - let max = 50 + let max = 1 switch platform { case .GPU: guard let inTexture = toPredictTexture else { @@ -102,9 +105,9 @@ class ViewController: UIViewController { } } } - print("sleep before ") - usleep(33000) - print("sleep after ") +// print("sleep before ") +// usleep(33000) +// print("sleep after ") } case .CPU: guard let inInputPointer = inputPointer else { diff --git a/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj b/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj index c3d46e333be55a60f08110d640271cb54415a17e..f88ebf65510fe563cc1b51b064b4e0c5f7c36864 100644 --- a/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj +++ b/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 4AA1EA90214664CD00D0F791 /* Split.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AA1EA8F214664CD00D0F791 /* Split.metal */; }; 4AA1EA92214665D700D0F791 /* ShapeOp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA1EA91214665D700D0F791 /* ShapeOp.swift */; }; 4AA1EA942146661500D0F791 /* ShapeKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA1EA932146661500D0F791 /* ShapeKernel.swift */; }; - 4AA1EA962146665A00D0F791 /* FlattenKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA1EA952146665A00D0F791 /* FlattenKernel.swift */; }; 4AA1EA982146666500D0F791 /* FlattenOp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA1EA972146666500D0F791 /* FlattenOp.swift */; }; 4AF928772133F1DB005B6C3A /* BoxCoder.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF928762133F1DB005B6C3A /* BoxCoder.metal */; }; 4AF9287921341661005B6C3A /* Softmax.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF9287821341661005B6C3A /* Softmax.metal */; }; @@ -68,6 +67,7 @@ FC5163F620EF556E00636C28 /* Texture2DTo2DArrayKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC5163F520EF556E00636C28 /* Texture2DTo2DArrayKernel.swift */; }; FC60DB8920E9AAA500FF203F /* MetalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC60DB8820E9AAA500FF203F /* MetalExtension.swift */; }; FC82735920E3C04200BE430A /* OpCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC82735820E3C04200BE430A /* OpCreator.swift */; }; + FC9A19E32148C31300CD9CBF /* MobilenetSSD_AR.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC9A19E22148C31300CD9CBF /* MobilenetSSD_AR.swift */; }; FC9D037920E229E4000F735A /* OpParam.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC9D037820E229E4000F735A /* OpParam.swift */; }; FC9D038020E22FBB000F735A /* FeedOp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC9D037F20E22FBB000F735A /* FeedOp.swift */; }; FC9D038220E2312E000F735A /* FetchOp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC9D038120E2312E000F735A /* FetchOp.swift */; }; @@ -123,7 +123,6 @@ 4AA1EA8F214664CD00D0F791 /* Split.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Split.metal; sourceTree = ""; }; 4AA1EA91214665D700D0F791 /* ShapeOp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShapeOp.swift; sourceTree = ""; }; 4AA1EA932146661500D0F791 /* ShapeKernel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShapeKernel.swift; sourceTree = ""; }; - 4AA1EA952146665A00D0F791 /* FlattenKernel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlattenKernel.swift; sourceTree = ""; }; 4AA1EA972146666500D0F791 /* FlattenOp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlattenOp.swift; sourceTree = ""; }; 4AF928762133F1DB005B6C3A /* BoxCoder.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = BoxCoder.metal; sourceTree = ""; }; 4AF9287821341661005B6C3A /* Softmax.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Softmax.metal; sourceTree = ""; }; @@ -181,6 +180,7 @@ FC5163F520EF556E00636C28 /* Texture2DTo2DArrayKernel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Texture2DTo2DArrayKernel.swift; sourceTree = ""; }; FC60DB8820E9AAA500FF203F /* MetalExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetalExtension.swift; sourceTree = ""; }; FC82735820E3C04200BE430A /* OpCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpCreator.swift; sourceTree = ""; }; + FC9A19E22148C31300CD9CBF /* MobilenetSSD_AR.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobilenetSSD_AR.swift; sourceTree = ""; }; FC9D037820E229E4000F735A /* OpParam.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpParam.swift; sourceTree = ""; }; FC9D037F20E22FBB000F735A /* FeedOp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedOp.swift; sourceTree = ""; }; FC9D038120E2312E000F735A /* FetchOp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchOp.swift; sourceTree = ""; }; @@ -280,6 +280,7 @@ FC039B6C20E11C3C0081E9F8 /* paddle-mobile */ = { isa = PBXGroup; children = ( + FC9A19E22148C31300CD9CBF /* MobilenetSSD_AR.swift */, FC33B0EF2147659000714A93 /* MobileNet.swift */, FC292C862142624800CF622F /* Genet.swift */, FC292C7E214255BC00CF622F /* MobileNetSSD.swift */, @@ -398,7 +399,6 @@ FCBCCC6C2123073A00D94F7E /* BoxcoderKernel.swift */, 4AA1EA8D2146647F00D0F791 /* SplitKernel.swift */, 4AA1EA932146661500D0F791 /* ShapeKernel.swift */, - 4AA1EA952146665A00D0F791 /* FlattenKernel.swift */, 4AA1EA87214662BD00D0F791 /* BilinearInterpKernel.swift */, FCBCCC70212309A700D94F7E /* MulticlassNMSKernel.swift */, FCDDC6C5212F9FB800E5EF74 /* PreluKernel.swift */, @@ -619,7 +619,6 @@ FCD04E7420F3437E0007374F /* ConvAddKernel.swift in Sources */, FC039BB920E11CC20081E9F8 /* Scope.swift in Sources */, FC292C5621421B4600CF622F /* PaddleMobileGPU.m in Sources */, - 4AA1EA962146665A00D0F791 /* FlattenKernel.swift in Sources */, FCD04E6620F314C50007374F /* PoolOp.swift in Sources */, FC039BAC20E11CBC0081E9F8 /* BatchNormOp.swift in Sources */, FCBCCC6F2123097100D94F7E /* MulticlassNMSOp.swift in Sources */, @@ -651,6 +650,7 @@ FCBCCC67212306B000D94F7E /* ConcatOp.swift in Sources */, FCD04E6C20F31A280007374F /* SoftmaxKernel.swift in Sources */, FCEB684A212F00DB00D2448E /* PreluKernel.metal in Sources */, + FC9A19E32148C31300CD9CBF /* MobilenetSSD_AR.swift in Sources */, FCDDC6CF212FE14700E5EF74 /* PriorBoxKernel.metal in Sources */, FC4CB74B20F12C30007C0C6D /* ProgramOptimize.swift in Sources */, FC5163F620EF556E00636C28 /* Texture2DTo2DArrayKernel.swift in Sources */, diff --git a/metal/paddle-mobile/paddle-mobile/MobileNet.swift b/metal/paddle-mobile/paddle-mobile/MobileNet.swift index f54c19a9d20f49a6ff9adc581fab1aef7aef55a0..a383a75d7216b3c574d3bd881d3b63774b9e36b8 100644 --- a/metal/paddle-mobile/paddle-mobile/MobileNet.swift +++ b/metal/paddle-mobile/paddle-mobile/MobileNet.swift @@ -13,7 +13,6 @@ limitations under the License. */ import Foundation -import paddle_mobile class MobileNet: Net{ diff --git a/metal/paddle-mobile/paddle-mobile/MobilenetSSD_AR.swift b/metal/paddle-mobile/paddle-mobile/MobilenetSSD_AR.swift new file mode 100644 index 0000000000000000000000000000000000000000..106a1882ff9dd6edeff107f013c282346fd83977 --- /dev/null +++ b/metal/paddle-mobile/paddle-mobile/MobilenetSSD_AR.swift @@ -0,0 +1,79 @@ +/* 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. */ + +import Foundation + +public class MobileNet_ssd_AR: Net{ + @objc public override init(device: MTLDevice) { + super.init(device: device) + means = [103.94, 116.78, 123.68] + scale = 1 + except = 2 + modelPath = Bundle.main.path(forResource: "ar_model", ofType: nil) ?! "model null" + paramPath = Bundle.main.path(forResource: "ar_params", ofType: nil) ?! "para null" + modelDir = "" + preprocessKernel = MobilenetssdPreProccess.init(device: device) + dim = (n: 1, h: 160, w: 160, c: 3) + } + + class MobilenetssdPreProccess: CusomKernel { + init(device: MTLDevice) { + let s = CusomKernel.Shape.init(inWidth: 160, inHeight: 160, inChannel: 3) + super.init(device: device, inFunctionName: "mobilent_ar_preprocess_half", outputDim: s, usePaddleMobileLib: false) + } + } + + override public func resultStr(res: [Float]) -> String { + return " \(res)" + } + + override func fetchResult(paddleMobileRes: ResultHolder) -> [Float32] { + + guard let interRes = paddleMobileRes.intermediateResults else { + fatalError(" need have inter result ") + } + + guard let scores = interRes["Scores"], scores.count > 0, let score = scores[0] as? Texture else { + fatalError(" need score ") + } + + guard let bboxs = interRes["BBoxes"], bboxs.count > 0, let bbox = bboxs[0] as? Texture else { + fatalError() + } + + var scoreFormatArr: [Float32] = score.metalTexture.realNHWC(dim: (n: score.padToFourDim[0], h: score.padToFourDim[1], w: score.padToFourDim[2], c: score.padToFourDim[3])) + // print("score: ") + // print(scoreFormatArr.strideArray()) + // + var bboxArr = bbox.metalTexture.float32Array() + // print("bbox: ") + // print(bboxArr.strideArray()) + + let nmsCompute = NMSCompute.init() + nmsCompute.scoreThredshold = 0.01 + nmsCompute.nmsTopK = 400 + nmsCompute.keepTopK = 200 + nmsCompute.nmsEta = 1.0 + nmsCompute.nmsThreshold = 0.45 + nmsCompute.background_label = 0; + nmsCompute.scoreDim = [NSNumber.init(value: score.tensorDim[0]), NSNumber.init(value: score.tensorDim[1]), NSNumber.init(value: score.tensorDim[2])] + nmsCompute.bboxDim = [NSNumber.init(value: bbox.tensorDim[0]), NSNumber.init(value: bbox.tensorDim[1]), NSNumber.init(value: bbox.tensorDim[2])] + guard let result = nmsCompute.compute(withScore: &scoreFormatArr, andBBoxs: &bboxArr) else { + fatalError( " result error " ) + } + + let output: [Float32] = result.map { $0.floatValue } + return output + } +} diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift b/metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift index 0bd6b3692d0f983a8b154bec9727468942ef7a51..dded09dae7985829c062eac67f9df47cbcbd6084 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift @@ -38,7 +38,8 @@ extension Runable where Self: OperatorProtocol{ } func inputVariant() -> [String : [Variant]] { - fatalError(" op \(type) need implement inputVariant") + return [:] +// fatalError(" op \(type) need implement inputVariant") } func delogOutput() { @@ -166,7 +167,7 @@ let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Out gPreluType : (inputs: ["X"], outputs: ["Out"]), gConv2dTransposeType : (inputs: ["Input"], outputs: ["Output"]), gBilinearInterpType : (inputs: ["X"], outputs: ["Out"]), - gSplit : (inputs: ["Input"], outputs: ["Out"]), + gSplit : (inputs: ["X"], outputs: ["Out"]), gShape : (inputs: ["Input"], outputs: ["Out"]), - gFlatten : (inputs: ["Input"], outputs: ["Out"]) + gFlatten : (inputs: ["X"], outputs: ["Out"]) ] diff --git a/metal/paddle-mobile/paddle-mobile/Operators/FlattenOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/FlattenOp.swift index a7e92bdff7161a41a8c278176e710474898814ef..70dd1c0fc8d47e336bf0d4d2695caa0fc7846ca9 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/FlattenOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/FlattenOp.swift @@ -14,21 +14,9 @@ import Foundation -class FlattenParam: OpParam { - typealias ParamPrecisionType = P - required init(opDesc: OpDesc, inScope: Scope) throws { - do { - output = try FlattenParam.output(outputs: opDesc.outputs, from: inScope) - } catch let error { - throw error - } - } - var output: Texture

-} - -class FlattenOp: Operator, FlattenParam

>, Runable, Creator, InferShaperable{ +class FlattenOp: Operator, ReshapeParam

>, Runable, Creator, InferShaperable{ - typealias OpType = SplitOp

+ typealias OpType = FlattenOp

func inferShape() { // para.output.dim = para.input.dim diff --git a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/FlattenKernel.swift b/metal/paddle-mobile/paddle-mobile/Operators/Kernels/FlattenKernel.swift deleted file mode 100644 index 87c317f68ad22995e7981537ef7be29fb9a19cc5..0000000000000000000000000000000000000000 --- a/metal/paddle-mobile/paddle-mobile/Operators/Kernels/FlattenKernel.swift +++ /dev/null @@ -1,40 +0,0 @@ -/* 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. */ - -import Foundation - -struct FlattenMetalParam { -} - -class FlattenKernel: Kernel, Computable{ - func compute(commandBuffer: MTLCommandBuffer, param: FlattenParam

) throws { - guard let encoder = commandBuffer.makeComputeCommandEncoder() else { - throw PaddleMobileError.predictError(message: " encode is nil") - } - encoder.setTexture(param.output.metalTexture, index: 0) - encoder.endEncoding() - } - - required init(device: MTLDevice, param: FlattenParam

) { - param.output.initTexture(device: device, computePrecision: computePrecision) - if computePrecision == .Float32 { - super.init(device: device, inFunctionName: "split") - } else if computePrecision == .Float16 { - super.init(device: device, inFunctionName: "split_half") - } else { - fatalError() - } - } - -} diff --git a/metal/paddle-mobile/paddle-mobile/Operators/SplitOp.swift b/metal/paddle-mobile/paddle-mobile/Operators/SplitOp.swift index 6ea783b55a206454e304ad0e117237b05a634c4d..5adc47c663e5abd639f2cc2f4c95ae4c565e897a 100644 --- a/metal/paddle-mobile/paddle-mobile/Operators/SplitOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Operators/SplitOp.swift @@ -18,7 +18,8 @@ class SplitParam: OpParam { typealias ParamPrecisionType = P required init(opDesc: OpDesc, inScope: Scope) throws { do { - output = try SplitParam.output(outputs: opDesc.outputs, from: inScope) +// output = try SplitParam.output(outputs: opDesc.outputs, from: inScope) + output = try SplitParam.outputOut(outputs: opDesc.outputs, from: inScope) } catch let error { throw error } diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift b/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift index b43ea3742bc23d18b596d7f90935da840342dbfd..cd329394c6cce744d6e3c4de61ed3df6aa00b070 100644 --- a/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobile.swift @@ -16,7 +16,7 @@ import Foundation class ScaleKernel: CusomKernel { init(device: MTLDevice, shape: Shape) { - super.init(device: device, inFunctionName: "scale", outputDim: shape, usePaddleMobileLib: false) + super.init(device: device, inFunctionName: "scale_half", outputDim: shape, usePaddleMobileLib: false) } } diff --git a/metal/paddle-mobile/paddle-mobile/framework/Executor.swift b/metal/paddle-mobile/paddle-mobile/framework/Executor.swift index 01d8282b90c563117289cd3082c3d0a170509ba6..595bf2e5b541e6465df4342cd2ba2f5362c9b086 100644 --- a/metal/paddle-mobile/paddle-mobile/framework/Executor.swift +++ b/metal/paddle-mobile/paddle-mobile/framework/Executor.swift @@ -14,10 +14,9 @@ import Foundation -let testTo = 161 +let testTo = 3 var isTest = false - let computePrecision: ComputePrecision = .Float16 public class ResultHolder { @@ -85,7 +84,6 @@ public class Executor { throw PaddleMobileError.predictError(message: "CommandBuffer is nil") } inflightSemaphore.wait() - let resInput: MTLTexture if let inPre = preProcessKernle { @@ -118,11 +116,13 @@ public class Executor { } buffer.addCompletedHandler { [weak self] (commandbuffer) in -// return + // let inputArr = resInput.toTensor(dim: (n: dim[0], c: dim[3], h: dim[1], w: dim[2])) //// print(inputArr.strideArray()) -// -// writeToLibrary(fileName: "test_image_ssd", array: inputArr) + +// print(dim) +// writeToLibrary(fileName: "test_image_ssd_ar", array: inputArr) + // print("write to library done") // return // print(inputArr)