Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
e8adaffd
Commit
e8adaffd
authored
Jan 23, 2017
by
Nick Johnston
Browse files
Modify compression tools to be Python3 compatible.
parent
82c219f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
compression/decoder.py
compression/decoder.py
+8
-8
compression/encoder.py
compression/encoder.py
+5
-5
compression/msssim.py
compression/msssim.py
+6
-6
No files found.
compression/decoder.py
View file @
e8adaffd
...
@@ -40,26 +40,26 @@ FLAGS = tf.flags.FLAGS
...
@@ -40,26 +40,26 @@ FLAGS = tf.flags.FLAGS
def
get_input_tensor_names
():
def
get_input_tensor_names
():
name_list
=
[
'GruBinarizer/SignBinarizer/Sign:0'
]
name_list
=
[
'GruBinarizer/SignBinarizer/Sign:0'
]
for
i
in
x
range
(
1
,
16
):
for
i
in
range
(
1
,
16
):
name_list
.
append
(
'GruBinarizer/SignBinarizer/Sign_{}:0'
.
format
(
i
))
name_list
.
append
(
'GruBinarizer/SignBinarizer/Sign_{}:0'
.
format
(
i
))
return
name_list
return
name_list
def
get_output_tensor_names
():
def
get_output_tensor_names
():
return
[
'loop_{0:02d}/add:0'
.
format
(
i
)
for
i
in
x
range
(
0
,
16
)]
return
[
'loop_{0:02d}/add:0'
.
format
(
i
)
for
i
in
range
(
0
,
16
)]
def
main
(
_
):
def
main
(
_
):
if
(
FLAGS
.
input_codes
is
None
or
FLAGS
.
output_directory
is
None
or
if
(
FLAGS
.
input_codes
is
None
or
FLAGS
.
output_directory
is
None
or
FLAGS
.
model
is
None
):
FLAGS
.
model
is
None
):
print
(
'
\n
Usage: python decoder.py --input_codes=output_codes.pkl '
print
(
'
\n
Usage: python decoder.py --input_codes=output_codes.pkl '
'--iteration=15 --output_directory=/tmp/compression_output/ '
'--iteration=15 --output_directory=/tmp/compression_output/ '
'--model=residual_gru.pb
\n\n
'
)
'--model=residual_gru.pb
\n\n
'
)
return
return
if
FLAGS
.
iteration
<
-
1
or
FLAGS
.
iteration
>
15
:
if
FLAGS
.
iteration
<
-
1
or
FLAGS
.
iteration
>
15
:
print
(
'
\n
--iteration must be between 0 and 15 inclusive, or -1 to infer '
print
(
'
\n
--iteration must be between 0 and 15 inclusive, or -1 to infer '
'from file.
\n
'
)
'from file.
\n
'
)
return
return
iteration
=
FLAGS
.
iteration
iteration
=
FLAGS
.
iteration
...
@@ -67,7 +67,7 @@ def main(_):
...
@@ -67,7 +67,7 @@ def main(_):
tf
.
gfile
.
MkDir
(
FLAGS
.
output_directory
)
tf
.
gfile
.
MkDir
(
FLAGS
.
output_directory
)
if
not
tf
.
gfile
.
Exists
(
FLAGS
.
input_codes
):
if
not
tf
.
gfile
.
Exists
(
FLAGS
.
input_codes
):
print
'
\n
Input codes not found.
\n
'
print
(
'
\n
Input codes not found.
\n
'
)
return
return
contents
=
''
contents
=
''
...
...
compression/encoder.py
View file @
e8adaffd
...
@@ -42,7 +42,7 @@ FLAGS = tf.flags.FLAGS
...
@@ -42,7 +42,7 @@ FLAGS = tf.flags.FLAGS
def
get_output_tensor_names
():
def
get_output_tensor_names
():
name_list
=
[
'GruBinarizer/SignBinarizer/Sign:0'
]
name_list
=
[
'GruBinarizer/SignBinarizer/Sign:0'
]
for
i
in
x
range
(
1
,
16
):
for
i
in
range
(
1
,
16
):
name_list
.
append
(
'GruBinarizer/SignBinarizer/Sign_{}:0'
.
format
(
i
))
name_list
.
append
(
'GruBinarizer/SignBinarizer/Sign_{}:0'
.
format
(
i
))
return
name_list
return
name_list
...
@@ -50,13 +50,13 @@ def get_output_tensor_names():
...
@@ -50,13 +50,13 @@ def get_output_tensor_names():
def
main
(
_
):
def
main
(
_
):
if
(
FLAGS
.
input_image
is
None
or
FLAGS
.
output_codes
is
None
or
if
(
FLAGS
.
input_image
is
None
or
FLAGS
.
output_codes
is
None
or
FLAGS
.
model
is
None
):
FLAGS
.
model
is
None
):
print
(
'
\n
Usage: python encoder.py --input_image=/your/image/here.png '
print
(
'
\n
Usage: python encoder.py --input_image=/your/image/here.png '
'--output_codes=output_codes.pkl --iteration=15 '
'--output_codes=output_codes.pkl --iteration=15 '
'--model=residual_gru.pb
\n\n
'
)
'--model=residual_gru.pb
\n\n
'
)
return
return
if
FLAGS
.
iteration
<
0
or
FLAGS
.
iteration
>
15
:
if
FLAGS
.
iteration
<
0
or
FLAGS
.
iteration
>
15
:
print
'
\n
--iteration must be between 0 and 15 inclusive.
\n
'
print
(
'
\n
--iteration must be between 0 and 15 inclusive.
\n
'
)
return
return
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
input_image
)
as
input_image
:
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
input_image
)
as
input_image
:
...
...
compression/msssim.py
View file @
e8adaffd
...
@@ -171,7 +171,7 @@ def MultiScaleSSIM(img1, img2, max_val=255, filter_size=11, filter_sigma=1.5,
...
@@ -171,7 +171,7 @@ def MultiScaleSSIM(img1, img2, max_val=255, filter_size=11, filter_sigma=1.5,
im1
,
im2
=
[
x
.
astype
(
np
.
float64
)
for
x
in
[
img1
,
img2
]]
im1
,
im2
=
[
x
.
astype
(
np
.
float64
)
for
x
in
[
img1
,
img2
]]
mssim
=
np
.
array
([])
mssim
=
np
.
array
([])
mcs
=
np
.
array
([])
mcs
=
np
.
array
([])
for
_
in
x
range
(
levels
):
for
_
in
range
(
levels
):
ssim
,
cs
=
_SSIMForMultiScale
(
ssim
,
cs
=
_SSIMForMultiScale
(
im1
,
im2
,
max_val
=
max_val
,
filter_size
=
filter_size
,
im1
,
im2
,
max_val
=
max_val
,
filter_size
=
filter_size
,
filter_sigma
=
filter_sigma
,
k1
=
k1
,
k2
=
k2
)
filter_sigma
=
filter_sigma
,
k1
=
k1
,
k2
=
k2
)
...
@@ -186,16 +186,16 @@ def MultiScaleSSIM(img1, img2, max_val=255, filter_size=11, filter_sigma=1.5,
...
@@ -186,16 +186,16 @@ def MultiScaleSSIM(img1, img2, max_val=255, filter_size=11, filter_sigma=1.5,
def
main
(
_
):
def
main
(
_
):
if
FLAGS
.
original_image
is
None
or
FLAGS
.
compared_image
is
None
:
if
FLAGS
.
original_image
is
None
or
FLAGS
.
compared_image
is
None
:
print
(
'
\n
Usage: python msssim.py --original_image=original.png '
print
(
'
\n
Usage: python msssim.py --original_image=original.png '
'--compared_image=distorted.png
\n\n
'
)
'--compared_image=distorted.png
\n\n
'
)
return
return
if
not
tf
.
gfile
.
Exists
(
FLAGS
.
original_image
):
if
not
tf
.
gfile
.
Exists
(
FLAGS
.
original_image
):
print
'
\n
Cannot find --original_image.
\n
'
print
(
'
\n
Cannot find --original_image.
\n
'
)
return
return
if
not
tf
.
gfile
.
Exists
(
FLAGS
.
compared_image
):
if
not
tf
.
gfile
.
Exists
(
FLAGS
.
compared_image
):
print
'
\n
Cannot find --compared_image.
\n
'
print
(
'
\n
Cannot find --compared_image.
\n
'
)
return
return
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
original_image
)
as
image_file
:
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
original_image
)
as
image_file
:
...
@@ -210,7 +210,7 @@ def main(_):
...
@@ -210,7 +210,7 @@ def main(_):
img1
=
sess
.
run
(
decoded_image
,
feed_dict
=
{
input_img
:
img1_str
})
img1
=
sess
.
run
(
decoded_image
,
feed_dict
=
{
input_img
:
img1_str
})
img2
=
sess
.
run
(
decoded_image
,
feed_dict
=
{
input_img
:
img2_str
})
img2
=
sess
.
run
(
decoded_image
,
feed_dict
=
{
input_img
:
img2_str
})
print
MultiScaleSSIM
(
img1
,
img2
,
max_val
=
255
)
print
((
MultiScaleSSIM
(
img1
,
img2
,
max_val
=
255
)
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment