Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.learn.tensorflow
Commits
8325c6f5
Commit
8325c6f5
authored
Oct 23, 2017
by
Amir MOHAMMADI
Browse files
Create the graph early enough
parent
7e1cb805
Changes
1
Hide whitespace changes
Inline
Side-by-side
bob/learn/tensorflow/script/predict_bio.py
View file @
8325c6f5
...
...
@@ -163,41 +163,44 @@ def main(argv=None):
output_dir
=
get_from_config_or_commandline
(
config
,
'output_dir'
,
args
,
defaults
,
False
)
generator
,
output_types
,
output_shapes
=
bio_generator
(
database
,
preprocessor
,
groups
,
number_of_parallel_jobs
,
biofile_to_label
,
multiple_samples
)
dataset
=
Dataset
.
from_generator
(
generator
,
output_types
,
output_shapes
)
predict_input_fn
=
bio_predict_input_fn
(
dataset
)
predictions
=
estimator
.
predict
(
predict_input_fn
,
predict_keys
=
predict_keys
,
hooks
=
hooks
,
checkpoint_path
=
checkpoint_path
,
)
pool
=
Pool
()
try
:
pred_buffer
=
defaultdict
(
list
)
for
i
,
pred
in
enumerate
(
predictions
):
key
=
pred
[
'keys'
]
prob
=
pred
.
get
(
'probabilities'
,
pred
.
get
(
'embeddings'
))
pred_buffer
[
key
].
append
(
prob
)
if
i
==
0
:
last_key
=
key
if
last_key
==
key
:
continue
with
tf
.
Graph
().
as_default
():
generator
,
output_types
,
output_shapes
=
bio_generator
(
database
,
preprocessor
,
groups
,
number_of_parallel_jobs
,
biofile_to_label
,
multiple_samples
)
dataset
=
Dataset
.
from_generator
(
generator
,
output_types
,
output_shapes
)
predict_input_fn
=
bio_predict_input_fn
(
dataset
)
predictions
=
estimator
.
predict
(
predict_input_fn
,
predict_keys
=
predict_keys
,
hooks
=
hooks
,
checkpoint_path
=
checkpoint_path
,
)
pool
=
Pool
()
try
:
pred_buffer
=
defaultdict
(
list
)
for
i
,
pred
in
enumerate
(
predictions
):
key
=
pred
[
'keys'
]
prob
=
pred
.
get
(
'probabilities'
,
pred
.
get
(
'embeddings'
))
pred_buffer
[
key
].
append
(
prob
)
if
i
==
0
:
last_key
=
key
if
last_key
==
key
:
continue
else
:
save_predictions
(
pool
,
output_dir
,
last_key
,
pred_buffer
)
last_key
=
key
# else below is for the for loop
else
:
save_predictions
(
pool
,
output_dir
,
last_key
,
pred_buffer
)
last_key
=
key
# else below is for the for loop
else
:
save_predictions
(
pool
,
output_dir
,
key
,
pred_buffer
)
finally
:
pool
.
close
()
pool
.
join
()
save_predictions
(
pool
,
output_dir
,
key
,
pred_buffer
)
finally
:
pool
.
close
()
pool
.
join
()
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment