Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.face
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
bob
bob.bio.face
Commits
16717689
Commit
16717689
authored
4 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Fixing batching issue
parent
77e0ba63
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!64
Dask pipelines
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/bio/face/embeddings/tensorflow_compat_v1.py
+27
-20
27 additions, 20 deletions
bob/bio/face/embeddings/tensorflow_compat_v1.py
with
27 additions
and
20 deletions
bob/bio/face/embeddings/tensorflow_compat_v1.py
+
27
−
20
View file @
16717689
...
...
@@ -9,6 +9,7 @@ from sklearn.base import TransformerMixin, BaseEstimator
import
numpy
as
np
import
logging
from
sklearn.utils
import
check_array
from
bob.pipelines.sample
import
SampleBatch
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -38,13 +39,13 @@ class TensorflowCompatV1(TransformerMixin, BaseEstimator):
self
.
architecture_fn
=
architecture_fn
self
.
loaded
=
False
def
transform
(
self
,
data
):
def
transform
(
self
,
X
):
"""
Forward the data with the loaded neural network
Parameters
----------
image
: numpy.ndarray
X
: numpy.ndarray
Input Data
Returns
...
...
@@ -54,30 +55,36 @@ class TensorflowCompatV1(TransformerMixin, BaseEstimator):
"""
data
=
check_array
(
data
,
allow_nd
=
True
)
def
_transform
(
data
):
data
=
check_array
(
data
,
allow_nd
=
True
)
# THE INPUT SHAPE FOR THESE MODELS
# ARE `N x C x H x W`
# THE INPUT SHAPE FOR THESE MODELS
# ARE `N x C x H x W`
# If ndim==3 we add another axis
if
data
.
ndim
==
3
:
data
=
data
[
None
,
...]
# If ndim==3 we add another axis
if
data
.
ndim
==
3
:
data
=
data
[
None
,
...]
# Making sure it's channels last and has three channels
if
data
.
ndim
==
4
:
# Just swiping the second dimension if bob format NxCxHxH
if
data
.
shape
[
1
]
==
3
:
data
=
np
.
moveaxis
(
data
,
1
,
-
1
)
# Making sure it's channels last and has three channels
if
data
.
ndim
==
4
:
# Just swiping the second dimension if bob format NxCxHxH
if
data
.
shape
[
1
]
==
3
:
data
=
np
.
moveaxis
(
data
,
1
,
-
1
)
if
data
.
shape
!=
self
.
input_shape
:
raise
ValueError
(
f
"
Image shape
{
data
.
shape
}
not supported. Expected
{
self
.
input_shape
}
"
)
if
data
.
shape
!=
self
.
input_shape
:
raise
ValueError
(
f
"
Image shape
{
data
.
shape
}
not supported. Expected
{
self
.
input_shape
}
"
)
if
not
self
.
loaded
:
self
.
load_model
()
if
not
self
.
loaded
:
self
.
load_model
()
return
self
.
session
.
run
(
self
.
embedding
,
feed_dict
=
{
self
.
input_tensor
:
data
},)
return
self
.
session
.
run
(
self
.
embedding
,
feed_dict
=
{
self
.
input_tensor
:
data
},)
if
isinstance
(
X
,
SampleBatch
):
return
[
_transform
(
x
)
for
x
in
X
]
else
:
return
_transform
(
X
)
def
load_model
(
self
):
import
tensorflow
as
tf
...
...
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