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
68612afb
"awq/vscode:/vscode.git/clone" did not exist on "661047f119c82324fcda3dbe11eaf5b7e233a359"
Commit
68612afb
authored
Aug 07, 2017
by
Eli Bixby
Browse files
Use context manager
parent
a2931072
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
17 deletions
+15
-17
tutorials/image/cifar10_estimator/generate_cifar10_tfrecords.py
...als/image/cifar10_estimator/generate_cifar10_tfrecords.py
+15
-17
No files found.
tutorials/image/cifar10_estimator/generate_cifar10_tfrecords.py
View file @
68612afb
...
@@ -55,7 +55,7 @@ def _get_file_names():
...
@@ -55,7 +55,7 @@ def _get_file_names():
def
read_pickle_from_file
(
filename
):
def
read_pickle_from_file
(
filename
):
with
o
pen
(
filename
,
'r'
)
as
f
:
with
tf
.
gfile
.
O
pen
(
filename
,
'r'
)
as
f
:
data_dict
=
cPickle
.
load
(
f
)
data_dict
=
cPickle
.
load
(
f
)
return
data_dict
return
data_dict
...
@@ -63,8 +63,7 @@ def read_pickle_from_file(filename):
...
@@ -63,8 +63,7 @@ def read_pickle_from_file(filename):
def
convert_to_tfrecord
(
input_files
,
output_file
):
def
convert_to_tfrecord
(
input_files
,
output_file
):
"""Converts a file to tfrecords."""
"""Converts a file to tfrecords."""
print
(
'Generating %s'
%
output_file
)
print
(
'Generating %s'
%
output_file
)
record_writer
=
tf
.
python_io
.
TFRecordWriter
(
output_file
)
with
tf
.
python_io
.
TFRecordWriter
(
output_file
)
as
record_writer
:
for
input_file
in
input_files
:
for
input_file
in
input_files
:
data_dict
=
read_pickle_from_file
(
input_file
)
data_dict
=
read_pickle_from_file
(
input_file
)
data
=
data_dict
[
'data'
]
data
=
data_dict
[
'data'
]
...
@@ -78,7 +77,6 @@ def convert_to_tfrecord(input_files, output_file):
...
@@ -78,7 +77,6 @@ def convert_to_tfrecord(input_files, output_file):
'label'
:
_int64_feature
(
labels
[
i
])
'label'
:
_int64_feature
(
labels
[
i
])
}))
}))
record_writer
.
write
(
example
.
SerializeToString
())
record_writer
.
write
(
example
.
SerializeToString
())
record_writer
.
close
()
def
main
(
unused_argv
):
def
main
(
unused_argv
):
...
...
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