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
2bb1baad
Commit
2bb1baad
authored
Jun 14, 2017
by
xiangjinwu
Committed by
Sergio Guadarrama
Jun 14, 2017
Browse files
slim Python 3 compatibility: cPickle and str/bytes (#1534)
parent
7e0016c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
9 deletions
+12
-9
slim/datasets/dataset_utils.py
slim/datasets/dataset_utils.py
+1
-1
slim/datasets/download_and_convert_cifar10.py
slim/datasets/download_and_convert_cifar10.py
+9
-6
slim/datasets/download_and_convert_flowers.py
slim/datasets/download_and_convert_flowers.py
+2
-2
No files found.
slim/datasets/dataset_utils.py
View file @
2bb1baad
...
@@ -124,7 +124,7 @@ def read_label_file(dataset_dir, filename=LABELS_FILENAME):
...
@@ -124,7 +124,7 @@ def read_label_file(dataset_dir, filename=LABELS_FILENAME):
A map from a label (integer) to class name.
A map from a label (integer) to class name.
"""
"""
labels_filename
=
os
.
path
.
join
(
dataset_dir
,
filename
)
labels_filename
=
os
.
path
.
join
(
dataset_dir
,
filename
)
with
tf
.
gfile
.
Open
(
labels_filename
,
'r'
)
as
f
:
with
tf
.
gfile
.
Open
(
labels_filename
,
'r
b
'
)
as
f
:
lines
=
f
.
read
().
decode
()
lines
=
f
.
read
().
decode
()
lines
=
lines
.
split
(
'
\n
'
)
lines
=
lines
.
split
(
'
\n
'
)
lines
=
filter
(
None
,
lines
)
lines
=
filter
(
None
,
lines
)
...
...
slim/datasets/download_and_convert_cifar10.py
View file @
2bb1baad
...
@@ -26,7 +26,7 @@ from __future__ import absolute_import
...
@@ -26,7 +26,7 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
print_function
import
cPickle
from
six.moves
import
cPickle
import
os
import
os
import
sys
import
sys
import
tarfile
import
tarfile
...
@@ -72,14 +72,17 @@ def _add_to_tfrecord(filename, tfrecord_writer, offset=0):
...
@@ -72,14 +72,17 @@ def _add_to_tfrecord(filename, tfrecord_writer, offset=0):
Returns:
Returns:
The new offset.
The new offset.
"""
"""
with
tf
.
gfile
.
Open
(
filename
,
'r'
)
as
f
:
with
tf
.
gfile
.
Open
(
filename
,
'rb'
)
as
f
:
data
=
cPickle
.
load
(
f
)
if
sys
.
version_info
<
(
3
,):
data
=
cPickle
.
load
(
f
)
else
:
data
=
cPickle
.
load
(
f
,
encoding
=
'bytes'
)
images
=
data
[
'data'
]
images
=
data
[
b
'data'
]
num_images
=
images
.
shape
[
0
]
num_images
=
images
.
shape
[
0
]
images
=
images
.
reshape
((
num_images
,
3
,
32
,
32
))
images
=
images
.
reshape
((
num_images
,
3
,
32
,
32
))
labels
=
data
[
'labels'
]
labels
=
data
[
b
'labels'
]
with
tf
.
Graph
().
as_default
():
with
tf
.
Graph
().
as_default
():
image_placeholder
=
tf
.
placeholder
(
dtype
=
tf
.
uint8
)
image_placeholder
=
tf
.
placeholder
(
dtype
=
tf
.
uint8
)
...
@@ -99,7 +102,7 @@ def _add_to_tfrecord(filename, tfrecord_writer, offset=0):
...
@@ -99,7 +102,7 @@ def _add_to_tfrecord(filename, tfrecord_writer, offset=0):
feed_dict
=
{
image_placeholder
:
image
})
feed_dict
=
{
image_placeholder
:
image
})
example
=
dataset_utils
.
image_to_tfexample
(
example
=
dataset_utils
.
image_to_tfexample
(
png_string
,
'png'
,
_IMAGE_SIZE
,
_IMAGE_SIZE
,
label
)
png_string
,
b
'png'
,
_IMAGE_SIZE
,
_IMAGE_SIZE
,
label
)
tfrecord_writer
.
write
(
example
.
SerializeToString
())
tfrecord_writer
.
write
(
example
.
SerializeToString
())
return
offset
+
num_images
return
offset
+
num_images
...
...
slim/datasets/download_and_convert_flowers.py
View file @
2bb1baad
...
@@ -136,14 +136,14 @@ def _convert_dataset(split_name, filenames, class_names_to_ids, dataset_dir):
...
@@ -136,14 +136,14 @@ def _convert_dataset(split_name, filenames, class_names_to_ids, dataset_dir):
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
# Read the filename:
# Read the filename:
image_data
=
tf
.
gfile
.
FastGFile
(
filenames
[
i
],
'r'
).
read
()
image_data
=
tf
.
gfile
.
FastGFile
(
filenames
[
i
],
'r
b
'
).
read
()
height
,
width
=
image_reader
.
read_image_dims
(
sess
,
image_data
)
height
,
width
=
image_reader
.
read_image_dims
(
sess
,
image_data
)
class_name
=
os
.
path
.
basename
(
os
.
path
.
dirname
(
filenames
[
i
]))
class_name
=
os
.
path
.
basename
(
os
.
path
.
dirname
(
filenames
[
i
]))
class_id
=
class_names_to_ids
[
class_name
]
class_id
=
class_names_to_ids
[
class_name
]
example
=
dataset_utils
.
image_to_tfexample
(
example
=
dataset_utils
.
image_to_tfexample
(
image_data
,
'jpg'
,
height
,
width
,
class_id
)
image_data
,
b
'jpg'
,
height
,
width
,
class_id
)
tfrecord_writer
.
write
(
example
.
SerializeToString
())
tfrecord_writer
.
write
(
example
.
SerializeToString
())
sys
.
stdout
.
write
(
'
\n
'
)
sys
.
stdout
.
write
(
'
\n
'
)
...
...
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