Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
cb064033
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cb064033
编写于
8月 28, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
run genet
上级
ca857a36
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
154 addition
and
65 deletion
+154
-65
metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj
...-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj
+28
-24
metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/xcuserdata/liuruilong.xcuserdatad/xcschemes/paddle-mobile-demo.xcscheme
...ruilong.xcuserdatad/xcschemes/paddle-mobile-demo.xcscheme
+1
-1
metal/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.mm
...l/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.mm
+1
-0
metal/paddle-mobile-demo/paddle-mobile-demo/Net/Genet.swift
metal/paddle-mobile-demo/paddle-mobile-demo/Net/Genet.swift
+50
-0
metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNet.swift
...paddle-mobile-demo/paddle-mobile-demo/Net/MobileNet.swift
+1
-1
metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNetSSD.swift
...dle-mobile-demo/paddle-mobile-demo/Net/MobileNetSSD.swift
+0
-1
metal/paddle-mobile-demo/paddle-mobile-demo/Net/Net.swift
metal/paddle-mobile-demo/paddle-mobile-demo/Net/Net.swift
+0
-12
metal/paddle-mobile-demo/paddle-mobile-demo/Net/PreProcessKernel.metal
...mobile-demo/paddle-mobile-demo/Net/PreProcessKernel.metal
+15
-3
metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift
...addle-mobile-demo/paddle-mobile-demo/ViewController.swift
+14
-0
metal/paddle-mobile/paddle-mobile/Executor.swift
metal/paddle-mobile/paddle-mobile/Executor.swift
+0
-5
metal/paddle-mobile/paddle-mobile/Operators/Base/OpCreator.swift
...addle-mobile/paddle-mobile/Operators/Base/OpCreator.swift
+4
-2
metal/paddle-mobile/paddle-mobile/Operators/Base/OpParam.swift
.../paddle-mobile/paddle-mobile/Operators/Base/OpParam.swift
+8
-3
metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift
...paddle-mobile/paddle-mobile/Operators/Base/Operator.swift
+7
-1
metal/paddle-mobile/paddle-mobile/Operators/ConvAddBatchNormReluOp.swift
...bile/paddle-mobile/Operators/ConvAddBatchNormReluOp.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift
metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift
+1
-0
metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift
...dle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift
+14
-4
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ElementwiseAddKernel.swift
...addle-mobile/Operators/Kernels/ElementwiseAddKernel.swift
+7
-6
metal/paddle-mobile/paddle-mobile/Operators/Kernels/PreluKernel.swift
...-mobile/paddle-mobile/Operators/Kernels/PreluKernel.swift
+1
-0
metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift
metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift
+1
-1
未找到文件。
metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj
浏览文件 @
cb064033
...
...
@@ -18,8 +18,9 @@
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 */
;
};
FC8CFEDB21351F5D0094D569
/* params in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC8CFED921351F5D0094D569
/* params */
;
};
FC8CFEDC21351F5D0094D569
/* model in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC8CFEDA21351F5D0094D569
/* model */
;
};
FC8CFEDF213521C10094D569
/* genet_model in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC8CFEDD213521C10094D569
/* genet_model */
;
};
FC8CFEE0213521C10094D569
/* genet_params in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC8CFEDE213521C10094D569
/* genet_params */
;
};
FC8CFEE2213524EA0094D569
/* Genet.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC8CFEE1213524EA0094D569
/* Genet.swift */
;
};
FC918191211DBC3500B6F354
/* paddle-mobile.png in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC918190211DBC3500B6F354
/* paddle-mobile.png */
;
};
FC918193211DC70500B6F354
/* iphone.JPG in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FC918192211DC70500B6F354
/* iphone.JPG */
;
};
FCA3A16121313E1F00084FE5
/* hand.jpg in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
FCA3A16021313E1F00084FE5
/* hand.jpg */
;
};
...
...
@@ -66,8 +67,9 @@
FC27991421343A46000B6BAD
/* CPUCompute.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
CPUCompute.h
;
sourceTree
=
"<group>"
;
};
FC3C800E2133F46600D1295E
/* MobileNetSSD.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MobileNetSSD.swift
;
sourceTree
=
"<group>"
;
};
FC3C80102133F4AB00D1295E
/* MobileNet.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MobileNet.swift
;
sourceTree
=
"<group>"
;
};
FC8CFED921351F5D0094D569
/* params */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
params
;
sourceTree
=
"<group>"
;
};
FC8CFEDA21351F5D0094D569
/* model */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
model
;
sourceTree
=
"<group>"
;
};
FC8CFEDD213521C10094D569
/* genet_model */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
genet_model
;
sourceTree
=
"<group>"
;
};
FC8CFEDE213521C10094D569
/* genet_params */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
genet_params
;
sourceTree
=
"<group>"
;
};
FC8CFEE1213524EA0094D569
/* Genet.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Genet.swift
;
sourceTree
=
"<group>"
;
};
FC918190211DBC3500B6F354
/* paddle-mobile.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"paddle-mobile.png"
;
sourceTree
=
"<group>"
;
};
FC918192211DC70500B6F354
/* iphone.JPG */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.jpeg
;
path
=
iphone.JPG
;
sourceTree
=
"<group>"
;
};
FCA3A16021313E1F00084FE5
/* hand.jpg */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.jpeg
;
path
=
hand.jpg
;
sourceTree
=
"<group>"
;
};
...
...
@@ -137,7 +139,6 @@
FC0E2C2020EDC03B009C1FAC
/* models */
,
FC0E2C1D20EDC030009C1FAC
/* images */
,
FC039B8120E11C550081E9F8
/* AppDelegate.swift */
,
FC013927210204A3008100E3
/* PreProcessKernel.metal */
,
FC039B8320E11C550081E9F8
/* ViewController.swift */
,
FC039B8520E11C550081E9F8
/* Main.storyboard */
,
FC039B8820E11C560081E9F8
/* Assets.xcassets */
,
...
...
@@ -164,7 +165,7 @@
FC0E2C2020EDC03B009C1FAC
/* models */
=
{
isa
=
PBXGroup
;
children
=
(
FC8CFED821351F5D0094D569
/* enet */
,
FC8CFED821351F5D0094D569
/*
g
enet */
,
FCBCCC4F2122EEDC00D94F7E
/* mobilenet_ssd_hand */
,
FCD04E6020F3146A0007374F
/* mobilenet */
,
);
...
...
@@ -175,23 +176,25 @@
FC8CFED2213519540094D569
/* Net */
=
{
isa
=
PBXGroup
;
children
=
(
FC013927210204A3008100E3
/* PreProcessKernel.metal */
,
FCBCCC542122EF5400D94F7E
/* MetalHelper.swift */
,
FC3C800E2133F46600D1295E
/* MobileNetSSD.swift */
,
FC3C80102133F4AB00D1295E
/* MobileNet.swift */
,
FC27990F21341CE5000B6BAD
/* Net.swift */
,
FC27991221343A3A000B6BAD
/* CPUCompute.mm */
,
FC27991421343A46000B6BAD
/* CPUCompute.h */
,
FC8CFEE1213524EA0094D569
/* Genet.swift */
,
);
path
=
Net
;
sourceTree
=
"<group>"
;
};
FC8CFED821351F5D0094D569
/* enet */
=
{
FC8CFED821351F5D0094D569
/*
g
enet */
=
{
isa
=
PBXGroup
;
children
=
(
FC8CFED
921351F5D0094D569
/* params
*/
,
FC8CFED
A21351F5D0094D569
/* model
*/
,
FC8CFED
D213521C10094D569
/* genet_model
*/
,
FC8CFED
E213521C10094D569
/* genet_params
*/
,
);
path
=
enet
;
path
=
g
enet
;
sourceTree
=
"<group>"
;
};
FCBCCC4F2122EEDC00D94F7E
/* mobilenet_ssd_hand */
=
{
...
...
@@ -274,10 +277,9 @@
isa
=
PBXResourcesBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
FC8CFEDB21351F5D0094D569
/* params in Resources */
,
FCD04E6320F3146B0007374F
/* params in Resources */
,
FC8CFEDC21351F5D0094D569
/* model in Resources */
,
FC039B8C20E11C560081E9F8
/* LaunchScreen.storyboard in Resources */
,
FC8CFEE0213521C10094D569
/* genet_params in Resources */
,
FC918191211DBC3500B6F354
/* paddle-mobile.png in Resources */
,
FC039B8920E11C560081E9F8
/* Assets.xcassets in Resources */
,
FCBCCC522122EEDC00D94F7E
/* ssd_hand_params in Resources */
,
...
...
@@ -285,6 +287,7 @@
FC918193211DC70500B6F354
/* iphone.JPG in Resources */
,
FCDFD41B211D91C7005AB38B
/* synset.txt in Resources */
,
FCD04E6420F3146B0007374F
/* model in Resources */
,
FC8CFEDF213521C10094D569
/* genet_model in Resources */
,
FC039B8720E11C550081E9F8
/* Main.storyboard in Resources */
,
FCA3A16121313E1F00084FE5
/* hand.jpg in Resources */
,
FCBCCC532122EEDC00D94F7E
/* ssd_hand_model in Resources */
,
...
...
@@ -340,6 +343,7 @@
FC039B8420E11C550081E9F8
/* ViewController.swift in Sources */
,
FC013928210204A3008100E3
/* PreProcessKernel.metal in Sources */
,
FC27991021341CE5000B6BAD
/* Net.swift in Sources */
,
FC8CFEE2213524EA0094D569
/* Genet.swift in Sources */
,
FCBCCC552122EF5500D94F7E
/* MetalHelper.swift in Sources */
,
FC27991321343A3A000B6BAD
/* CPUCompute.mm in Sources */
,
FC3C80112133F4AB00D1295E
/* MobileNet.swift in Sources */
,
...
...
@@ -490,19 +494,19 @@
buildSettings
=
{
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CODE_SIGN_IDENTITY
=
"iPhone D
istribution
"
;
CODE_SIGN_STYLE
=
Manual
;
DEVELOPMENT_TEAM
=
6T9LLJKSM4
;
CODE_SIGN_IDENTITY
=
"iPhone D
eveloper
"
;
CODE_SIGN_STYLE
=
Automatic
;
DEVELOPMENT_TEAM
=
A798K58VVL
;
INFOPLIST_FILE
=
"paddle-mobile-demo/Info.plist"
;
IPHONEOS_DEPLOYMENT_TARGET
=
9.0
;
LD_RUNPATH_SEARCH_PATHS
=
(
"$(inherited)"
,
"@executable_path/Frameworks"
,
);
PRODUCT_BUNDLE_IDENTIFIER
=
com.baidu.mms.qa
;
PRODUCT_BUNDLE_IDENTIFIER
=
"com.baidu.paddle-mobile"
;
PRODUCT_NAME
=
"$(TARGET_NAME)"
;
PROVISIONING_PROFILE
=
"
ba9c4b24-7bd0-49c5-93cd-e3051e775d6c
"
;
PROVISIONING_PROFILE_SPECIFIER
=
Distribution_MMS
;
PROVISIONING_PROFILE
=
""
;
PROVISIONING_PROFILE_SPECIFIER
=
""
;
SWIFT_OBJC_BRIDGING_HEADER
=
"paddle-mobile-demo/paddle-mobile-demo-Bridging-Header.h"
;
SWIFT_OPTIMIZATION_LEVEL
=
"-Onone"
;
SWIFT_VERSION
=
4.0
;
...
...
@@ -516,19 +520,19 @@
buildSettings
=
{
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CODE_SIGN_IDENTITY
=
"iPhone D
istribution
"
;
CODE_SIGN_STYLE
=
Manual
;
DEVELOPMENT_TEAM
=
6T9LLJKSM4
;
CODE_SIGN_IDENTITY
=
"iPhone D
eveloper
"
;
CODE_SIGN_STYLE
=
Automatic
;
DEVELOPMENT_TEAM
=
A798K58VVL
;
INFOPLIST_FILE
=
"paddle-mobile-demo/Info.plist"
;
IPHONEOS_DEPLOYMENT_TARGET
=
9.0
;
LD_RUNPATH_SEARCH_PATHS
=
(
"$(inherited)"
,
"@executable_path/Frameworks"
,
);
PRODUCT_BUNDLE_IDENTIFIER
=
com.baidu.mms.qa
;
PRODUCT_BUNDLE_IDENTIFIER
=
"com.baidu.paddle-mobile"
;
PRODUCT_NAME
=
"$(TARGET_NAME)"
;
PROVISIONING_PROFILE
=
"
ba9c4b24-7bd0-49c5-93cd-e3051e775d6c
"
;
PROVISIONING_PROFILE_SPECIFIER
=
Distribution_MMS
;
PROVISIONING_PROFILE
=
""
;
PROVISIONING_PROFILE_SPECIFIER
=
""
;
SWIFT_OBJC_BRIDGING_HEADER
=
"paddle-mobile-demo/paddle-mobile-demo-Bridging-Header.h"
;
SWIFT_VERSION
=
4.0
;
TARGETED_DEVICE_FAMILY
=
"1,2"
;
...
...
metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/xcuserdata/liuruilong.xcuserdatad/xcschemes/paddle-mobile-demo.xcscheme
浏览文件 @
cb064033
...
...
@@ -42,7 +42,7 @@
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration =
"
Release
"
buildConfiguration =
"
Debug
"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle =
"0"
...
...
metal/paddle-mobile-demo/paddle-mobile-demo/Net/CPUCompute.mm
浏览文件 @
cb064033
...
...
@@ -310,6 +310,7 @@ void MultiClassNMSCompute(NMSParam *param) {
for
(
int
i
=
0
;
i
<
param
.
output_size
;
++
i
)
{
[
output
addObject
:[
NSNumber
numberWithFloat
:
param
.
output
[
i
]]];
}
delete
param
.
output
;
return
output
;
}
...
...
metal/paddle-mobile-demo/paddle-mobile-demo/Net/Genet.swift
0 → 100644
浏览文件 @
cb064033
/* 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
import
paddle_mobile
class
Genet
:
Net
{
var
program
:
Program
?
var
executor
:
Executor
<
Float32
>
?
let
except
:
Int
=
0
class
GenetPreProccess
:
CusomKernel
{
init
(
device
:
MTLDevice
)
{
let
s
=
CusomKernel
.
Shape
.
init
(
inWidth
:
128
,
inHeight
:
128
,
inChannel
:
3
)
super
.
init
(
device
:
device
,
inFunctionName
:
"genet_preprocess"
,
outputDim
:
s
,
usePaddleMobileLib
:
false
)
}
}
func
resultStr
(
res
:
[
Float
])
->
String
{
return
" 哈哈 还没好 genet !"
;
}
var
preprocessKernel
:
CusomKernel
let
dim
=
[
1
,
128
,
128
,
3
]
let
modelPath
:
String
let
paramPath
:
String
let
modelDir
:
String
init
()
{
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
)
}
}
metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNet.swift
浏览文件 @
cb064033
...
...
@@ -26,7 +26,7 @@ class MobileNet: Net{
class
MobilenetPreProccess
:
CusomKernel
{
init
(
device
:
MTLDevice
)
{
let
s
=
CusomKernel
.
Shape
.
init
(
inWidth
:
224
,
inHeight
:
224
,
inChannel
:
3
)
super
.
init
(
device
:
device
,
inFunctionName
:
"preprocess"
,
outputDim
:
s
,
usePaddleMobileLib
:
false
)
super
.
init
(
device
:
device
,
inFunctionName
:
"
mobilenet_
preprocess"
,
outputDim
:
s
,
usePaddleMobileLib
:
false
)
}
}
...
...
metal/paddle-mobile-demo/paddle-mobile-demo/Net/MobileNetSSD.swift
浏览文件 @
cb064033
...
...
@@ -69,7 +69,6 @@ class MobileNet_ssd_hand: Net{
let
output
:
[
Float32
]
=
result
.
map
{
$0
.
floatValue
}
return
output
}
...
...
metal/paddle-mobile-demo/paddle-mobile-demo/Net/Net.swift
浏览文件 @
cb064033
...
...
@@ -21,18 +21,6 @@ import paddle_mobile
import
MetalPerformanceShaders
let
modelHelperMap
:
[
SupportModel
:
Net
]
=
[
.
mobilenet_ssd
:
MobileNet_ssd_hand
.
init
()]
//let modelHelperMap: [SupportModel : Net] = [.mobilenet : MobileNet.init(), .mobilenet_ssd : MobileNet_ssd_hand.init()]
enum
SupportModel
:
String
{
// case mobilenet = "mobilenet"
case
mobilenet_ssd
=
"mobilenetssd"
static
func
supportedModels
()
->
[
SupportModel
]
{
//.mobilenet,
return
[
.
mobilenet_ssd
]
}
}
protocol
Net
{
var
program
:
Program
?
{
get
set
}
var
executor
:
Executor
<
Float32
>
?
{
get
set
}
...
...
metal/paddle-mobile-demo/paddle-mobile-demo/PreProcessKernel.metal
→
metal/paddle-mobile-demo/paddle-mobile-demo/
Net/
PreProcessKernel.metal
浏览文件 @
cb064033
...
...
@@ -10,7 +10,7 @@
using namespace metal;
kernel void preprocess(
kernel void
mobilenet_
preprocess(
texture2d<float, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]],
uint2 gid [[thread_position_in_grid]])
...
...
@@ -24,7 +24,7 @@ kernel void preprocess(
outTexture.write(float4(inColor.z, inColor.y, inColor.x, 0.0f), gid);
}
kernel void preprocess_half(
kernel void
mobilenet_
preprocess_half(
texture2d<half, access::read> inTexture [[texture(0)]],
texture2d<half, access::write> outTexture [[texture(1)]],
uint2 gid [[thread_position_in_grid]])
...
...
@@ -68,5 +68,17 @@ kernel void mobilenet_ssd_preprocess_half(
}
kernel void genet_preprocess(
texture2d<float, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> 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(123.68f, 116.78f, 103.94f, 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);
}
metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift
浏览文件 @
cb064033
...
...
@@ -19,6 +19,20 @@ import MetalPerformanceShaders
let
threadSupport
=
[
1
]
let
modelHelperMap
:
[
SupportModel
:
Net
]
=
[
.
mobilenet_ssd
:
MobileNet_ssd_hand
.
init
(),
.
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
=
"enet"
static
func
supportedModels
()
->
[
SupportModel
]
{
//.mobilenet,
return
[
.
mobilenet_ssd
,
.
genet
]
}
}
class
ViewController
:
UIViewController
{
@IBOutlet
weak
var
resultTextView
:
UITextView
!
@IBOutlet
weak
var
selectImageView
:
UIImageView
!
...
...
metal/paddle-mobile/paddle-mobile/Executor.swift
浏览文件 @
cb064033
...
...
@@ -130,11 +130,6 @@ public class Executor<P: PrecisionType> {
// }
// return
// self.ops[testTo].delogOutput()
// self.ops[91].delogOutput()
// self.ops[92].delogOutput()
// self.ops[93].delogOutput()
let
afterDate
=
Date
.
init
()
var
resultHolder
:
ResultHolder
<
P
>
...
...
metal/paddle-mobile/paddle-mobile/Operators/Base/OpCreator.swift
浏览文件 @
cb064033
...
...
@@ -58,7 +58,9 @@ class OpCreator<P: PrecisionType> {
gDwConvBnReluType
:
DwConvBNReluOp
<
P
>.
creat
,
gMulticlassNMSType
:
MulticlassNMSOp
<
P
>.
creat
,
gTransposeType
:
TransposeOp
<
P
>.
creat
,
gPriorBoxType
:
PriorBoxOp
<
P
>.
creat
]
gPriorBoxType
:
PriorBoxOp
<
P
>.
creat
,
gPreluType
:
PreluOp
<
P
>.
creat
,
gConv2dTransposeType
:
ConvTransposeOp
<
P
>.
creat
]
private
init
(){}
}
metal/paddle-mobile/paddle-mobile/Operators/Base/OpParam.swift
浏览文件 @
cb064033
...
...
@@ -50,7 +50,7 @@ protocol OpParam {
static
func
getAttr
<
T
>
(
key
:
String
,
attrs
:
[
String
:
Attr
])
throws
->
T
static
func
i
nputAlpha
<
VarType
:
Variant
>
(
inputs
:
[
String
:
[
String
]],
from
:
Scope
)
throws
->
VarType
static
func
paramI
nputAlpha
<
VarType
:
Variant
>
(
inputs
:
[
String
:
[
String
]],
from
:
Scope
)
throws
->
VarType
}
...
...
@@ -63,9 +63,14 @@ extension OpParam {
guard
let
mapKeys
=
map
[
key
],
mapKeys
.
count
>
0
else
{
throw
PaddleMobileError
.
paramError
(
message
:
key
+
" not found in
\(
map
)
or maped values is empty"
)
}
guard
let
variant
=
from
[
mapKeys
[
0
]]
,
let
v
=
variant
as?
VarType
else
{
guard
let
variant
=
from
[
mapKeys
[
0
]]
else
{
throw
PaddleMobileError
.
paramError
(
message
:
mapKeys
[
0
]
+
" not found in scope"
)
}
guard
let
v
=
variant
as?
VarType
else
{
throw
PaddleMobileError
.
paramError
(
message
:
" type error"
)
}
return
v
}
...
...
@@ -78,7 +83,7 @@ extension OpParam {
}
}
static
func
i
nputAlpha
<
VarType
:
Variant
>
(
inputs
:
[
String
:
[
String
]],
from
:
Scope
)
throws
->
VarType
{
static
func
paramI
nputAlpha
<
VarType
:
Variant
>
(
inputs
:
[
String
:
[
String
]],
from
:
Scope
)
throws
->
VarType
{
do
{
let
alphaTensor
:
VarType
=
try
getFirstTensor
(
key
:
"Alpha"
,
map
:
inputs
,
from
:
from
)
return
alphaTensor
...
...
metal/paddle-mobile/paddle-mobile/Operators/Base/Operator.swift
浏览文件 @
cb064033
...
...
@@ -137,6 +137,9 @@ let gBoxcoderType = "box_coder"
let
gMulticlassNMSType
=
"multiclass_nms"
let
gConvBnReluType
=
"conv_bn_relu"
let
gDwConvBnReluType
=
"depth_conv_bn_relu"
let
gPreluType
=
"prelu"
let
gConv2dTransposeType
=
"conv2d_transpose"
let
opInfos
=
[
gConvType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Output"
]),
gBatchNormType
:
(
inputs
:
[
"X"
],
outputs
:
[
"Y"
]),
...
...
@@ -156,4 +159,7 @@ let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Out
gConvBnReluType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Out"
]),
gDwConvBnReluType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Out"
]),
gMulticlassNMSType
:
(
inputs
:
[
"BBoxes"
,
"Scores"
],
outputs
:
[
"Out"
]),
gPriorBoxType
:
(
inputs
:
[
"Input"
,
"Image"
],
outputs
:
[
"Boxes"
,
"Variances"
])]
gPriorBoxType
:
(
inputs
:
[
"Input"
,
"Image"
],
outputs
:
[
"Boxes"
,
"Variances"
]),
gPreluType
:
(
inputs
:
[
"X"
],
outputs
:
[
"Out"
]),
gConv2dTransposeType
:
(
inputs
:
[
"Input"
],
outputs
:
[
"Output"
])
]
metal/paddle-mobile/paddle-mobile/Operators/ConvAddBatchNormReluOp.swift
浏览文件 @
cb064033
...
...
@@ -34,7 +34,7 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
scale
=
try
ConvAddBatchNormReluParam
.
inputScale
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
mean
=
try
ConvAddBatchNormReluParam
.
inputMean
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
y
=
try
ConvAddBatchNormReluParam
.
inputY
(
inputs
:
opDesc
.
paraI
nputs
,
from
:
inScope
)
y
=
try
ConvAddBatchNormReluParam
.
inputY
(
inputs
:
opDesc
.
i
nputs
,
from
:
inScope
)
}
catch
let
error
{
throw
error
}
...
...
metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift
浏览文件 @
cb064033
...
...
@@ -25,6 +25,7 @@ class ConvAddParam<P: PrecisionType>: OpParam {
paddings
=
try
ConvAddParam
.
getAttr
(
key
:
"paddings"
,
attrs
:
opDesc
.
attrs
)
dilations
=
try
ConvAddParam
.
getAttr
(
key
:
"dilations"
,
attrs
:
opDesc
.
attrs
)
groups
=
try
ConvAddParam
.
getAttr
(
key
:
"groups"
,
attrs
:
opDesc
.
attrs
)
y
=
try
ConvAddParam
.
inputY
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
}
catch
let
error
{
throw
error
...
...
metal/paddle-mobile/paddle-mobile/Operators/ElementwiseAddOp.swift
浏览文件 @
cb064033
...
...
@@ -18,17 +18,27 @@ class ElementwiseAddParam<P: PrecisionType>: OpParam {
typealias
ParamPrecisionType
=
P
required
init
(
opDesc
:
OpDesc
,
inScope
:
Scope
)
throws
{
do
{
input
=
try
ElementwiseAddParam
.
inputX
(
inputs
:
opDesc
.
inputs
,
from
:
inScope
)
inputY
=
try
ElementwiseAddParam
.
inputY
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
}
catch
_
{
do
{
inputYTexture
=
try
ElementwiseAddParam
.
inputX
(
inputs
:
opDesc
.
inputs
,
from
:
inScope
)
}
catch
let
error
{
throw
error
}
}
do
{
input
=
try
ElementwiseAddParam
.
inputX
(
inputs
:
opDesc
.
inputs
,
from
:
inScope
)
output
=
try
ElementwiseAddParam
.
outputOut
(
outputs
:
opDesc
.
outputs
,
from
:
inScope
)
axis
=
try
ElementwiseAddParam
.
getAttr
(
key
:
"axis"
,
attrs
:
opDesc
.
attrs
)
}
catch
let
error
{
throw
error
}
}
let
input
:
Texture
<
P
>
let
inputY
:
Tensor
<
P
>
var
inputYTexture
:
Texture
<
P
>
?
var
inputY
:
Tensor
<
P
>
?
var
input
:
Texture
<
P
>
var
output
:
Texture
<
P
>
let
axis
:
Int
}
...
...
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ElementwiseAddKernel.swift
浏览文件 @
cb064033
...
...
@@ -18,6 +18,7 @@ import Foundation
class
ElementwiseAddKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
ElementwiseAddParam
<
P
>
)
{
super
.
init
(
device
:
device
,
inFunctionName
:
"elementwise_add"
)
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
)
}
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
ElementwiseAddParam
<
P
>
)
throws
{
...
...
metal/paddle-mobile/paddle-mobile/Operators/Kernels/PreluKernel.swift
浏览文件 @
cb064033
...
...
@@ -17,6 +17,7 @@ class PreluKernel<P: PrecisionType>: Kernel, Computable{
}
else
{
super
.
init
(
device
:
device
,
inFunctionName
:
"prelu_other"
)
}
param
.
output
.
initTexture
(
device
:
device
,
inTranspose
:
param
.
input
.
transpose
)
}
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
PreluParam
<
P
>
)
throws
{
...
...
metal/paddle-mobile/paddle-mobile/Operators/PreluOp.swift
浏览文件 @
cb064033
...
...
@@ -21,7 +21,7 @@ class PreluParam<P: PrecisionType>: OpParam {
do
{
input
=
try
PreluParam
.
inputX
(
inputs
:
opDesc
.
inputs
,
from
:
inScope
)
output
=
try
PreluParam
.
outputOut
(
outputs
:
opDesc
.
outputs
,
from
:
inScope
)
alpha
=
try
PreluParam
.
inputAlpha
(
inputs
:
opDesc
.
i
nputs
,
from
:
inScope
)
alpha
=
try
PreluParam
.
paramInputAlpha
(
inputs
:
opDesc
.
paraI
nputs
,
from
:
inScope
)
mode
=
try
PreluParam
.
getAttr
(
key
:
"mode"
,
attrs
:
opDesc
.
attrs
)
}
catch
let
error
{
throw
error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录