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
a34446f5
Commit
a34446f5
authored
5 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Improve graph and session handling in facenet class
parent
2aa5ca35
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/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 @
a34446f5
...
...
@@ -115,23 +115,24 @@ class FaceNet(object):
# code from https://github.com/davidsandberg/facenet
model_exp
=
os
.
path
.
expanduser
(
self
.
model_path
)
if
(
os
.
path
.
isfile
(
model_exp
)):
logger
.
info
(
'
Model filename: %s
'
%
model_exp
)
with
tf
.
gfile
.
FastGFile
(
model_exp
,
'
rb
'
)
as
f
:
graph_def
=
tf
.
GraphDef
()
graph_def
.
ParseFromString
(
f
.
read
())
tf
.
import_graph_def
(
graph_def
,
name
=
''
)
else
:
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
)
saver
=
tf
.
train
.
import_meta_graph
(
os
.
path
.
join
(
model_exp
,
meta_file
))
saver
.
restore
(
tf
.
get_default_session
(),
os
.
path
.
join
(
model_exp
,
ckpt_file
))
with
self
.
graph
.
as_default
():
if
(
os
.
path
.
isfile
(
model_exp
)):
logger
.
info
(
'
Model filename: %s
'
%
model_exp
)
with
tf
.
gfile
.
FastGFile
(
model_exp
,
'
rb
'
)
as
f
:
graph_def
=
tf
.
GraphDef
()
graph_def
.
ParseFromString
(
f
.
read
())
tf
.
import_graph_def
(
graph_def
,
name
=
''
)
else
:
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
)
saver
=
tf
.
train
.
import_meta_graph
(
os
.
path
.
join
(
model_exp
,
meta_file
))
saver
.
restore
(
self
.
session
,
os
.
path
.
join
(
model_exp
,
ckpt_file
))
# Get input and output tensors
self
.
images_placeholder
=
self
.
graph
.
get_tensor_by_name
(
"
input:0
"
)
self
.
embeddings
=
self
.
graph
.
get_tensor_by_name
(
self
.
layer_name
)
...
...
@@ -142,8 +143,8 @@ class FaceNet(object):
def
__call__
(
self
,
img
):
images
=
self
.
_check_feature
(
img
)
if
self
.
session
is
None
:
self
.
session
=
tf
.
InteractiveSession
()
self
.
graph
=
tf
.
get_default_
graph
(
)
self
.
graph
=
tf
.
Graph
()
self
.
session
=
tf
.
Session
(
graph
=
self
.
graph
)
if
self
.
embeddings
is
None
:
self
.
load_model
()
feed_dict
=
{
self
.
images_placeholder
:
images
,
...
...
@@ -152,9 +153,6 @@ class FaceNet(object):
self
.
embeddings
,
feed_dict
=
feed_dict
)
return
features
.
flatten
()
def
__del__
(
self
):
tf
.
reset_default_graph
()
@staticmethod
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