Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
2c2347df
P
Paddle
项目概览
OPTHREE
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c2347df
编写于
2月 27, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/PaddlePaddle/Paddle
into convert
上级
72c13278
111e7710
变更
24
显示空白变更内容
内联
并排
Showing
24 changed file
with
254 addition
and
30 deletion
+254
-30
demo/image_classification/prediction.py
demo/image_classification/prediction.py
+1
-1
demo/model_zoo/resnet/classify.py
demo/model_zoo/resnet/classify.py
+1
-1
paddle/api/Arguments.cpp
paddle/api/Arguments.cpp
+7
-0
paddle/api/GradientMachine.cpp
paddle/api/GradientMachine.cpp
+4
-4
paddle/api/PaddleAPI.h
paddle/api/PaddleAPI.h
+3
-2
paddle/api/Trainer.cpp
paddle/api/Trainer.cpp
+4
-5
paddle/gserver/gradientmachines/GradientMachine.h
paddle/gserver/gradientmachines/GradientMachine.h
+4
-0
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
+12
-0
paddle/gserver/gradientmachines/MultiGradientMachine.h
paddle/gserver/gradientmachines/MultiGradientMachine.h
+4
-0
paddle/gserver/gradientmachines/NeuralNetwork.cpp
paddle/gserver/gradientmachines/NeuralNetwork.cpp
+3
-4
paddle/gserver/gradientmachines/NeuralNetwork.h
paddle/gserver/gradientmachines/NeuralNetwork.h
+2
-1
paddle/gserver/layers/CosSimLayer.cpp
paddle/gserver/layers/CosSimLayer.cpp
+2
-2
paddle/gserver/layers/CosSimVecMatLayer.cpp
paddle/gserver/layers/CosSimVecMatLayer.cpp
+2
-2
paddle/math/tests/test_RowBuffer.cpp
paddle/math/tests/test_RowBuffer.cpp
+4
-4
paddle/py_paddle/util.py
paddle/py_paddle/util.py
+1
-1
python/paddle/reader/__init__.py
python/paddle/reader/__init__.py
+2
-0
python/paddle/reader/creator.py
python/paddle/reader/creator.py
+53
-0
python/paddle/reader/tests/CMakeLists.txt
python/paddle/reader/tests/CMakeLists.txt
+5
-0
python/paddle/reader/tests/creator_test.py
python/paddle/reader/tests/creator_test.py
+38
-0
python/paddle/reader/tests/test_data_creator.txt
python/paddle/reader/tests/test_data_creator.txt
+3
-0
python/paddle/v2/dataset/__init__.py
python/paddle/v2/dataset/__init__.py
+0
-0
python/paddle/v2/dataset/config.py
python/paddle/v2/dataset/config.py
+8
-0
python/paddle/v2/dataset/mnist.py
python/paddle/v2/dataset/mnist.py
+39
-0
python/paddle/v2/optimizer.py
python/paddle/v2/optimizer.py
+52
-3
未找到文件。
demo/image_classification/prediction.py
浏览文件 @
2c2347df
...
...
@@ -126,7 +126,7 @@ class ImageClassifier():
# For oversampling, average predictions across crops.
# If not, the shape of output[name]: (1, class_number),
# the mean is also applicable.
return
output
[
output_layer
].
mean
(
0
)
return
output
[
output_layer
]
[
'value'
]
.
mean
(
0
)
def
predict
(
self
,
image
=
None
,
output_layer
=
None
):
assert
isinstance
(
image
,
basestring
)
...
...
demo/model_zoo/resnet/classify.py
浏览文件 @
2c2347df
...
...
@@ -156,7 +156,7 @@ class ImageClassifier():
# For oversampling, average predictions across crops.
# If not, the shape of output[name]: (1, class_number),
# the mean is also applicable.
res
[
name
]
=
output
[
name
].
mean
(
0
)
res
[
name
]
=
output
[
name
]
[
'value'
]
.
mean
(
0
)
return
res
...
...
paddle/api/Arguments.cpp
浏览文件 @
2c2347df
...
...
@@ -38,6 +38,13 @@ Arguments* Arguments::createByPaddleArgumentVector(void* ptr) {
return
args
;
}
Arguments
*
Arguments
::
createByPaddleArgument
(
const
void
*
ptr
)
{
auto
p
=
(
paddle
::
Argument
*
)(
ptr
);
auto
args
=
new
Arguments
();
args
->
m
->
outputs
.
push_back
(
*
p
);
return
args
;
}
Matrix
*
Arguments
::
getSlotValue
(
size_t
idx
)
const
throw
(
RangeError
)
{
auto
&
a
=
m
->
getArg
(
idx
);
return
Matrix
::
createByPaddleMatrixPtr
(
&
a
.
value
);
...
...
paddle/api/GradientMachine.cpp
浏览文件 @
2c2347df
...
...
@@ -144,12 +144,12 @@ Parameter* GradientMachine::getParameter(size_t i) throw(RangeError) {
void
GradientMachine
::
randParameters
()
{
m
->
machine
->
randParameters
();
}
Matrix
*
GradientMachine
::
getLayerOutput
(
const
std
::
string
&
layerName
)
const
Arguments
*
GradientMachine
::
getLayerOutput
(
const
std
::
string
&
layerName
)
const
throw
(
UnsupportError
)
{
auto
nn
=
std
::
dynamic_pointer_cast
<
paddle
::
NeuralNetwork
>
(
m
->
machine
)
;
auto
nn
=
m
->
machine
;
if
(
nn
)
{
auto
mat
=
nn
->
getLayerOutput
(
layerName
);
return
Matrix
::
createByPaddleMatrixPtr
(
&
mat
);
auto
arg
=
nn
->
getLayerOutput
(
layerName
);
return
Arguments
::
createByPaddleArgument
(
&
arg
);
}
else
{
throw
UnsupportError
();
}
...
...
paddle/api/PaddleAPI.h
浏览文件 @
2c2347df
...
...
@@ -454,6 +454,7 @@ public:
private:
static
Arguments
*
createByPaddleArgumentVector
(
void
*
ptr
);
static
Arguments
*
createByPaddleArgument
(
const
void
*
ptr
);
void
*
getInternalArgumentsPtr
()
const
;
private:
...
...
@@ -769,7 +770,7 @@ public:
void
randParameters
();
Matrix
*
getLayerOutput
(
const
std
::
string
&
layerName
)
const
Arguments
*
getLayerOutput
(
const
std
::
string
&
layerName
)
const
throw
(
UnsupportError
);
/**
...
...
@@ -956,7 +957,7 @@ public:
Arguments
*
getForwardOutput
();
Matrix
*
getLayerOutput
(
const
std
::
string
&
layerName
)
;
Arguments
*
getLayerOutput
(
const
std
::
string
&
layerName
)
const
;
};
/// the N-Best results generated from one input sequence.
...
...
paddle/api/Trainer.cpp
浏览文件 @
2c2347df
...
...
@@ -131,12 +131,11 @@ void Trainer::testOneDataBatch(size_t batchSize, const Arguments& args) {
void
TrainerPrivate
::
finishTestPeriod
()
{
tester_
->
finishTestPeriod
();
}
void
Trainer
::
finishTestPeriod
()
{
m
->
finishTestPeriod
();
}
Matrix
*
Trainer
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
auto
nn
=
std
::
dynamic_pointer_cast
<
paddle
::
NeuralNetwork
>
(
this
->
m
->
getGradientMachine
());
Arguments
*
Trainer
::
getLayerOutput
(
const
std
::
string
&
layerName
)
const
{
auto
nn
=
this
->
m
->
getGradientMachine
();
CHECK
(
nn
)
<<
"trainerInternal_.getGradientMachine() is not NeuralNetwork"
;
auto
m
=
nn
->
getLayerOutput
(
layerName
);
return
Matrix
::
createByPaddleMatrixPtr
(
&
m
);
auto
arg
=
nn
->
getLayerOutput
(
layerName
);
return
Arguments
::
createByPaddleArgument
(
&
arg
);
}
void
Trainer
::
forwardOneBatch
(
size_t
batchSize
)
{
...
...
paddle/gserver/gradientmachines/GradientMachine.h
浏览文件 @
2c2347df
...
...
@@ -134,6 +134,10 @@ public:
backward
(
callback
);
}
virtual
Argument
getLayerOutput
(
const
std
::
string
&
layerName
)
{
return
*
((
Argument
*
)
nullptr
);
}
// see comment in Layer.h for the function with the same name
virtual
void
resetState
()
{}
...
...
paddle/gserver/gradientmachines/MultiGradientMachine.cpp
浏览文件 @
2c2347df
...
...
@@ -282,6 +282,18 @@ void MultiGradientMachine::forwardBackward(const std::vector<Argument>& inArgs,
backwardImp
(
callback
);
}
Argument
MultiGradientMachine
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
std
::
vector
<
Argument
>
args
;
args
.
reserve
(
threads_
.
size
());
for
(
auto
&
thread
:
threads_
)
{
args
.
push_back
(
thread
->
getGradientMachine
()
->
getLayerOutput
(
layerName
));
}
outLayerArgs_
.
concat
(
args
,
false
/* use_gpu */
,
outArgStream_
,
passType_
);
return
outLayerArgs_
;
}
void
MultiGradientMachine
::
backwardImp
(
const
UpdateCallback
&
callback
)
{
for
(
size_t
i
=
0
;
i
<
parameters_
.
size
();
i
++
)
{
if
(
!
parameters_
[
i
]
->
useGpu
()
||
parameters_
[
i
]
->
isStatic
())
continue
;
...
...
paddle/gserver/gradientmachines/MultiGradientMachine.h
浏览文件 @
2c2347df
...
...
@@ -189,6 +189,8 @@ public:
PassType
passType
,
const
UpdateCallback
&
callback
);
virtual
Argument
getLayerOutput
(
const
std
::
string
&
layerName
);
virtual
void
onPassEnd
();
virtual
void
finish
();
...
...
@@ -314,6 +316,8 @@ protected:
std
::
vector
<
Argument
>
outArgs_
;
hl_stream_t
outArgStream_
;
Argument
outLayerArgs_
;
/// ParameterType which needs to be merged from each GPU
std
::
vector
<
ParameterType
>
mergeTypes_
;
int
numDevices_
;
/* number of gpu devices */
...
...
paddle/gserver/gradientmachines/NeuralNetwork.cpp
浏览文件 @
2c2347df
...
...
@@ -293,11 +293,10 @@ void NeuralNetwork::backward(const UpdateCallback& callback) {
}
}
MatrixPtr
NeuralNetwork
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
auto
it
=
layerMap_
.
find
(
layerName
);
CHECK
(
it
!=
layerMap_
.
end
())
<<
"Cannot find layer: "
<<
layerName
;
return
it
->
second
->
getOutputValue
();
Argument
NeuralNetwork
::
getLayerOutput
(
const
std
::
string
&
layerName
)
{
return
getLayer
(
layerName
)
->
getOutput
();
}
void
NeuralNetwork
::
onPassEnd
()
{
for
(
auto
&
layer
:
layers_
)
{
layer
->
onPassEnd
();
...
...
paddle/gserver/gradientmachines/NeuralNetwork.h
浏览文件 @
2c2347df
...
...
@@ -87,7 +87,8 @@ public:
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
MatrixPtr
getLayerOutput
(
const
std
::
string
&
layerName
);
virtual
Argument
getLayerOutput
(
const
std
::
string
&
layerName
);
const
LayerPtr
&
getLayer
(
const
std
::
string
&
layerName
)
const
{
auto
it
=
layerMap_
.
find
(
layerName
);
CHECK
(
it
!=
layerMap_
.
end
())
<<
"Unknown layer "
<<
layerName
;
...
...
paddle/gserver/layers/CosSimLayer.cpp
浏览文件 @
2c2347df
...
...
@@ -42,7 +42,7 @@ void CosSimLayer::forward(PassType passType) {
/* malloc memory for the output_ if necessary */
int
batchSize
=
getInputValue
(
0
)
->
getHeight
();
int
size
=
getSize
();
CHECK_EQ
(
forward_
.
size
(),
1
)
<<
"Only one forward function needed"
;
CHECK_EQ
(
forward_
.
size
(),
1
UL
)
<<
"Only one forward function needed"
;
{
REGISTER_TIMER_INFO
(
"CosFwResetTimer"
,
getName
().
c_str
());
...
...
@@ -68,7 +68,7 @@ void CosSimLayer::forward(PassType passType) {
void
CosSimLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
/* activation */
{
REGISTER_TIMER_INFO
(
"CosBpAtvTimer"
,
getName
().
c_str
());
CHECK_EQ
(
backward_
.
size
(),
1
)
<<
"Only one backward function needed"
;
CHECK_EQ
(
backward_
.
size
(),
1
UL
)
<<
"Only one backward function needed"
;
const
auto
outG
=
this
->
getOutputGrad
();
const
auto
outV
=
this
->
getOutputValue
();
...
...
paddle/gserver/layers/CosSimVecMatLayer.cpp
浏览文件 @
2c2347df
...
...
@@ -112,7 +112,7 @@ bool CosSimVecMatLayer::init(const LayerMap& layerMap,
void
CosSimVecMatLayer
::
forward
(
PassType
passType
)
{
Layer
::
forward
(
passType
);
CHECK_EQ
(
forward_
.
size
(),
1
)
<<
"Only one forward function needed"
;
CHECK_EQ
(
forward_
.
size
(),
1
UL
)
<<
"Only one forward function needed"
;
MatrixPtr
inV0
=
getInputValue
(
0
);
MatrixPtr
inV1
=
getInputValue
(
1
);
...
...
@@ -145,7 +145,7 @@ void CosSimVecMatLayer::forward(PassType passType) {
}
void
CosSimVecMatLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
CHECK_EQ
(
backward_
.
size
(),
1
)
<<
"Only one forward function needed"
;
CHECK_EQ
(
backward_
.
size
(),
1
UL
)
<<
"Only one forward function needed"
;
MatrixPtr
inV0
=
getInputValue
(
0
);
MatrixPtr
inV1
=
getInputValue
(
1
);
...
...
paddle/math/tests/test_RowBuffer.cpp
浏览文件 @
2c2347df
...
...
@@ -17,10 +17,10 @@ limitations under the License. */
TEST
(
RowBuffer
,
testAutoGrow
)
{
paddle
::
RowBuffer
buf
(
128
);
ASSERT_EQ
(
128
,
buf
.
getWidth
());
ASSERT_EQ
(
128
UL
,
buf
.
getWidth
());
ASSERT_TRUE
(
buf
.
isAutoGrowth
());
buf
.
resize
(
2
);
ASSERT_EQ
(
2
,
buf
.
getRowCount
());
ASSERT_EQ
(
2
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
buf
.
data
()[
i
]
=
i
;
}
...
...
@@ -35,7 +35,7 @@ TEST(RowBuffer, testAutoGrow) {
data
[
i
]
=
i
;
}
ASSERT_EQ
(
3
,
buf
.
getRowCount
());
ASSERT_EQ
(
3
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getRowCount
()
-
1
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
buf
.
getWidth
();
++
j
)
{
ASSERT_NEAR
(
i
*
buf
.
getWidth
()
+
j
,
buf
.
get
(
i
)[
j
],
1e-5
);
...
...
@@ -51,7 +51,7 @@ TEST(RowBuffer, testWithMemBuf) {
std
::
make_shared
<
paddle
::
CpuMemoryHandle
>
(
128
*
2
*
sizeof
(
real
));
paddle
::
RowBuffer
buf
(
mem
,
128
);
ASSERT_TRUE
(
!
buf
.
isAutoGrowth
());
ASSERT_EQ
(
2
,
buf
.
getRowCount
());
ASSERT_EQ
(
2
UL
,
buf
.
getRowCount
());
for
(
size_t
i
=
0
;
i
<
buf
.
getWidth
()
*
2
;
++
i
)
{
buf
.
data
()[
i
]
=
i
;
}
...
...
paddle/py_paddle/util.py
浏览文件 @
2c2347df
...
...
@@ -208,7 +208,7 @@ def __monkeypatch_gradient_machine__():
output
=
dict
()
for
name
in
layerNames
:
output
[
name
]
=
__
matrix_to_numpy__
(
self
.
getLayerOutput
(
name
))
output
[
name
]
=
__
arguments_to_numpy__
(
0
,
self
.
getLayerOutput
(
name
))
return
output
swig_paddle
.
GradientMachine
.
getLayerOutputs
=
getLayerOutputs
...
...
python/paddle/reader/__init__.py
浏览文件 @
2c2347df
...
...
@@ -21,3 +21,5 @@
#
# r = paddle.reader.buffered(paddle.reader.creator.text("hello.txt"))
from
decorator
import
*
import
creator
python/paddle/reader/creator.py
0 → 100644
浏览文件 @
2c2347df
# Copyright (c) 2016 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.
__all__
=
[
'np_array'
,
'text_file'
]
def
np_array
(
x
):
"""
Creates a reader that yields elements of x, if it is a
numpy vector. Or rows of x, if it is a numpy matrix.
Or any sub-hyperplane indexed by the highest dimension.
:param x: the numpy array to create reader from.
:returns: data reader created from x.
"""
def
reader
():
if
x
.
ndim
<
1
:
yield
x
for
e
in
x
:
yield
e
return
reader
def
text_file
(
path
):
"""
Creates a data reader that outputs text line by line from given text file.
Trailing new line ('
\n
') of each line will be removed.
:path: path of the text file.
:returns: data reader of text file
"""
def
reader
():
f
=
open
(
path
,
"r"
)
for
l
in
f
:
yield
l
.
rstrip
(
'
\n
'
)
f
.
close
()
return
reader
python/paddle/reader/tests/CMakeLists.txt
浏览文件 @
2c2347df
...
...
@@ -2,3 +2,8 @@ add_test(NAME reader_decorator_test
COMMAND
${
PROJ_ROOT
}
/paddle/.set_python_path.sh -d
${
PROJ_ROOT
}
/python/
${
PYTHON_EXECUTABLE
}
${
PROJ_ROOT
}
/python/paddle/reader/tests/decorator_test.py
WORKING_DIRECTORY
${
PROJ_ROOT
}
/python/paddle
)
add_test
(
NAME reader_creator_test
COMMAND
${
PROJ_ROOT
}
/paddle/.set_python_path.sh -d
${
PROJ_ROOT
}
/python/
${
PYTHON_EXECUTABLE
}
${
PROJ_ROOT
}
/python/paddle/reader/tests/creator_test.py
WORKING_DIRECTORY
${
PROJ_ROOT
}
/python/paddle
)
python/paddle/reader/tests/creator_test.py
0 → 100644
浏览文件 @
2c2347df
# Copyright PaddlePaddle contributors. 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
unittest
import
paddle.reader.creator
import
numpy
as
np
import
os
class
TestNumpyArray
(
unittest
.
TestCase
):
def
test_numpy_array
(
self
):
l
=
[[
1
,
2
,
3
],
[
4
,
5
,
6
]]
x
=
np
.
array
(
l
,
np
.
int32
)
reader
=
paddle
.
reader
.
creator
.
np_array
(
x
)
for
idx
,
e
in
enumerate
(
reader
()):
self
.
assertItemsEqual
(
e
,
l
[
idx
])
class
TestTextFile
(
unittest
.
TestCase
):
def
test_text_file
(
self
):
path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"test_data_creator.txt"
)
reader
=
paddle
.
reader
.
creator
.
text_file
(
path
)
for
idx
,
e
in
enumerate
(
reader
()):
self
.
assertEqual
(
e
,
str
(
idx
*
2
)
+
" "
+
str
(
idx
*
2
+
1
))
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/reader/tests/test_data_creator.txt
0 → 100644
浏览文件 @
2c2347df
0 1
2 3
4 5
python/paddle/v2/dataset/__init__.py
0 → 100644
浏览文件 @
2c2347df
python/paddle/v2/dataset/config.py
0 → 100644
浏览文件 @
2c2347df
import
os
__all__
=
[
'DATA_HOME'
]
DATA_HOME
=
os
.
path
.
expanduser
(
'~/.cache/paddle_data_set'
)
if
not
os
.
path
.
exists
(
DATA_HOME
):
os
.
makedirs
(
DATA_HOME
)
python/paddle/v2/dataset/mnist.py
0 → 100644
浏览文件 @
2c2347df
import
sklearn.datasets.mldata
import
sklearn.model_selection
import
numpy
from
config
import
DATA_HOME
__all__
=
[
'train_creator'
,
'test_creator'
]
def
__mnist_reader_creator__
(
data
,
target
):
def
reader
():
n_samples
=
data
.
shape
[
0
]
for
i
in
xrange
(
n_samples
):
yield
(
data
[
i
]
/
255.0
).
astype
(
numpy
.
float32
),
int
(
target
[
i
])
return
reader
TEST_SIZE
=
10000
data
=
sklearn
.
datasets
.
mldata
.
fetch_mldata
(
"MNIST original"
,
data_home
=
DATA_HOME
)
X_train
,
X_test
,
y_train
,
y_test
=
sklearn
.
model_selection
.
train_test_split
(
data
.
data
,
data
.
target
,
test_size
=
TEST_SIZE
,
random_state
=
0
)
def
train_creator
():
return
__mnist_reader_creator__
(
X_train
,
y_train
)
def
test_creator
():
return
__mnist_reader_creator__
(
X_test
,
y_test
)
def
unittest
():
assert
len
(
list
(
test_creator
()()))
==
TEST_SIZE
if
__name__
==
'__main__'
:
unittest
()
python/paddle/v2/optimizer.py
浏览文件 @
2c2347df
...
...
@@ -3,7 +3,10 @@ import paddle.trainer_config_helpers.optimizers as v1_optimizers
import
paddle.trainer_config_helpers.config_parser_utils
as
config_parser_utils
import
paddle.v2
__all__
=
[
'Adam'
,
'Adamax'
]
__all__
=
[
'Momentum'
,
'Adam'
,
'Adamax'
,
'AdaGrad'
,
'DecayedAdaGrad'
,
'AdaDelta'
,
'RMSProp'
,
'ModelAverage'
,
'L2Regularization'
]
class
Optimizer
(
object
):
...
...
@@ -38,6 +41,14 @@ class Optimizer(object):
pass_num
)
class
Momentum
(
Optimizer
):
def
__init__
(
self
,
momentum
=
None
,
sparse
=
False
,
**
kwargs
):
learning_method
=
v1_optimizers
.
MomentumOptimizer
(
momentum
=
None
,
sparse
=
False
)
super
(
Momentum
,
self
).
__init__
(
learning_method
=
learning_method
,
**
kwargs
)
class
Adam
(
Optimizer
):
def
__init__
(
self
,
beta1
=
0.9
,
beta2
=
0.999
,
epsilon
=
1e-8
,
**
kwargs
):
learning_method
=
v1_optimizers
.
AdamOptimizer
(
...
...
@@ -52,7 +63,45 @@ class Adamax(Optimizer):
super
(
Adamax
,
self
).
__init__
(
learning_method
=
learning_method
,
**
kwargs
)
class
AdaGrad
(
Optimizer
):
def
__init__
(
self
,
**
kwargs
):
learning_method
=
v1_optimizers
.
AdaGradOptimizer
()
super
(
AdaGrad
,
self
).
__init__
(
learning_method
=
learning_method
,
**
kwargs
)
class
DecayedAdaGrad
(
Optimizer
):
def
__init__
(
self
,
rho
=
0.95
,
epsilon
=
1e-06
,
**
kwargs
):
learning_method
=
v1_optimizers
.
DecayedAdaGradOptimizer
(
rho
=
rho
,
epsilon
=
epsilon
)
super
(
DecayedAdaGrad
,
self
).
__init__
(
learning_method
=
learning_method
,
**
kwargs
)
class
AdaDelta
(
Optimizer
):
def
__init__
(
self
,
rho
=
0.95
,
epsilon
=
1e-06
,
**
kwargs
):
learning_method
=
v1_optimizers
.
AdaDeltaOptimizer
(
rho
=
rho
,
epsilon
=
epsilon
)
super
(
AdaDelta
,
self
).
__init__
(
learning_method
=
learning_method
,
**
kwargs
)
class
RMSProp
(
Optimizer
):
def
__init__
(
self
,
rho
=
0.95
,
epsilon
=
1e-6
,
**
kwargs
):
learning_method
=
v1_optimizers
.
RMSPropOptimizer
(
rho
=
rho
,
epsilon
=
epsilon
)
super
(
RMSProp
,
self
).
__init__
(
learning_method
=
learning_method
,
**
kwargs
)
ModelAverage
=
v1_optimizers
.
ModelAverage
L2Regularization
=
v1_optimizers
.
L2Regularization
if
__name__
==
'__main__'
:
swig_api
.
initPaddle
(
'--use_gpu=false'
)
opt
=
paddle
.
v2
.
optimizer
.
Adam
()
print
opt
.
enable_types
()
for
opt
in
[
Momentum
(),
Adam
(),
Adamax
(),
AdaGrad
(),
DecayedAdaGrad
(),
AdaDelta
(),
RMSProp
(),
Adam
(
model_average
=
ModelAverage
(
average_window
=
0.5
),
regularization
=
L2Regularization
(
rate
=
0.5
),
gradient_clipping_threshold
=
25
)
]:
print
opt
,
opt
.
enable_types
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录