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
199db00e
Commit
199db00e
authored
Oct 25, 2016
by
Rohan Jain
Committed by
GitHub
Oct 25, 2016
Browse files
Merge pull request #510 from nickj-google/master
Fix IO handling in compression models.
parents
c9c4981d
f0de6d56
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
compression/decoder.py
compression/decoder.py
+5
-2
compression/encoder.py
compression/encoder.py
+5
-2
No files found.
compression/decoder.py
View file @
199db00e
...
...
@@ -21,6 +21,7 @@ Example usage:
python decoder.py --input_codes=output_codes.pkl --iteration=15 \
--output_directory=/tmp/compression_output/ --model=residual_gru.pb
"""
import
io
import
os
import
numpy
as
np
...
...
@@ -69,8 +70,10 @@ def main(_):
print
'
\n
Input codes not found.
\n
'
return
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
input_codes
,
'rb'
)
as
code_file
:
loaded_codes
=
np
.
load
(
code_file
)
contents
=
''
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
input_codes
,
'r'
)
as
code_file
:
contents
=
code_file
.
read
()
loaded_codes
=
np
.
load
(
io
.
BytesIO
(
contents
))
assert
[
'codes'
,
'shape'
]
not
in
loaded_codes
.
files
loaded_shape
=
loaded_codes
[
'shape'
]
loaded_array
=
loaded_codes
[
'codes'
]
...
...
compression/encoder.py
View file @
199db00e
...
...
@@ -23,6 +23,7 @@ Example usage:
python encoder.py --input_image=/your/image/here.png \
--output_codes=output_codes.pkl --iteration=15 --model=residual_gru.pb
"""
import
io
import
os
import
numpy
as
np
...
...
@@ -94,8 +95,10 @@ def main(_):
int_codes
=
(
int_codes
+
1
)
/
2
export
=
np
.
packbits
(
int_codes
.
reshape
(
-
1
))
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
output_codes
,
'wb'
)
as
code_file
:
np
.
savez_compressed
(
code_file
,
shape
=
int_codes
.
shape
,
codes
=
export
)
output
=
io
.
BytesIO
()
np
.
savez_compressed
(
output
,
shape
=
int_codes
.
shape
,
codes
=
export
)
with
tf
.
gfile
.
FastGFile
(
FLAGS
.
output_codes
,
'w'
)
as
code_file
:
code_file
.
write
(
output
.
getvalue
())
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