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
057203e7
Commit
057203e7
authored
Jun 20, 2017
by
derekjchow
Committed by
Sergio Guadarrama
Jun 20, 2017
Browse files
Make Record scripts python3 compatible. (#1614)
parent
9c17823e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
object_detection/create_pascal_tf_record.py
object_detection/create_pascal_tf_record.py
+9
-7
object_detection/create_pet_tf_record.py
object_detection/create_pet_tf_record.py
+9
-7
No files found.
object_detection/create_pascal_tf_record.py
View file @
057203e7
...
...
@@ -83,7 +83,7 @@ def dict_to_tf_example(data,
"""
img_path
=
os
.
path
.
join
(
data
[
'folder'
],
image_subdirectory
,
data
[
'filename'
])
full_path
=
os
.
path
.
join
(
dataset_directory
,
img_path
)
with
tf
.
gfile
.
GFile
(
full_path
)
as
fid
:
with
tf
.
gfile
.
GFile
(
full_path
,
'rb'
)
as
fid
:
encoded_jpg
=
fid
.
read
()
encoded_jpg_io
=
io
.
BytesIO
(
encoded_jpg
)
image
=
PIL
.
Image
.
open
(
encoded_jpg_io
)
...
...
@@ -114,19 +114,21 @@ def dict_to_tf_example(data,
ymin
.
append
(
float
(
obj
[
'bndbox'
][
'ymin'
])
/
height
)
xmax
.
append
(
float
(
obj
[
'bndbox'
][
'xmax'
])
/
width
)
ymax
.
append
(
float
(
obj
[
'bndbox'
][
'ymax'
])
/
height
)
classes_text
.
append
(
obj
[
'name'
])
classes_text
.
append
(
obj
[
'name'
]
.
encode
(
'utf8'
)
)
classes
.
append
(
label_map_dict
[
obj
[
'name'
]])
truncated
.
append
(
int
(
obj
[
'truncated'
]))
poses
.
append
(
obj
[
'pose'
])
poses
.
append
(
obj
[
'pose'
]
.
encode
(
'utf8'
)
)
example
=
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
{
'image/height'
:
dataset_util
.
int64_feature
(
height
),
'image/width'
:
dataset_util
.
int64_feature
(
width
),
'image/filename'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
]),
'image/source_id'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
]),
'image/key/sha256'
:
dataset_util
.
bytes_feature
(
key
),
'image/filename'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
].
encode
(
'utf8'
)),
'image/source_id'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
].
encode
(
'utf8'
)),
'image/key/sha256'
:
dataset_util
.
bytes_feature
(
key
.
encode
(
'utf8'
)),
'image/encoded'
:
dataset_util
.
bytes_feature
(
encoded_jpg
),
'image/format'
:
dataset_util
.
bytes_feature
(
'jpeg'
),
'image/format'
:
dataset_util
.
bytes_feature
(
'jpeg'
.
encode
(
'utf8'
)
),
'image/object/bbox/xmin'
:
dataset_util
.
float_list_feature
(
xmin
),
'image/object/bbox/xmax'
:
dataset_util
.
float_list_feature
(
xmax
),
'image/object/bbox/ymin'
:
dataset_util
.
float_list_feature
(
ymin
),
...
...
object_detection/create_pet_tf_record.py
View file @
057203e7
...
...
@@ -86,7 +86,7 @@ def dict_to_tf_example(data,
ValueError: if the image pointed to by data['filename'] is not a valid JPEG
"""
img_path
=
os
.
path
.
join
(
image_subdirectory
,
data
[
'filename'
])
with
tf
.
gfile
.
GFile
(
img_path
)
as
fid
:
with
tf
.
gfile
.
GFile
(
img_path
,
'rb'
)
as
fid
:
encoded_jpg
=
fid
.
read
()
encoded_jpg_io
=
io
.
BytesIO
(
encoded_jpg
)
image
=
PIL
.
Image
.
open
(
encoded_jpg_io
)
...
...
@@ -118,19 +118,21 @@ def dict_to_tf_example(data,
xmax
.
append
(
float
(
obj
[
'bndbox'
][
'xmax'
])
/
width
)
ymax
.
append
(
float
(
obj
[
'bndbox'
][
'ymax'
])
/
height
)
class_name
=
get_class_name_from_filename
(
data
[
'filename'
])
classes_text
.
append
(
class_name
)
classes_text
.
append
(
class_name
.
encode
(
'utf8'
)
)
classes
.
append
(
label_map_dict
[
class_name
])
truncated
.
append
(
int
(
obj
[
'truncated'
]))
poses
.
append
(
obj
[
'pose'
])
poses
.
append
(
obj
[
'pose'
]
.
encode
(
'utf8'
)
)
example
=
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
{
'image/height'
:
dataset_util
.
int64_feature
(
height
),
'image/width'
:
dataset_util
.
int64_feature
(
width
),
'image/filename'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
]),
'image/source_id'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
]),
'image/key/sha256'
:
dataset_util
.
bytes_feature
(
key
),
'image/filename'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
].
encode
(
'utf8'
)),
'image/source_id'
:
dataset_util
.
bytes_feature
(
data
[
'filename'
].
encode
(
'utf8'
)),
'image/key/sha256'
:
dataset_util
.
bytes_feature
(
key
.
encode
(
'utf8'
)),
'image/encoded'
:
dataset_util
.
bytes_feature
(
encoded_jpg
),
'image/format'
:
dataset_util
.
bytes_feature
(
'jpeg'
),
'image/format'
:
dataset_util
.
bytes_feature
(
'jpeg'
.
encode
(
'utf8'
)
),
'image/object/bbox/xmin'
:
dataset_util
.
float_list_feature
(
xmin
),
'image/object/bbox/xmax'
:
dataset_util
.
float_list_feature
(
xmax
),
'image/object/bbox/ymin'
:
dataset_util
.
float_list_feature
(
ymin
),
...
...
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