Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.ip.tensorflow_extractor
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
Show more breadcrumbs
bob
bob.ip.tensorflow_extractor
Commits
ff821c8a
Commit
ff821c8a
authored
5 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Plain Diff
Merge branch 'facenet' into 'master'
Improve graph and session handling in facenet class See merge request
!13
parents
2aa5ca35
a34446f5
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!13
Improve graph and session handling in facenet class
Pipeline
#30799
passed
5 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/ip/tensorflow_extractor/FaceNet.py
+20
-22
20 additions, 22 deletions
bob/ip/tensorflow_extractor/FaceNet.py
with
20 additions
and
22 deletions
bob/ip/tensorflow_extractor/FaceNet.py
+
20
−
22
View file @
ff821c8a
...
@@ -115,23 +115,24 @@ class FaceNet(object):
...
@@ -115,23 +115,24 @@ class FaceNet(object):
# code from https://github.com/davidsandberg/facenet
# code from https://github.com/davidsandberg/facenet
model_exp
=
os
.
path
.
expanduser
(
self
.
model_path
)
model_exp
=
os
.
path
.
expanduser
(
self
.
model_path
)
if
(
os
.
path
.
isfile
(
model_exp
)):
with
self
.
graph
.
as_default
():
logger
.
info
(
'
Model filename: %s
'
%
model_exp
)
if
(
os
.
path
.
isfile
(
model_exp
)):
with
tf
.
gfile
.
FastGFile
(
model_exp
,
'
rb
'
)
as
f
:
logger
.
info
(
'
Model filename: %s
'
%
model_exp
)
graph_def
=
tf
.
GraphDef
()
with
tf
.
gfile
.
FastGFile
(
model_exp
,
'
rb
'
)
as
f
:
graph_def
.
ParseFromString
(
f
.
read
())
graph_def
=
tf
.
GraphDef
()
tf
.
import_graph_def
(
graph_def
,
name
=
''
)
graph_def
.
ParseFromString
(
f
.
read
())
else
:
tf
.
import_graph_def
(
graph_def
,
name
=
''
)
logger
.
info
(
'
Model directory: %s
'
%
model_exp
)
else
:
meta_file
,
ckpt_file
=
get_model_filenames
(
model_exp
)
logger
.
info
(
'
Model directory: %s
'
%
model_exp
)
meta_file
,
ckpt_file
=
get_model_filenames
(
model_exp
)
logger
.
info
(
'
Metagraph file: %s
'
%
meta_file
)
logger
.
info
(
'
Checkpoint file: %s
'
%
ckpt_file
)
logger
.
info
(
'
Metagraph file: %s
'
%
meta_file
)
logger
.
info
(
'
Checkpoint file: %s
'
%
ckpt_file
)
saver
=
tf
.
train
.
import_meta_graph
(
os
.
path
.
join
(
model_exp
,
meta_file
))
saver
=
tf
.
train
.
import_meta_graph
(
saver
.
restore
(
tf
.
get_default_session
(),
os
.
path
.
join
(
model_exp
,
meta_file
))
os
.
path
.
join
(
model_exp
,
ckpt_file
))
saver
.
restore
(
self
.
session
,
os
.
path
.
join
(
model_exp
,
ckpt_file
))
# Get input and output tensors
# Get input and output tensors
self
.
images_placeholder
=
self
.
graph
.
get_tensor_by_name
(
"
input:0
"
)
self
.
images_placeholder
=
self
.
graph
.
get_tensor_by_name
(
"
input:0
"
)
self
.
embeddings
=
self
.
graph
.
get_tensor_by_name
(
self
.
layer_name
)
self
.
embeddings
=
self
.
graph
.
get_tensor_by_name
(
self
.
layer_name
)
...
@@ -142,8 +143,8 @@ class FaceNet(object):
...
@@ -142,8 +143,8 @@ class FaceNet(object):
def
__call__
(
self
,
img
):
def
__call__
(
self
,
img
):
images
=
self
.
_check_feature
(
img
)
images
=
self
.
_check_feature
(
img
)
if
self
.
session
is
None
:
if
self
.
session
is
None
:
self
.
session
=
tf
.
InteractiveSession
()
self
.
graph
=
tf
.
Graph
()
self
.
graph
=
tf
.
get_default_
graph
(
)
self
.
session
=
tf
.
Session
(
graph
=
self
.
graph
)
if
self
.
embeddings
is
None
:
if
self
.
embeddings
is
None
:
self
.
load_model
()
self
.
load_model
()
feed_dict
=
{
self
.
images_placeholder
:
images
,
feed_dict
=
{
self
.
images_placeholder
:
images
,
...
@@ -152,9 +153,6 @@ class FaceNet(object):
...
@@ -152,9 +153,6 @@ class FaceNet(object):
self
.
embeddings
,
feed_dict
=
feed_dict
)
self
.
embeddings
,
feed_dict
=
feed_dict
)
return
features
.
flatten
()
return
features
.
flatten
()
def
__del__
(
self
):
tf
.
reset_default_graph
()
@staticmethod
@staticmethod
def
get_rcvariable
():
def
get_rcvariable
():
"""
"""
...
...
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