Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项目经理老王
Mace
提交
237fb749
Mace
项目概览
项目经理老王
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
237fb749
编写于
11月 22, 2018
作者:
李
李滨
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'python_tool' into 'master'
Refactor image tensor tool See merge request !881
上级
f654c291
554fd4c0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
53 addition
and
39 deletion
+53
-39
tools/image/image_to_tensor.py
tools/image/image_to_tensor.py
+32
-24
tools/image/tensor_to_image.py
tools/image/tensor_to_image.py
+21
-15
未找到文件。
tools/image/image_to_tensor.py
浏览文件 @
237fb749
...
@@ -3,6 +3,8 @@ import os
...
@@ -3,6 +3,8 @@ import os
import
sys
import
sys
import
tensorflow
as
tf
import
tensorflow
as
tf
# TODO(liyin): use dataset api and estimator with distributed strategy
FLAGS
=
None
FLAGS
=
None
...
@@ -32,10 +34,8 @@ def parse_args():
...
@@ -32,10 +34,8 @@ def parse_args():
def
images_to_tensors
(
input_files
,
image_shape
,
mean_values
=
None
):
def
images_to_tensors
(
input_files
,
image_shape
,
mean_values
=
None
):
for
i
in
xrange
(
len
(
input_files
)):
with
tf
.
Graph
().
as_default
():
with
tf
.
Session
()
as
sess
:
image_data
=
tf
.
placeholder
(
tf
.
string
,
name
=
'input'
)
with
tf
.
gfile
.
FastGFile
(
input_files
[
i
],
'rb'
)
as
f
:
image_data
=
f
.
read
()
image_data
=
tf
.
image
.
decode_image
(
image_data
,
image_data
=
tf
.
image
.
decode_image
(
image_data
,
channels
=
image_shape
[
2
])
channels
=
image_shape
[
2
])
if
mean_values
:
if
mean_values
:
...
@@ -54,10 +54,18 @@ def images_to_tensors(input_files, image_shape, mean_values=None):
...
@@ -54,10 +54,18 @@ def images_to_tensors(input_files, image_shape, mean_values=None):
image_shape
[:
2
],
image_shape
[:
2
],
align_corners
=
False
)
align_corners
=
False
)
image
=
sess
.
run
(
image_data
)
with
tf
.
Session
()
as
sess
:
output_file
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
os
.
path
.
splitext
(
for
i
in
xrange
(
len
(
input_files
)):
os
.
path
.
basename
(
input_files
[
i
]))[
0
]
+
'.dat'
)
with
tf
.
gfile
.
FastGFile
(
input_files
[
i
],
'rb'
)
as
f
:
image
.
tofile
(
output_file
)
src_image
=
f
.
read
()
dst_image
=
sess
.
run
(
image_data
,
feed_dict
=
{
'input:0'
:
src_image
})
output_file
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
os
.
path
.
splitext
(
os
.
path
.
basename
(
input_files
[
i
]))[
0
]
+
'.dat'
)
dst_image
.
tofile
(
output_file
)
def
main
(
unused_args
):
def
main
(
unused_args
):
...
...
tools/image/tensor_to_image.py
浏览文件 @
237fb749
...
@@ -4,6 +4,8 @@ import sys
...
@@ -4,6 +4,8 @@ import sys
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
# TODO(liyin): use dataset api and estimator with distributed strategy
FLAGS
=
None
FLAGS
=
None
...
@@ -27,22 +29,26 @@ def parse_args():
...
@@ -27,22 +29,26 @@ def parse_args():
def
tensors_to_images
(
input_files
,
image_shape
):
def
tensors_to_images
(
input_files
,
image_shape
):
for
i
in
xrange
(
len
(
input_files
)):
with
tf
.
Graph
().
as_default
():
with
tf
.
Session
()
as
sess
:
input
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
image_shape
,
name
=
'input'
)
tensor_data
=
np
.
fromfile
(
input_files
[
i
],
dtype
=
np
.
float32
)
\
output
=
tf
.
placeholder
(
tf
.
string
,
name
=
'output_file'
)
.
reshape
(
image_shape
)
# use the second channel if it is gray image
# use the second channel if it is gray image
if
image_shape
[
2
]
==
2
:
if
image_shape
[
2
]
==
2
:
_
,
tensor_data
=
tf
.
split
(
tensor_data
,
2
,
axis
=
2
)
_
,
input
=
tf
.
split
(
input
,
2
,
axis
=
2
)
tensor_data
=
tf
.
image
.
convert_image_dtype
(
tensor_data
,
tensor_data
=
tf
.
image
.
convert_image_dtype
(
input
,
tf
.
uint8
,
tf
.
uint8
,
saturate
=
True
)
saturate
=
True
)
image_data
=
tf
.
image
.
encode_jpeg
(
tensor_data
,
quality
=
100
)
image_data
=
tf
.
image
.
encode_jpeg
(
tensor_data
,
quality
=
100
)
image
=
sess
.
run
(
image_data
)
writer
=
tf
.
write_file
(
output
,
image_data
,
name
=
'output_writer'
)
with
tf
.
Session
()
as
sess
:
for
i
in
xrange
(
len
(
input_files
)):
input_data
=
np
.
fromfile
(
input_files
[
i
],
dtype
=
np
.
float32
)
\
.
reshape
(
image_shape
)
output_file
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
os
.
path
.
splitext
(
output_file
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
os
.
path
.
splitext
(
os
.
path
.
basename
(
input_files
[
i
]))[
0
]
+
'.jpg'
)
os
.
path
.
basename
(
input_files
[
i
]))[
0
]
+
'.jpg'
)
writer
=
tf
.
write_file
(
output_file
,
image
)
sess
.
run
(
writer
,
feed_dict
=
{
'input:0'
:
input_data
,
sess
.
run
(
writer
)
'output_file:0'
:
output_file
}
)
def
main
(
unused_args
):
def
main
(
unused_args
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录