Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Commits
d47eae91
Commit
d47eae91
authored
6 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Add dataset_to_hdf5 command
parent
f376738a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/tensorflow/script/db_to_tfrecords.py
+67
-0
67 additions, 0 deletions
bob/learn/tensorflow/script/db_to_tfrecords.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
68 additions
and
0 deletions
bob/learn/tensorflow/script/db_to_tfrecords.py
+
67
−
0
View file @
d47eae91
...
@@ -268,3 +268,70 @@ def datasets_to_tfrecords(dataset, output, force, **kwargs):
...
@@ -268,3 +268,70 @@ def datasets_to_tfrecords(dataset, output, force, **kwargs):
os
.
remove
(
json_output
)
os
.
remove
(
json_output
)
raise
raise
click
.
echo
(
"
Successfully wrote all files.
"
)
click
.
echo
(
"
Successfully wrote all files.
"
)
@click.command
(
entry_point_group
=
"
bob.learn.tensorflow.config
"
,
cls
=
ConfigCommand
)
@click.option
(
"
--dataset
"
,
required
=
True
,
cls
=
ResourceOption
,
entry_point_group
=
"
bob.learn.tensorflow.dataset
"
,
help
=
"
A tf.data.Dataset to be used.
"
,
)
@click.option
(
"
--output
"
,
"
-o
"
,
required
=
True
,
cls
=
ResourceOption
,
help
=
"
Name of the output file.
"
)
@click.option
(
"
--mean
"
,
is_flag
=
True
,
cls
=
ResourceOption
,
help
=
"
If provided, the mean of data and labels will be saved in the hdf5
"
'
file as well. You can access them in the
"
mean
"
groups.
'
,
)
@verbosity_option
(
cls
=
ResourceOption
)
def
dataset_to_hdf5
(
dataset
,
output
,
mean
,
**
kwargs
):
"""
Saves a tensorflow dataset into an HDF5 file
It is assumed that the dataset returns a tuple of (data, label, key) and
the dataset is not batched.
"""
log_parameters
(
logger
)
data
,
label
,
key
=
dataset
.
make_one_shot_iterator
().
get_next
()
sess
=
tf
.
Session
()
extension
=
"
.hdf5
"
if
not
output
.
endswith
(
extension
):
output
+=
extension
create_directories_safe
(
os
.
path
.
dirname
(
output
))
sample_count
=
0
data_mean
=
0.0
label_mean
=
0.0
with
HDF5File
(
output
,
"
w
"
)
as
f
:
while
True
:
try
:
d
,
l
,
k
=
sess
.
run
([
data
,
label
,
key
])
group
=
"
/{}
"
.
format
(
sample_count
)
f
.
create_group
(
group
)
f
.
cd
(
group
)
f
[
"
data
"
]
=
d
f
[
"
label
"
]
=
l
f
[
"
key
"
]
=
k
sample_count
+=
1
if
mean
:
data_mean
+=
(
d
-
data_mean
)
/
sample_count
label_mean
+=
(
l
-
label_mean
)
/
sample_count
except
tf
.
errors
.
OutOfRangeError
:
break
if
mean
:
f
.
create_group
(
"
/mean
"
)
f
.
cd
(
"
/mean
"
)
f
[
"
data_mean
"
]
=
data_mean
f
[
"
label_mean
"
]
=
label_mean
click
.
echo
(
f
"
Wrote
{
sample_count
}
samples into the hdf5 file.
"
)
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
d47eae91
...
@@ -53,6 +53,7 @@ setup(
...
@@ -53,6 +53,7 @@ setup(
'
bob.learn.tensorflow.cli
'
:
[
'
bob.learn.tensorflow.cli
'
:
[
'
cache-dataset = bob.learn.tensorflow.script.cache_dataset:cache_dataset
'
,
'
cache-dataset = bob.learn.tensorflow.script.cache_dataset:cache_dataset
'
,
'
compute-statistics = bob.learn.tensorflow.script.compute_statistics:compute_statistics
'
,
'
compute-statistics = bob.learn.tensorflow.script.compute_statistics:compute_statistics
'
,
'
dataset-to-hdf5 = bob.learn.tensorflow.script.db_to_tfrecords:dataset_to_hdf5
'
,
'
datasets-to-tfrecords = bob.learn.tensorflow.script.db_to_tfrecords:datasets_to_tfrecords
'
,
'
datasets-to-tfrecords = bob.learn.tensorflow.script.db_to_tfrecords:datasets_to_tfrecords
'
,
'
db-to-tfrecords = bob.learn.tensorflow.script.db_to_tfrecords:db_to_tfrecords
'
,
'
db-to-tfrecords = bob.learn.tensorflow.script.db_to_tfrecords:db_to_tfrecords
'
,
'
describe-tfrecord = bob.learn.tensorflow.script.db_to_tfrecords:describe_tfrecord
'
,
'
describe-tfrecord = bob.learn.tensorflow.script.db_to_tfrecords:describe_tfrecord
'
,
...
...
This diff is collapsed.
Click to expand it.
Amir MOHAMMADI
@amohammadi
mentioned in merge request
!79 (merged)
·
5 years ago
mentioned in merge request
!79 (merged)
mentioned in merge request !79
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment