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
f04d1ae5
Commit
f04d1ae5
authored
7 years ago
by
Olivier Canévet
Browse files
Options
Downloads
Patches
Plain Diff
[utils] Add load_real_mnist function
parent
7aac86e2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/tensorflow/utils/util.py
+28
-0
28 additions, 0 deletions
bob/learn/tensorflow/utils/util.py
with
28 additions
and
0 deletions
bob/learn/tensorflow/utils/util.py
+
28
−
0
View file @
f04d1ae5
...
...
@@ -17,6 +17,34 @@ def compute_euclidean_distance(x, y):
d
=
tf
.
sqrt
(
tf
.
reduce_sum
(
tf
.
square
(
tf
.
subtract
(
x
,
y
)),
1
))
return
d
def
dense_to_one_hot
(
labels_dense
,
num_classes
):
"""
Convert class labels from scalars to one-hot vectors.
Taken from tensorflow/contrib/learn/python/learn/datasets/mnist.py
"""
num_labels
=
labels_dense
.
shape
[
0
]
index_offset
=
numpy
.
arange
(
num_labels
)
*
num_classes
labels_one_hot
=
numpy
.
zeros
((
num_labels
,
num_classes
))
labels_one_hot
.
flat
[
index_offset
+
labels_dense
.
ravel
()]
=
1
return
labels_one_hot
def
load_real_mnist
(
one_hot
=
False
,
data_dir
=
None
):
"""
Return the original train and test data
"""
import
bob.db.mnist
db
=
bob
.
db
.
mnist
.
Database
(
data_dir
=
data_dir
)
train_data
,
train_labels
=
db
.
data
(
groups
=
[
"
train
"
])
test_data
,
test_labels
=
db
.
data
(
groups
=
[
"
test
"
])
if
one_hot
:
train_labels
=
dense_to_one_hot
(
train_labels
,
10
)
test_labels
=
dense_to_one_hot
(
test_labels
,
10
)
return
train_data
,
train_labels
,
test_data
,
test_labels
def
load_mnist
(
perc_train
=
0.9
,
data_dir
=
None
):
...
...
This diff is collapsed.
Click to expand it.
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