Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c6d90a7b
提交
c6d90a7b
authored
6月 29, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update test
上级
73efa875
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
15 行删除
+21
-15
test_nnet.py
theano/sandbox/gpuarray/tests/test_nnet.py
+21
-15
没有找到文件。
theano/sandbox/gpuarray/tests/test_nnet.py
浏览文件 @
c6d90a7b
from
__future__
import
print_function
from
__future__
import
print_function
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
import
unittest
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
...
@@ -291,6 +292,7 @@ def softmax_unittest_template(dtypeInput):
...
@@ -291,6 +292,7 @@ def softmax_unittest_template(dtypeInput):
cmp
(
128
,
16
*
1024
)
cmp
(
128
,
16
*
1024
)
cmp
(
128
,
64
*
1024
)
cmp
(
128
,
64
*
1024
)
class
test_SoftMax
(
unittest
.
TestCase
):
class
test_SoftMax
(
unittest
.
TestCase
):
def
_test_softmax
(
def
_test_softmax
(
self
,
self
,
...
@@ -356,7 +358,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -356,7 +358,7 @@ class test_SoftMax(unittest.TestCase):
def
test_softmax
(
self
):
def
test_softmax
(
self
):
x
=
T
.
fmatrix
(
'x'
)
x
=
T
.
fmatrix
(
'x'
)
z
=
T
.
nnet
.
softmax
z
=
T
.
nnet
.
softmax
_op
def
check_types_without_cudnn
(
graph
,
graph_gpu
):
def
check_types_without_cudnn
(
graph
,
graph_gpu
):
self
.
_check_types
(
self
.
_check_types
(
...
@@ -364,7 +366,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -364,7 +366,7 @@ class test_SoftMax(unittest.TestCase):
graph_gpu
,
graph_gpu
,
-
2
,
-
2
,
type
(
z
),
type
(
z
),
cuda
.
nnet
.
GpuSoftmax
GpuSoftmax
)
)
mode_wo_cudnn
=
mode_with_gpu
.
excluding
(
"cudnn"
)
mode_wo_cudnn
=
mode_with_gpu
.
excluding
(
"cudnn"
)
...
@@ -384,10 +386,11 @@ class test_SoftMax(unittest.TestCase):
...
@@ -384,10 +386,11 @@ class test_SoftMax(unittest.TestCase):
self
.
_cmp
(
0
,
10
,
f
,
f_gpu
)
self
.
_cmp
(
0
,
10
,
f
,
f_gpu
)
def
test_softmax_cudnn
(
self
):
def
test_softmax_cudnn
(
self
):
if
not
cuda
.
dnn
.
dnn_available
():
from
..
import
dnn
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
if
not
dnn
.
dnn_available
():
raise
SkipTest
(
dnn
.
dnn_available
.
msg
)
x
=
T
.
fmatrix
(
'x'
)
x
=
T
.
fmatrix
(
'x'
)
z
=
T
.
nnet
.
softmax
z
=
T
.
nnet
.
softmax
_op
def
check_types_with_cudnn
(
graph
,
graph_gpu
):
def
check_types_with_cudnn
(
graph
,
graph_gpu
):
self
.
_check_types
(
self
.
_check_types
(
...
@@ -395,7 +398,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -395,7 +398,7 @@ class test_SoftMax(unittest.TestCase):
graph_gpu
,
graph_gpu
,
-
3
,
-
3
,
type
(
z
),
type
(
z
),
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmax
dnn
.
GpuDnnSoftmax
)
)
f
,
f_gpu
=
self
.
_test_softmax
(
f
,
f_gpu
=
self
.
_test_softmax
(
...
@@ -409,20 +412,22 @@ class test_SoftMax(unittest.TestCase):
...
@@ -409,20 +412,22 @@ class test_SoftMax(unittest.TestCase):
)
)
def
test_cudnn_softmax_grad
(
self
):
def
test_cudnn_softmax_grad
(
self
):
if
not
cuda
.
dnn
.
dnn_available
():
from
..
import
dnn
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
if
not
dnn
.
dnn_available
():
raise
SkipTest
(
dnn
.
dnn_available
.
msg
)
def
cmp
(
n
,
m
,
f
,
f_gpu
):
def
cmp
(
n
,
m
,
f
,
f_gpu
):
data
=
numpy
.
arange
(
n
*
m
,
dtype
=
'float32'
)
.
reshape
(
n
,
m
)
data
=
numpy
.
arange
(
n
*
m
,
dtype
=
'float32'
)
.
reshape
(
n
,
m
)
gdata
=
numpy
.
asarray
(
data
)[:,
:,
None
,
None
]
gdata
=
numpy
.
asarray
(
data
)[:,
:,
None
,
None
]
out
=
f
(
data
)
out
=
f
(
data
)
gout
=
numpy
.
asarray
(
f_gpu
(
gdata
))[:,
:,
0
,
0
]
gout
=
numpy
.
asarray
(
f_gpu
(
gdata
))[:,
:,
0
,
0
]
assert
numpy
.
allclose
(
out
,
gout
),
numpy
.
absolute
(
out
-
gout
)
assert
numpy
.
allclose
(
out
,
gout
),
numpy
.
absolute
(
out
-
gout
)
x
=
T
.
matrix
(
'x'
,
'float32'
)
x
=
T
.
matrix
(
'x'
,
'float32'
)
x_gpu
=
T
.
tensor4
(
'x_gpu'
,
'float32'
)
x_gpu
=
T
.
tensor4
(
'x_gpu'
,
'float32'
)
f_z
=
T
.
nnet
.
softmax
f_z
=
T
.
nnet
.
softmax
_op
f_gpu
=
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmax
(
f_gpu
=
dnn
.
GpuDnnSoftmax
(
'bc01'
,
'bc01'
,
'accurate'
,
'accurate'
,
'channel'
'channel'
...
@@ -443,7 +448,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -443,7 +448,7 @@ class test_SoftMax(unittest.TestCase):
graph_gpu
,
graph_gpu
,
-
1
,
-
1
,
type
(
f_z
),
type
(
f_z
),
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmax
dnn
.
GpuDnnSoftmax
)
)
def
check_types_opt
(
graph
,
graph_gpu
):
def
check_types_opt
(
graph
,
graph_gpu
):
...
@@ -451,11 +456,12 @@ class test_SoftMax(unittest.TestCase):
...
@@ -451,11 +456,12 @@ class test_SoftMax(unittest.TestCase):
assert
len
([
n
for
n
in
graph_gpu
.
maker
.
fgraph
.
toposort
()
assert
len
([
n
for
n
in
graph_gpu
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
if
isinstance
(
n
.
op
,
n
.
op
,
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmax
dnn
.
GpuDnnSoftmax
)])
==
1
)])
==
1
# Verify that the CPU and GPU implementations return the same results
# Verify that the CPU and GPU implementations return the same results
# up to a tolerance.
# up to a tolerance.
self
.
_test_softmax
(
self
.
_test_softmax
(
x
,
x
,
x_gpu
,
x_gpu
,
...
@@ -485,7 +491,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -485,7 +491,7 @@ class test_SoftMax(unittest.TestCase):
for
i
in
sorted_f
for
i
in
sorted_f
if
isinstance
(
if
isinstance
(
i
.
op
,
i
.
op
,
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmaxGrad
dnn
.
GpuDnnSoftmaxGrad
)])
==
1
)
)])
==
1
)
assert
(
len
([
i
assert
(
len
([
i
for
i
in
sorted_f
for
i
in
sorted_f
...
@@ -508,7 +514,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -508,7 +514,7 @@ class test_SoftMax(unittest.TestCase):
for
i
in
sorted_f
for
i
in
sorted_f
if
isinstance
(
if
isinstance
(
i
.
op
,
i
.
op
,
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmaxGrad
dnn
.
GpuDnnSoftmaxGrad
)])
==
0
)
)])
==
0
)
assert
(
len
([
i
assert
(
len
([
i
for
i
in
sorted_f
for
i
in
sorted_f
...
@@ -527,7 +533,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -527,7 +533,7 @@ class test_SoftMax(unittest.TestCase):
for
i
in
sorted_f
for
i
in
sorted_f
if
isinstance
(
if
isinstance
(
i
.
op
,
i
.
op
,
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmaxGrad
dnn
.
GpuDnnSoftmaxGrad
)])
==
1
)
)])
==
1
)
assert
(
len
([
i
assert
(
len
([
i
for
i
in
sorted_f
for
i
in
sorted_f
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论