Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cc9ab256
提交
cc9ab256
authored
7月 12, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct docstring for spatial transformer op
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
bc7218f8
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
20 行删除
+22
-20
dnn.py
theano/gpuarray/dnn.py
+22
-20
没有找到文件。
theano/gpuarray/dnn.py
浏览文件 @
cc9ab256
...
@@ -2888,9 +2888,10 @@ class GpuDnnTransformerDescriptor(COp):
...
@@ -2888,9 +2888,10 @@ class GpuDnnTransformerDescriptor(COp):
class
GpuDnnTransformer
(
DnnBase
):
class
GpuDnnTransformer
(
DnnBase
):
"""
"""
This Op builds a spatial transformer that can be used in spatial transformer networks.
Spatial transformer that can be used in spatial transformer networks, it
implements the grid generator and sampler. The localization network can
be built using neural net components of Theano.
"""
"""
__props__
=
(
'dtype'
,)
__props__
=
(
'dtype'
,)
_cop_num_inputs
=
6
_cop_num_inputs
=
6
_cop_num_outputs
=
2
_cop_num_outputs
=
2
...
@@ -3025,18 +3026,19 @@ class GpuDnnTransformerGradT(DnnBase):
...
@@ -3025,18 +3026,19 @@ class GpuDnnTransformerGradT(DnnBase):
return
[[
1
],
[
0
]]
return
[[
1
],
[
0
]]
def
dnn_spatialtf
(
i
np
,
theta
,
scale_width
=
1
,
scale_height
=
1
,
alpha
=
None
,
beta
=
None
,
def
dnn_spatialtf
(
i
mg
,
theta
,
scale_width
=
1
,
scale_height
=
1
,
alpha
=
None
,
beta
=
None
,
dtype
=
theano
.
config
.
floatX
):
dtype
=
theano
.
config
.
floatX
):
"""
"""
GPU spatial transformer using cuDNN from NVIDIA.
GPU spatial transformer using cuDNN from NVIDIA.
Parameters
Parameters
----------
----------
inp : tensor
img : tensor
Input feature maps in format NCHW
Images to which the transformations will be applied.
(number of inputs, number of channels, height, width)
theta : tensor
theta : matrix
Affine transformation tensor containing one affine transformation
Affine transformation matrix generated by the localization network.
matrix per image. ``theta`` is usually generated by the localization
network.
scale_height: float
scale_height: float
A float specifying the scaling factor for the height of the output
A float specifying the scaling factor for the height of the output
image. A value of 1 will keep the original height of the input. Values
image. A value of 1 will keep the original height of the input. Values
...
@@ -3051,37 +3053,37 @@ def dnn_spatialtf(inp, theta, scale_width=1, scale_height=1, alpha=None, beta=No
...
@@ -3051,37 +3053,37 @@ def dnn_spatialtf(inp, theta, scale_width=1, scale_height=1, alpha=None, beta=No
Returns
Returns
-------
-------
out : tensor
out : tensor
Transformed inputs with the shape
Transformed images with width and height properly scaled.
``(number of inputs, number of channels, round(height * scale_height), round(width * downsampling_factor))``.
Notes
Notes
-----
-----
cuDNN currently only supports 2D transformations with 2x3 affine
Currently, cuDNN only supports 2D transformations with 2x3 affine
transformation matrix. Also, the only sampler available is the
transformation matrices.
bilinear interpolation.
Also, the only grid sampler method available is the bilinear interpolation.
"""
"""
# inp is a 4D tensor with shape: (num_inputs, num_channels, height, width)
# inp is a 4D tensor with shape: (num_inputs, num_channels, height, width)
assert
i
np
.
ndim
==
4
assert
i
mg
.
ndim
==
4
# Theta is an array of transformation matrices and must have shape: (num_images, 2, 3)
# Theta is an array of transformation matrices and must have shape: (num_images, 2, 3)
assert
theta
.
ndim
==
3
assert
theta
.
ndim
==
3
grid_dims
=
(
i
np
.
shape
[
0
],
inp
.
shape
[
1
],
grid_dims
=
(
i
mg
.
shape
[
0
],
img
.
shape
[
1
],
i
np
.
shape
[
2
]
*
scale_height
,
i
mg
.
shape
[
2
]
*
scale_height
,
i
np
.
shape
[
3
]
*
scale_width
)
i
mg
.
shape
[
3
]
*
scale_width
)
grid_dims
=
tuple
(
map
(
lambda
v
:
as_scalar
(
v
)
.
astype
(
'int32'
),
list
(
grid_dims
)))
grid_dims
=
tuple
(
map
(
lambda
v
:
as_scalar
(
v
)
.
astype
(
'int32'
),
list
(
grid_dims
)))
i
np
=
gpu_contiguous
(
inp
)
i
mg
=
gpu_contiguous
(
img
)
theta
=
gpu_contiguous
(
theta
)
theta
=
gpu_contiguous
(
theta
)
output
=
GpuAllocEmpty
(
i
np
.
dtype
,
infer_context_name
(
inp
))(
*
grid_dims
)
output
=
GpuAllocEmpty
(
i
mg
.
dtype
,
infer_context_name
(
img
))(
*
grid_dims
)
# Create spatial transformer descriptor
# Create spatial transformer descriptor
desc
=
GpuDnnTransformerDescriptor
(
dtype
)(
grid_dims
)
desc
=
GpuDnnTransformerDescriptor
(
dtype
)(
grid_dims
)
# Create grid dimensions variable
# Create grid dimensions variable
grid_dims_var
=
as_tensor_variable
(
grid_dims
)
grid_dims_var
=
as_tensor_variable
(
grid_dims
)
# Setup spatial transformer
# Setup spatial transformer
transformer
=
GpuDnnTransformer
(
dtype
)(
i
np
,
theta
,
output
,
grid_dims_var
,
desc
,
alpha
,
beta
)
transformer
=
GpuDnnTransformer
(
dtype
)(
i
mg
,
theta
,
output
,
grid_dims_var
,
desc
,
alpha
,
beta
)
return
transformer
return
transformer
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论