Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
105b33b2
提交
105b33b2
authored
7月 03, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add functions rescale input and use a rotation matrix
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
e36cb332
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
25 行删除
+30
-25
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+30
-25
没有找到文件。
theano/gpuarray/tests/test_dnn.py
浏览文件 @
105b33b2
...
...
@@ -2306,25 +2306,39 @@ def test_dnn_spatialtf_grid_generator():
utt
.
seed_rng
()
# shape: (num_images, channels, height, width), equivalent to NCHW
grid_dims
=
(
10
,
3
,
64
,
128
)
grid_dims
=
(
3
,
3
,
128
,
128
)
identity
=
[[
1
,
0
,
0
],
[
0
,
1
,
0
]]
identity
=
[[
-
1
,
0
,
0
],
[
0
,
-
1
,
0
]]
theta
=
np
.
asarray
(
grid_dims
[
0
]
*
[
identity
],
dtype
=
theano
.
config
.
floatX
)
float_type
=
theano
.
config
.
floatX
theta
=
np
.
asarray
(
grid_dims
[
0
]
*
[
identity
],
dtype
=
float_type
)
theta_gpu
=
gpuarray_shared_constructor
(
theta
)
def
normalize_input
(
input
):
# Scale input from [0, 255] to [0, 2]
scale_factor
=
1.
/
128.
input
*=
scale_factor
# Re-scale input from [0, 2] to [-1, 1] (normalized)
input
-=
1
return
input
def
rescale_input
(
input
):
# Re-scale output to range [0, 2]
input
+=
1
# Re-scale output to range [0, 255]
input
*=
128
return
input
from
scipy
import
misc
f
=
misc
.
face
()
.
astype
(
np
.
float32
)
f
=
misc
.
face
()
.
astype
(
float_type
)
# Convert from HWC to CHW
f
=
np
.
transpose
(
f
,
axes
=
(
2
,
0
,
1
))
# Scale input from [0, 255] to [0, 2]
sc
=
1.
/
128.
f
*=
sc
# Re-scale input from [0, 2] to [-1, 1] (normalized)
f
-=
1
f
=
normalize_input
(
f
)
# Create array of images
img
=
np
.
asarray
(
grid_dims
[
0
]
*
[
f
],
dtype
=
theano
.
config
.
floatX
)
img
=
np
.
asarray
(
grid_dims
[
0
]
*
[
f
],
dtype
=
float_type
)
# Create GPU variable for the images
img_gpu
=
gpuarray_shared_constructor
(
img
)
...
...
@@ -2334,23 +2348,14 @@ def test_dnn_spatialtf_grid_generator():
result
,
=
spatialtf_fn
()
img_out
=
np
.
asarray
(
result
,
dtype
=
np
.
float32
)
print
(
img_out
.
shape
)
for
i
in
range
(
len
(
img_out
)):
# Re-scale output to range [0, 2]
img_out
[
i
]
+=
1
# Re-scale output to range [0, 255]
img_out
[
i
]
*=
128
img_out
=
np
.
asarray
(
result
,
dtype
=
float_type
)
# Re-scale image to range [0, 255]
img_out
=
rescale_input
(
img_out
)
# Convert to uint8 (byte)
img_out
=
img_out
.
astype
(
dtype
=
np
.
uint8
)
# Transpose back to NHWC
img_out
=
np
.
transpose
(
img_out
,
axes
=
(
0
,
2
,
3
,
1
))
for
i
in
range
(
len
(
img_out
)):
print
(
"[sampled image #{0}]"
.
format
(
i
))
print
(
"Min/Max: {0}/{1}"
.
format
(
img_out
[
i
]
.
min
(),
img_out
[
i
]
.
max
()))
print
(
img_out
[
i
])
import
matplotlib.pyplot
as
plt
for
img_idx
in
range
(
len
(
img_out
)):
plt
.
imshow
(
img_out
[
img_idx
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论