Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7cce8524
提交
7cce8524
authored
7月 03, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add grayscale image support in spatialtf test
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
f8d20d3e
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
8 行删除
+28
-8
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+28
-8
没有找到文件。
theano/gpuarray/tests/test_dnn.py
浏览文件 @
7cce8524
...
@@ -2305,20 +2305,25 @@ def test_dnn_spatialtf_grid_generator():
...
@@ -2305,20 +2305,25 @@ def test_dnn_spatialtf_grid_generator():
raise
SkipTest
(
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
dnn
.
dnn_available
.
msg
)
utt
.
seed_rng
()
utt
.
seed_rng
()
float_type
=
theano
.
config
.
floatX
from
scipy
import
misc
f
=
misc
.
face
(
gray
=
True
)
.
astype
(
float_type
)
# shape: (num_images, channels, height, width), equivalent to NCHW
# shape: (num_images, channels, height, width), equivalent to NCHW
nchannels
=
f
.
shape
[
2
]
if
len
(
f
.
shape
)
==
3
else
1
assert
(
nchannels
is
not
None
)
grid_dims
=
(
3
,
3
,
128
,
128
)
grid_dims
=
(
3
,
3
,
128
,
128
)
identity
=
[[
-
1
,
0
,
0
],
rotation
=
[[
-
1
,
0
,
0
],
[
0
,
-
1
,
0
]]
[
0
,
-
1
,
0
]]
float_type
=
theano
.
config
.
floatX
theta
=
np
.
asarray
(
grid_dims
[
0
]
*
[
rotation
],
dtype
=
float_type
)
theta
=
np
.
asarray
(
grid_dims
[
0
]
*
[
identity
],
dtype
=
float_type
)
theta_gpu
=
gpuarray_shared_constructor
(
theta
)
theta_gpu
=
gpuarray_shared_constructor
(
theta
)
def
normalize_input
(
input
):
def
normalize_input
(
input
):
# Scale input from [0, 255] to [0, 2]
# Scale input from [0, 255] to [0, 2]
scale_factor
=
1.
/
128.
scale_factor
=
2
**
-
7
# 1/128
input
*=
scale_factor
input
*=
scale_factor
# Re-scale input from [0, 2] to [-1, 1] (normalized)
# Re-scale input from [0, 2] to [-1, 1] (normalized)
input
-=
1
input
-=
1
...
@@ -2331,12 +2336,18 @@ def test_dnn_spatialtf_grid_generator():
...
@@ -2331,12 +2336,18 @@ def test_dnn_spatialtf_grid_generator():
input
*=
128
input
*=
128
return
input
return
input
from
scipy
import
misc
# Gray-scale images don't have the channels dimension, only
f
=
misc
.
face
()
.
astype
(
float_type
)
# images with color channels have to converted from HWC to CHW
if
len
(
f
.
shape
)
==
3
:
# Convert from HWC to CHW
# Convert from HWC to CHW
f
=
np
.
transpose
(
f
,
axes
=
(
2
,
0
,
1
))
f
=
np
.
transpose
(
f
,
axes
=
(
2
,
0
,
1
))
else
:
# f.shape = (width, height)
shp
=
f
.
shape
# Add channel dimension
f
=
f
.
reshape
((
1
,
shp
[
0
],
shp
[
1
]))
# Normalize pixel values of the image in range [-1, 1]
f
=
normalize_input
(
f
)
f
=
normalize_input
(
f
)
# Create array of images
# Create array of images
img
=
np
.
asarray
(
grid_dims
[
0
]
*
[
f
],
dtype
=
float_type
)
img
=
np
.
asarray
(
grid_dims
[
0
]
*
[
f
],
dtype
=
float_type
)
# Create GPU variable for the images
# Create GPU variable for the images
...
@@ -2356,8 +2367,17 @@ def test_dnn_spatialtf_grid_generator():
...
@@ -2356,8 +2367,17 @@ def test_dnn_spatialtf_grid_generator():
# Transpose back to NHWC
# Transpose back to NHWC
img_out
=
np
.
transpose
(
img_out
,
axes
=
(
0
,
2
,
3
,
1
))
img_out
=
np
.
transpose
(
img_out
,
axes
=
(
0
,
2
,
3
,
1
))
grayscale
=
False
if
img_out
.
shape
[
3
]
==
1
:
# Gray-scale image
grayscale
=
True
shp
=
img_out
.
shape
img_out
=
img_out
.
reshape
(
shp
[
0
],
shp
[
1
],
shp
[
2
])
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
for
img_idx
in
range
(
len
(
img_out
)):
for
img_idx
in
range
(
len
(
img_out
)):
if
grayscale
:
plt
.
imshow
(
img_out
[
img_idx
],
cmap
=
'gray'
)
else
:
plt
.
imshow
(
img_out
[
img_idx
])
plt
.
imshow
(
img_out
[
img_idx
])
plt
.
show
()
plt
.
show
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论