Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
ed7a0793
Commit
ed7a0793
authored
May 11, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
binaryclassficiation inferencer
parent
73022908
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
5 deletions
+33
-5
tensorpack/callbacks/inference.py
tensorpack/callbacks/inference.py
+33
-5
No files found.
tensorpack/callbacks/inference.py
View file @
ed7a0793
...
@@ -15,7 +15,7 @@ from ..tfutils.summary import *
...
@@ -15,7 +15,7 @@ from ..tfutils.summary import *
from
.base
import
Callback
,
TestCallbackType
from
.base
import
Callback
,
TestCallbackType
__all__
=
[
'InferenceRunner'
,
'ClassificationError'
,
__all__
=
[
'InferenceRunner'
,
'ClassificationError'
,
'ScalarStats'
,
'Inferencer'
]
'ScalarStats'
,
'Inferencer'
,
'BinaryClassificationStats'
]
class
Inferencer
(
object
):
class
Inferencer
(
object
):
__metaclass__
=
ABCMeta
__metaclass__
=
ABCMeta
...
@@ -58,6 +58,12 @@ class Inferencer(object):
...
@@ -58,6 +58,12 @@ class Inferencer(object):
def
_get_output_tensors
(
self
):
def
_get_output_tensors
(
self
):
pass
pass
def
_scalar_summary
(
self
,
name
,
val
):
self
.
trainer
.
summary_writer
.
add_summary
(
create_summary
(
name
,
val
),
get_global_step
())
self
.
trainer
.
stat_holder
.
add_stat
(
name
,
val
)
class
InferenceRunner
(
Callback
):
class
InferenceRunner
(
Callback
):
"""
"""
A callback that runs different kinds of inferencer.
A callback that runs different kinds of inferencer.
...
@@ -190,7 +196,29 @@ class ClassificationError(Inferencer):
...
@@ -190,7 +196,29 @@ class ClassificationError(Inferencer):
self
.
err_stat
.
feed
(
wrong
,
batch_size
)
self
.
err_stat
.
feed
(
wrong
,
batch_size
)
def
_after_inference
(
self
):
def
_after_inference
(
self
):
self
.
trainer
.
summary_writer
.
add_summary
(
self
.
_scalar_summary
(
self
.
summary_name
,
self
.
err_stat
.
accuracy
)
create_summary
(
self
.
summary_name
,
self
.
err_stat
.
accuracy
),
get_global_step
())
class
BinaryClassificationStats
(
Inferencer
):
self
.
trainer
.
stat_holder
.
add_stat
(
self
.
summary_name
,
self
.
err_stat
.
accuracy
)
def
__init__
(
self
,
pred_var_name
,
label_var_name
,
summary_prefix
=
'val'
):
"""
:param pred_var_name: name of the 0/1 prediction tensor.
:param label_var_name: name of the 0/1 label tensor.
"""
self
.
pred_var_name
=
pred_var_name
self
.
label_var_name
=
label_var_name
self
.
prefix
=
summary_prefix
def
_get_output_tensors
(
self
):
return
[
self
.
pred_var_name
,
self
.
label_var_name
]
def
_before_inference
(
self
):
self
.
stat
=
BinaryStatistics
()
def
_datapoint
(
self
,
dp
,
outputs
):
pred
,
label
=
outputs
self
.
stat
.
feed
(
pred
,
label
)
def
_after_inference
(
self
):
self
.
_scalar_summary
(
self
.
prefix
+
'_precision'
,
self
.
stat
.
precision
)
self
.
_scalar_summary
(
self
.
prefix
+
'_recall'
,
self
.
stat
.
recall
)
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