Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9ae32534
提交
9ae32534
authored
6月 27, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename dim{0,1,2} properties of spatialtf descriptor and correct Ops' names
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
1eb4adee
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
19 行删除
+22
-19
dnn.py
theano/gpuarray/dnn.py
+22
-19
没有找到文件。
theano/gpuarray/dnn.py
浏览文件 @
9ae32534
...
@@ -2841,7 +2841,7 @@ class GpuDnnSpatialTfDesc(COp):
...
@@ -2841,7 +2841,7 @@ class GpuDnnSpatialTfDesc(COp):
"""
"""
__props__
=
(
'dimensions'
,
'precision'
)
__props__
=
(
'dimensions'
,
'precision'
)
params_type
=
ParamsType
(
dim0
=
int_t
,
dim1
=
int_t
,
dim2
=
int_t
,
dim3
=
int_t
,
params_type
=
ParamsType
(
nimages
=
int_t
,
height
=
int_t
,
width
=
int_t
,
nchannels
=
int_t
,
nb_dims
=
int_t
,
precision
=
cudnn
.
cudnnDataType_t
)
nb_dims
=
int_t
,
precision
=
cudnn
.
cudnnDataType_t
)
def
c_headers
(
self
):
def
c_headers
(
self
):
...
@@ -2862,7 +2862,10 @@ class GpuDnnSpatialTfDesc(COp):
...
@@ -2862,7 +2862,10 @@ class GpuDnnSpatialTfDesc(COp):
def
__init__
(
self
,
dimensions
,
precision
=
"float32"
):
def
__init__
(
self
,
dimensions
,
precision
=
"float32"
):
COp
.
__init__
(
self
,
[
"c_code/spatialtf_desc.c"
],
"APPLY_SPECIFIC(spatialtf_desc)"
)
COp
.
__init__
(
self
,
[
"c_code/spatialtf_desc.c"
],
"APPLY_SPECIFIC(spatialtf_desc)"
)
self
.
dimensions
=
dimensions
if
isinstance
(
dimensions
,
tuple
)
else
tuple
(
dimensions
)
# dimensions must have at least width and height
assert
len
(
dimensions
)
>=
2
self
.
dimensions
=
tuple
(
dimensions
)
# cuDNN supports only 2D transformations, therefore output tensor must
# cuDNN supports only 2D transformations, therefore output tensor must
# not exceed 4 dimensions (width, height, num_feature_maps, num_images)
# not exceed 4 dimensions (width, height, num_feature_maps, num_images)
...
@@ -2884,13 +2887,13 @@ class GpuDnnSpatialTfDesc(COp):
...
@@ -2884,13 +2887,13 @@ class GpuDnnSpatialTfDesc(COp):
return
node
return
node
# Grid width
# Grid width
dim0
=
property
(
lambda
self
:
self
.
dimensions
[
0
])
nimages
=
property
(
lambda
self
:
self
.
dimensions
[
0
])
# Grid height
# Grid height
dim1
=
property
(
lambda
self
:
self
.
dimensions
[
1
])
height
=
property
(
lambda
self
:
self
.
dimensions
[
1
])
# Number of feature maps
# Number of feature maps
dim2
=
property
(
lambda
self
:
self
.
dimensions
[
2
]
if
len
(
self
.
dimensions
)
>
2
else
1
)
width
=
property
(
lambda
self
:
self
.
dimensions
[
2
]
)
# Number of images
# Number of images
dim3
=
property
(
lambda
self
:
self
.
dimensions
[
3
]
if
len
(
self
.
dimensions
)
>
3
else
1
)
nchannels
=
property
(
lambda
self
:
self
.
dimensions
[
3
]
)
# Number of dimensions in the output tensor
# Number of dimensions in the output tensor
nb_dims
=
property
(
lambda
self
:
len
(
self
.
dimensions
))
nb_dims
=
property
(
lambda
self
:
len
(
self
.
dimensions
))
...
@@ -2898,7 +2901,7 @@ class GpuDnnSpatialTfDesc(COp):
...
@@ -2898,7 +2901,7 @@ class GpuDnnSpatialTfDesc(COp):
return
(
super
(
GpuDnnSpatialTfDesc
,
self
)
.
c_code_cache_version
(),
version
())
return
(
super
(
GpuDnnSpatialTfDesc
,
self
)
.
c_code_cache_version
(),
version
())
class
GpuDnnGridGenerator
Op
(
DnnBase
):
class
GpuDnnGridGenerator
(
DnnBase
):
"""
"""
This Op builds a spatial transformer grid generator for use in spatial transformer network
This Op builds a spatial transformer grid generator for use in spatial transformer network
...
@@ -2921,6 +2924,9 @@ class GpuDnnGridGeneratorOp(DnnBase):
...
@@ -2921,6 +2924,9 @@ class GpuDnnGridGeneratorOp(DnnBase):
else
:
else
:
context_name
=
infer_context_name
(
desc
,
theta
,
cx
)
context_name
=
infer_context_name
(
desc
,
theta
,
cx
)
grid_dimensions
=
as_tensor_variable
(
grid_dimensions
)
theta
=
as_gpuarray_variable
(
theta
,
context_name
)
# Allocate GPU memory for grid of coordinates
# Allocate GPU memory for grid of coordinates
grid
=
GpuArrayType
(
dtype
=
precision
,
grid
=
GpuArrayType
(
dtype
=
precision
,
broadcastable
=
(
False
,
False
,
False
,
False
,),
broadcastable
=
(
False
,
False
,
False
,
False
,),
...
@@ -2932,7 +2938,7 @@ class GpuDnnGridGeneratorOp(DnnBase):
...
@@ -2932,7 +2938,7 @@ class GpuDnnGridGeneratorOp(DnnBase):
pass
pass
class
GpuDnnGridSampler
Op
(
DnnBase
):
class
GpuDnnGridSampler
(
DnnBase
):
"""
"""
This Op builds a spatial transformer grid sampler for use in spatial transformer network
This Op builds a spatial transformer grid sampler for use in spatial transformer network
...
@@ -2959,6 +2965,7 @@ class GpuDnnGridSamplerOp(DnnBase):
...
@@ -2959,6 +2965,7 @@ class GpuDnnGridSamplerOp(DnnBase):
img
=
as_gpuarray_variable
(
img
,
context_name
)
img
=
as_gpuarray_variable
(
img
,
context_name
)
output
=
as_gpuarray_variable
(
output
,
context_name
)
output
=
as_gpuarray_variable
(
output
,
context_name
)
grid
=
as_gpuarray_variable
(
grid
,
context_name
)
grid
=
as_gpuarray_variable
(
grid
,
context_name
)
grid_dimensions
=
as_tensor_variable
(
grid_dimensions
)
if
img
.
type
.
ndim
!=
4
:
if
img
.
type
.
ndim
!=
4
:
raise
TypeError
(
'img must be a 4D tensor'
)
raise
TypeError
(
'img must be a 4D tensor'
)
...
@@ -2975,7 +2982,7 @@ class GpuDnnGridSamplerOp(DnnBase):
...
@@ -2975,7 +2982,7 @@ class GpuDnnGridSamplerOp(DnnBase):
alpha
=
ensure_dt
(
alpha
,
_one
,
'alpha'
,
img
.
dtype
)
alpha
=
ensure_dt
(
alpha
,
_one
,
'alpha'
,
img
.
dtype
)
beta
=
ensure_dt
(
beta
,
_zero
,
'beta'
,
img
.
dtype
)
beta
=
ensure_dt
(
beta
,
_zero
,
'beta'
,
img
.
dtype
)
return
Apply
(
self
,
[
img
,
output
,
grid
,
grid_dimensions
,
desc
,
alpha
,
beta
],
return
Apply
(
self
,
[
img
,
grid
,
grid_dimensions
,
desc
,
alpha
,
beta
],
[
output
.
type
()])
[
output
.
type
()])
def
L_op
(
self
,
inputs
,
outputs
,
output_grads
):
def
L_op
(
self
,
inputs
,
outputs
,
output_grads
):
...
@@ -2992,23 +2999,19 @@ def dnn_spatialtf(img, theta, grid_dims, alpha=None, beta=None, precision=None):
...
@@ -2992,23 +2999,19 @@ def dnn_spatialtf(img, theta, grid_dims, alpha=None, beta=None, precision=None):
img
=
gpu_contiguous
(
img
)
img
=
gpu_contiguous
(
img
)
theta
=
gpu_contiguous
(
theta
)
theta
=
gpu_contiguous
(
theta
)
# Create spatial transformer descriptor
desc
=
GpuDnnSpatialTfDesc
(
grid_dims
,
precision
)()
desc
=
GpuDnnSpatialTfDesc
(
grid_dims
,
precision
)()
width
,
height
=
grid_dims
[:
2
]
num_feature_maps
=
grid_dims
[
2
]
if
len
(
grid_dims
)
>
2
else
1
num_images
=
grid_dims
[
3
]
if
len
(
grid_dims
)
>
3
else
1
grid_shp
=
(
width
,
height
,
num_feature_maps
,
num_images
)
# Create grid dimensions variable
# Create grid dimensions variable
grid_dims
=
np
.
asarray
(
list
(
grid_shp
),
dtype
=
np
.
int32
)
grid_dims
_arr
=
np
.
asarray
(
list
(
grid_dims
),
dtype
=
np
.
int32
)
grid_dims_var
=
as_tensor_variable
(
grid_dims
)
grid_dims_var
=
as_tensor_variable
(
grid_dims
_arr
)
# Setup grid of coordinates
# Setup grid of coordinates
grid_coord
=
GpuDnnGridGenerator
Op
()(
grid_dims_var
,
theta
,
desc
,
precision
,
ctx_name
)
grid_coord
=
GpuDnnGridGenerator
()(
grid_dims_var
,
theta
,
desc
,
precision
,
ctx_name
)
out
=
GpuAllocEmpty
(
dtype
=
img
.
dtype
,
context_name
=
ctx_name
)(
*
grid_
shp
)
out
=
GpuAllocEmpty
(
dtype
=
img
.
dtype
,
context_name
=
ctx_name
)(
*
grid_
dims
)
grid_sampler
=
GpuDnnGridSampler
Op
()(
img
,
out
,
grid_coord
,
grid_dims_var
,
desc
,
alpha
,
beta
,
ctx_name
)
grid_sampler
=
GpuDnnGridSampler
()(
img
,
out
,
grid_coord
,
grid_dims_var
,
desc
,
alpha
,
beta
,
ctx_name
)
return
grid_sampler
return
grid_sampler
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论