Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
0662c069
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看板
提交
0662c069
编写于
9月 02, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
run mobilenet
上级
846bf2ce
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
45 addition
and
50 deletion
+45
-50
metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift
...addle-mobile-demo/paddle-mobile-demo/ViewController.swift
+1
-1
metal/paddle-mobile/paddle-mobile/Executor.swift
metal/paddle-mobile/paddle-mobile/Executor.swift
+8
-6
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
+16
-26
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift
...mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift
+2
-5
metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift
...obile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift
+14
-10
metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift
metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift
+3
-1
未找到文件。
metal/paddle-mobile-demo/paddle-mobile-demo/ViewController.swift
浏览文件 @
0662c069
...
@@ -109,7 +109,7 @@ class ViewController: UIViewController {
...
@@ -109,7 +109,7 @@ class ViewController: UIViewController {
threadPickerView
.
delegate
=
self
threadPickerView
.
delegate
=
self
threadPickerView
.
dataSource
=
self
threadPickerView
.
dataSource
=
self
selectImage
=
UIImage
.
init
(
named
:
"
hand.jp
g"
)
selectImage
=
UIImage
.
init
(
named
:
"
banana.jpe
g"
)
selectImageView
.
image
=
selectImage
selectImageView
.
image
=
selectImage
net
.
getTexture
(
image
:
selectImage
!.
cgImage
!
)
{[
weak
self
]
(
texture
)
in
net
.
getTexture
(
image
:
selectImage
!.
cgImage
!
)
{[
weak
self
]
(
texture
)
in
self
?
.
toPredictTexture
=
texture
self
?
.
toPredictTexture
=
texture
...
...
metal/paddle-mobile/paddle-mobile/Executor.swift
浏览文件 @
0662c069
...
@@ -119,7 +119,7 @@ public class Executor<P: PrecisionType> {
...
@@ -119,7 +119,7 @@ public class Executor<P: PrecisionType> {
// })
// })
// print(inputArr.strideArray())
// print(inputArr.strideArray())
//
//
// writeToLibrary(fileName: "
genet_input_hand
", array: inputArr)
// writeToLibrary(fileName: "
banana
", array: inputArr)
// print("write to library done")
// print("write to library done")
// return
// return
// print(inputArr)
// print(inputArr)
...
@@ -128,11 +128,13 @@ public class Executor<P: PrecisionType> {
...
@@ -128,11 +128,13 @@ public class Executor<P: PrecisionType> {
// print(stridableInput)
// print(stridableInput)
// let _: Flo? = input.logDesc(header: "input: ", stridable: true)
// let _: Flo? = input.logDesc(header: "input: ", stridable: true)
// for i in 0..<self.ops.count {
for
i
in
0
..<
self
.
ops
.
count
{
// let op = self.ops[i]
let
op
=
self
.
ops
[
i
]
// print(" 第 \(i) 个 op: ")
print
(
" 第
\(
i
)
个 op: "
)
// op.delogOutput()
op
.
delogOutput
()
// }
}
// return;
// self.ops[testTo - 2].delogOutput()
// self.ops[testTo - 2].delogOutput()
// self.ops[testTo - 1].delogOutput()
// self.ops[testTo - 1].delogOutput()
// self.ops[60].delogOutput()
// self.ops[60].delogOutput()
...
...
metal/paddle-mobile/paddle-mobile/Operators/ConvAddBatchNormReluOp.swift
浏览文件 @
0662c069
...
@@ -34,7 +34,7 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
...
@@ -34,7 +34,7 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
scale
=
try
ConvAddBatchNormReluParam
.
inputScale
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
scale
=
try
ConvAddBatchNormReluParam
.
inputScale
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
mean
=
try
ConvAddBatchNormReluParam
.
inputMean
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
mean
=
try
ConvAddBatchNormReluParam
.
inputMean
(
inputs
:
opDesc
.
paraInputs
,
from
:
inScope
)
y
=
try
ConvAddBatchNormReluParam
.
inputY
(
inputs
:
opDesc
.
i
nputs
,
from
:
inScope
)
y
=
try
ConvAddBatchNormReluParam
.
inputY
(
inputs
:
opDesc
.
paraI
nputs
,
from
:
inScope
)
}
catch
let
error
{
}
catch
let
error
{
throw
error
throw
error
}
}
...
...
metal/paddle-mobile/paddle-mobile/Operators/ConvAddOp.swift
浏览文件 @
0662c069
...
@@ -93,34 +93,24 @@ class ConvAddOp<P: PrecisionType>: Operator<ConvAddKernel<P>, ConvAddParam<P>>,
...
@@ -93,34 +93,24 @@ class ConvAddOp<P: PrecisionType>: Operator<ConvAddKernel<P>, ConvAddParam<P>>,
}
}
func
delogOutput
()
{
func
delogOutput
()
{
// print("op \(type): ")
// print(" padding: ")
// print(para.paddings)
// print("stride: ")
// print(para.stride)
// print("dilations: ")
// print(para.dilations)
// print(" para input dim: ")
// print(para.input.dim)
// print(" para filter dim: ")
// print(para.filter.dim)
// print(" para output dim: ")
// print(para.output.dim)
// print(" biase: ")
// let biase: [Float32] = para.y.buffer.array()
// print(biase)
print
(
"op
\(
type
)
: "
)
print
(
"
\(
type
)
output: "
)
print
(
"
\(
type
)
output: "
)
print
(
" padding: "
)
print
(
para
.
paddings
)
print
(
"stride: "
)
print
(
para
.
stride
)
print
(
"dilations: "
)
print
(
para
.
dilations
)
print
(
" para input dim: "
)
print
(
para
.
input
.
dim
)
print
(
" para filter dim: "
)
print
(
para
.
filter
.
dim
)
print
(
" para output dim: "
)
print
(
para
.
output
.
dim
)
print
(
" biase: "
)
let
biase
:
[
Float32
]
=
para
.
y
.
buffer
.
array
()
print
(
biase
)
print
(
" - filter - "
)
let
array
:
[
Float32
]
=
para
.
filter
.
buffer
.
array
()
print
(
array
)
print
(
" - y - "
)
let
yArray
:
[
Float32
]
=
para
.
y
.
buffer
.
array
()
print
(
yArray
)
print
(
para
.
output
.
metalTexture
.
toTensor
(
dim
:
(
n
:
para
.
output
.
tensorDim
[
0
],
c
:
para
.
output
.
tensorDim
[
1
],
h
:
para
.
output
.
tensorDim
[
2
],
w
:
para
.
output
.
tensorDim
[
3
]))
.
strideArray
())
print
(
para
.
output
.
metalTexture
.
toTensor
(
dim
:
(
n
:
para
.
output
.
tensorDim
[
0
],
c
:
para
.
output
.
tensorDim
[
1
],
h
:
para
.
output
.
tensorDim
[
2
],
w
:
para
.
output
.
tensorDim
[
3
]))
.
strideArray
())
}
}
}
}
metal/paddle-mobile/paddle-mobile/Operators/Kernels/ConvAddBatchNormReluKernel.swift
浏览文件 @
0662c069
...
@@ -81,8 +81,6 @@ class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable
...
@@ -81,8 +81,6 @@ class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable
fatalError
()
fatalError
()
}
}
let
offsetX
=
param
.
filter
.
width
/
2
-
Int
(
param
.
paddings
[
0
])
let
offsetX
=
param
.
filter
.
width
/
2
-
Int
(
param
.
paddings
[
0
])
let
offsetY
=
param
.
filter
.
height
/
2
-
Int
(
param
.
paddings
[
1
])
let
offsetY
=
param
.
filter
.
height
/
2
-
Int
(
param
.
paddings
[
1
])
...
@@ -121,10 +119,10 @@ class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable
...
@@ -121,10 +119,10 @@ class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable
var
newBiaseBuffer
:
MTLBuffer
var
newBiaseBuffer
:
MTLBuffer
var
newScaleBuffer
:
MTLBuffer
var
newScaleBuffer
:
MTLBuffer
if
computePrecision
==
.
Float
16
{
if
computePrecision
==
.
Float
32
{
newBiaseBuffer
=
device
.
makeBuffer
(
bytes
:
newBiase
,
length
:
param
.
bias
.
buffer
.
length
)
!
newBiaseBuffer
=
device
.
makeBuffer
(
bytes
:
newBiase
,
length
:
param
.
bias
.
buffer
.
length
)
!
newScaleBuffer
=
device
.
makeBuffer
(
bytes
:
newScale
,
length
:
param
.
scale
.
buffer
.
length
)
!
newScaleBuffer
=
device
.
makeBuffer
(
bytes
:
newScale
,
length
:
param
.
scale
.
buffer
.
length
)
!
}
else
if
computePrecision
==
.
Float
32
{
}
else
if
computePrecision
==
.
Float
16
{
newBiaseBuffer
=
device
.
makeBuffer
(
length
:
param
.
bias
.
buffer
.
length
/
2
)
!
newBiaseBuffer
=
device
.
makeBuffer
(
length
:
param
.
bias
.
buffer
.
length
/
2
)
!
newScaleBuffer
=
device
.
makeBuffer
(
length
:
param
.
bias
.
buffer
.
length
/
2
)
!
newScaleBuffer
=
device
.
makeBuffer
(
length
:
param
.
bias
.
buffer
.
length
/
2
)
!
...
@@ -151,7 +149,6 @@ class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable
...
@@ -151,7 +149,6 @@ class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
throw
PaddleMobileError
.
predictError
(
message
:
" encode is nil"
)
}
}
encoder
.
setTexture
(
param
.
input
.
metalTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
input
.
metalTexture
,
index
:
0
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
setTexture
(
param
.
output
.
metalTexture
,
index
:
1
)
encoder
.
setBytes
(
&
metalParam
,
length
:
MemoryLayout
<
MetalConvParam
>.
size
,
index
:
0
)
encoder
.
setBytes
(
&
metalParam
,
length
:
MemoryLayout
<
MetalConvParam
>.
size
,
index
:
0
)
...
...
metal/paddle-mobile/paddle-mobile/Operators/Kernels/SoftmaxKernel.swift
浏览文件 @
0662c069
...
@@ -21,6 +21,17 @@ struct SoftmaxMetalParam {
...
@@ -21,6 +21,17 @@ struct SoftmaxMetalParam {
class
SoftmaxKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
class
SoftmaxKernel
<
P
:
PrecisionType
>
:
Kernel
,
Computable
{
required
init
(
device
:
MTLDevice
,
param
:
SoftmaxParam
<
P
>
)
{
param
.
output
.
initTexture
(
device
:
device
,
computePrecision
:
computePrecision
)
if
computePrecision
==
.
Float32
{
super
.
init
(
device
:
device
,
inFunctionName
:
"softmax"
)
}
else
if
computePrecision
==
.
Float16
{
super
.
init
(
device
:
device
,
inFunctionName
:
"softmax_half"
)
}
else
{
fatalError
()
}
}
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
SoftmaxParam
<
P
>
)
throws
{
func
compute
(
commandBuffer
:
MTLCommandBuffer
,
param
:
SoftmaxParam
<
P
>
)
throws
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
guard
let
encoder
=
commandBuffer
.
makeComputeCommandEncoder
()
else
{
throw
PaddleMobileError
.
predictError
(
message
:
" encoder is nil"
)
throw
PaddleMobileError
.
predictError
(
message
:
" encoder is nil"
)
...
@@ -32,19 +43,12 @@ class SoftmaxKernel<P: PrecisionType>: Kernel, Computable{
...
@@ -32,19 +43,12 @@ class SoftmaxKernel<P: PrecisionType>: Kernel, Computable{
N
:
Int32
(
param
.
input
.
tensorDim
[
0
]),
N
:
Int32
(
param
.
input
.
tensorDim
[
0
]),
K
:
Int32
(
param
.
input
.
tensorDim
[
1
])
K
:
Int32
(
param
.
input
.
tensorDim
[
1
])
)
)
print
(
" soft max param: "
)
print
(
smp
)
encoder
.
setBytes
(
&
smp
,
length
:
MemoryLayout
<
SoftmaxMetalParam
>.
size
,
index
:
0
)
encoder
.
setBytes
(
&
smp
,
length
:
MemoryLayout
<
SoftmaxMetalParam
>.
size
,
index
:
0
)
encoder
.
dispatch
(
computePipline
:
pipline
,
outTexture
:
param
.
output
.
metalTexture
)
encoder
.
dispatch
(
computePipline
:
pipline
,
outTexture
:
param
.
output
.
metalTexture
)
encoder
.
endEncoding
()
encoder
.
endEncoding
()
}
}
required
init
(
device
:
MTLDevice
,
param
:
SoftmaxParam
<
P
>
)
{
param
.
output
.
initTexture
(
device
:
device
,
computePrecision
:
computePrecision
)
if
computePrecision
==
.
Float32
{
super
.
init
(
device
:
device
,
inFunctionName
:
"softmax"
)
}
else
if
computePrecision
==
.
Float16
{
super
.
init
(
device
:
device
,
inFunctionName
:
"softmax_half"
)
}
else
{
fatalError
()
}
}
}
}
metal/paddle-mobile/paddle-mobile/Operators/SoftmaxOp.swift
浏览文件 @
0662c069
...
@@ -52,7 +52,9 @@ class SoftmaxOp<P: PrecisionType>: Operator<SoftmaxKernel<P>, SoftmaxParam<P>>,
...
@@ -52,7 +52,9 @@ class SoftmaxOp<P: PrecisionType>: Operator<SoftmaxKernel<P>, SoftmaxParam<P>>,
func
delogOutput
()
{
func
delogOutput
()
{
print
(
"softmax delog"
)
print
(
"softmax delog"
)
print
(
para
.
input
)
print
(
para
.
output
)
let
originDim
=
para
.
output
.
originDim
let
originDim
=
para
.
output
.
originDim
let
outputArray
:
[
Float32
]
=
para
.
output
.
metalTexture
.
realNHWC
(
dim
:
(
n
:
originDim
[
0
],
h
:
originDim
[
1
],
w
:
originDim
[
2
],
c
:
originDim
[
3
]))
let
outputArray
:
[
Float32
]
=
para
.
output
.
metalTexture
.
realNHWC
(
dim
:
(
n
:
originDim
[
0
],
h
:
originDim
[
1
],
w
:
originDim
[
2
],
c
:
originDim
[
3
]))
print
(
outputArray
.
strideArray
())
print
(
outputArray
.
strideArray
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录