Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3b205e97
提交
3b205e97
authored
8月 10, 2017
作者:
AndreiCostinescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Changed comments to docstrings where necessary in theano/tensor/nnet/tests
上级
0260d1b6
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
93 行增加
和
74 行删除
+93
-74
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+48
-42
test_blocksparse.py
theano/tensor/nnet/tests/test_blocksparse.py
+6
-4
test_conv.py
theano/tensor/nnet/tests/test_conv.py
+11
-9
test_corr.py
theano/tensor/nnet/tests/test_corr.py
+4
-3
test_corr3d.py
theano/tensor/nnet/tests/test_corr3d.py
+4
-3
test_ctc.py
theano/tensor/nnet/tests/test_ctc.py
+9
-5
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+11
-8
没有找到文件。
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
3b205e97
...
...
@@ -1097,12 +1097,16 @@ class TestBilinearUpsampling(unittest.TestCase):
compile_mode
=
compile_mode
.
excluding
(
'AbstractConvCheck'
)
def
numerical_kernel_1D
(
self
,
ratio
):
# Gets numerical 1D kernel for bilinear upsampling
"""
Gets numerical 1D kernel for bilinear upsampling
"""
return
np
.
array
(
list
(
range
(
1
,
ratio
+
1
))
+
list
(
range
(
ratio
-
1
,
0
,
-
1
)))
def
numerical_kernel_2D
(
self
,
ratio
):
# Gets numerical 2D kernel for bilinear upsampling
"""
Gets numerical 2D kernel for bilinear upsampling
"""
return
np
.
array
([
i
*
j
for
i
in
self
.
numerical_kernel_1D
(
ratio
)
for
j
in
self
.
numerical_kernel_1D
(
ratio
)])
.
\
reshape
(
2
*
ratio
-
1
,
2
*
ratio
-
1
)
...
...
@@ -1157,50 +1161,52 @@ class TestBilinearUpsampling(unittest.TestCase):
utt
.
assert_allclose
(
kernel_1D
,
f_ten_norm
(
ratio
))
def
numerical_upsampling_multiplier
(
self
,
ratio
):
# Compute upsampling multiplier
#
# This method computes the multipliers of an array
# that will be upsampled using bilinear interpolation.
#
# Parameters
# ----------
# ratio: int
# the ratio by which the array will be upsampled.
#
# Returns
# -------
# 1D numpy array
# The multiplers that can be used in bilinear interpolation
# to upsample an array.
#
# int
# The size of the multipliers array
"""
Compute upsampling multiplier
This method computes the multipliers of an array
that will be upsampled using bilinear interpolation.
Parameters
----------
ratio: int
the ratio by which the array will be upsampled.
Returns
-------
1D numpy array
The multiplers that can be used in bilinear interpolation
to upsample an array.
int
The size of the multipliers array
"""
kern
=
np
.
arange
(
ratio
+
1
)
return
kern
,
kern
.
shape
[
0
]
def
get_upsampled_twobytwo_mat
(
self
,
two_by_two
,
ratio
):
# Upsample 4D array with two rows and two columns
#
# This method gets a 4D numpy array with two rows and two columns
# and computes its upsampled array by using bilinear interpolation
#
# Parameters
# ----------
# two_by_two: numpy 4D array
# The array that will be upsampled by bilinear interpolation.
# Array is of shape (batch size, num channels, 2, 2)
#
# ratio: int
# The ratio by which two_by_two's last
# two dimensions (row and col) will be upsampled.
#
# Returns
# -------
# 4D numpy array
# The array upsampled by using bilinear interpolation. Array
# is of shape (batch size, num channels, 2*ratio, 2*ratio).
"""
Upsample 4D array with two rows and two columns
This method gets a 4D numpy array with two rows and two columns
and computes its upsampled array by using bilinear interpolation
Parameters
----------
two_by_two: numpy 4D array
The array that will be upsampled by bilinear interpolation.
Array is of shape (batch size, num channels, 2, 2)
ratio: int
The ratio by which two_by_two's last
two dimensions (row and col) will be upsampled.
Returns
-------
4D numpy array
The array upsampled by using bilinear interpolation. Array
is of shape (batch size, num channels, 2*ratio, 2*ratio).
"""
kern
,
shp
=
self
.
numerical_upsampling_multiplier
(
ratio
)
up_1D
=
two_by_two
[:,
:,
:,
:
1
]
*
kern
[::
-
1
]
+
\
two_by_two
[:,
:,
:,
1
:]
*
kern
...
...
theano/tensor/nnet/tests/test_blocksparse.py
浏览文件 @
3b205e97
...
...
@@ -87,8 +87,9 @@ class BlockSparse_Gemv_and_Outer(utt.InferShapeTester):
@staticmethod
def
gemv_numpy2
(
o
,
W
,
h
,
iIdx
,
oIdx
):
# Other implementation
"""
Other implementation
"""
from
numpy
import
ix_
for
b
in
range
(
o
.
shape
[
0
]):
w
=
W
[
ix_
(
iIdx
[
b
],
oIdx
[
b
])]
.
swapaxes
(
1
,
2
)
...
...
@@ -98,8 +99,9 @@ class BlockSparse_Gemv_and_Outer(utt.InferShapeTester):
@staticmethod
def
gemv_numpy3
(
o
,
W
,
h
,
iIdx
,
oIdx
):
# Other implementation
"""
Other implementation
"""
from
numpy
import
ix_
for
b
in
range
(
o
.
shape
[
0
]):
w
=
W
[
ix_
(
iIdx
[
b
],
oIdx
[
b
])]
...
...
theano/tensor/nnet/tests/test_conv.py
浏览文件 @
3b205e97
...
...
@@ -36,16 +36,18 @@ class TestConv2D(utt.InferShapeTester):
input
=
None
,
filters
=
None
,
unroll_batch
=
None
,
unroll_kern
=
None
,
unroll_patch
=
None
,
verify_grad
=
True
,
should_raise
=
False
):
# :param image_shape: The constant shape info passed to conv2d.
# :param filter_shape: The constant shape info passed to conv2d.
#
# :param N_image_shape: None(default to image_shape) or tuple of
# 4 elements with the shape of the input image
#
# :param N_filter_shape: None(default to filter_shape) or tuple
# of 4 elements with the shape of the
# input filter
"""
:param image_shape: The constant shape info passed to conv2d.
:param filter_shape: The constant shape info passed to conv2d.
:param N_image_shape: None(default to image_shape) or tuple of
4 elements with the shape of the input image
:param N_filter_shape: None(default to filter_shape) or tuple
of 4 elements with the shape of the
input filter
"""
if
N_image_shape
is
None
:
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
for
x
in
image_shape
]
...
...
theano/tensor/nnet/tests/test_corr.py
浏览文件 @
3b205e97
...
...
@@ -34,9 +34,10 @@ class TestCorr2D(utt.InferShapeTester):
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
input
=
None
,
filters
=
None
,
verify_grad
=
True
,
non_contiguous
=
False
,
filter_dilation
=
(
1
,
1
)):
# :param image_shape: The constant shape info passed to corrMM.
# :param filter_shape: The constant shape info passed to corrMM.
"""
:param image_shape: The constant shape info passed to corrMM.
:param filter_shape: The constant shape info passed to corrMM.
"""
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"Need cxx to test conv2d"
)
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
...
...
theano/tensor/nnet/tests/test_corr3d.py
浏览文件 @
3b205e97
...
...
@@ -36,9 +36,10 @@ class TestCorr3D(utt.InferShapeTester):
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
input
=
None
,
filters
=
None
,
verify_grad
=
True
,
non_contiguous
=
False
,
filter_dilation
=
(
1
,
1
,
1
)):
# :param image_shape: The constant shape info passed to corr3dMM.
# :param filter_shape: The constant shape info passed to corr3dMM.
"""
:param image_shape: The constant shape info passed to corr3dMM.
:param filter_shape: The constant shape info passed to corr3dMM.
"""
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"Need cxx for this test"
)
...
...
theano/tensor/nnet/tests/test_ctc.py
浏览文件 @
3b205e97
...
...
@@ -77,9 +77,12 @@ def setup_grad_case():
class
TestCTC
(
unittest
.
TestCase
):
# Test Baidu CTC wrapper implementation.
# Expected values for costs and gradients are obtained through an external
# C implementation, that uses the library directly.
"""
Test Baidu CTC wrapper implementation.
Expected values for costs and gradients are obtained through an external
C implementation, that uses the library directly.
"""
def
setUp
(
self
):
if
theano
.
config
.
mode
==
"FAST_COMPILE"
or
theano
.
config
.
cxx
==
""
:
...
...
@@ -108,8 +111,9 @@ class TestCTC(unittest.TestCase):
self
.
check_grads_disabled
(
t_activations
,
t_labels
,
t_activation_times
)
def
check_grads_disabled
(
self
,
activations
,
labels
,
input_length
):
# Check if optimization to disable gradients is working
"""
Check if optimization to disable gradients is working
"""
ctc_cost
=
ctc
(
activations
,
labels
,
input_length
)
ctc_function
=
theano
.
function
([],
[
ctc_cost
])
for
node
in
ctc_function
.
maker
.
fgraph
.
apply_nodes
:
...
...
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
3b205e97
...
...
@@ -87,14 +87,15 @@ class T_softplus(unittest.TestCase):
class
T_sigmoid_opts
(
unittest
.
TestCase
):
def
get_mode
(
self
,
excluding
=
None
):
# Return appropriate mode for the tests.
#
# :param excluding: List of optimizations to exclude.
#
# :return: The current default mode unless the `config.mode` option is
# set to 'FAST_COMPILE' (in which case it is replaced by the 'FAST_RUN'
# mode), without the optimizations specified in `excluding`.
"""
Return appropriate mode for the tests.
:param excluding: List of optimizations to exclude.
:return: The current default mode unless the `config.mode` option is
set to 'FAST_COMPILE' (in which case it is replaced by the 'FAST_RUN'
mode), without the optimizations specified in `excluding`.
"""
if
excluding
is
None
:
excluding
=
[]
m
=
theano
.
config
.
mode
...
...
@@ -447,7 +448,9 @@ class T_softplus_opts(unittest.TestCase):
class
T_sigmoid_utils
(
unittest
.
TestCase
):
# Test utility functions found in 'sigm.py'.
"""
Test utility functions found in 'sigm.py'.
"""
def
test_compute_mul
(
self
):
x
,
y
,
z
=
tensor
.
vectors
(
'x'
,
'y'
,
'z'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论