Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
3pia
CMS Analyses
Tools
Commits
66f23183
Commit
66f23183
authored
4 years ago
by
Dennis Noll
Browse files
Options
Downloads
Patches
Plain Diff
[keras] callbacks: added input plotting
parent
f56cb424
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
keras.py
+26
-5
26 additions, 5 deletions
keras.py
with
26 additions
and
5 deletions
keras.py
+
26
−
5
View file @
66f23183
...
...
@@ -20,6 +20,7 @@ from .plotting import (
figure_activations
,
figure_node_activations
,
figure_roc_curve
,
figure_multihist
,
)
# various helper functions
...
...
@@ -391,14 +392,35 @@ class CustomValidation(tf.keras.callbacks.Callback):
logs
.
update
(
make_logs
(
self
.
model
,
logs
,
res
,
mode
=
ModeKeys
.
TEST
,
prefix
=
"
val_
"
))
class
PlotMulticlass
(
CustomValidation
):
def
__init__
(
self
,
logdir
=
None
,
class_names
=
[
"
signal
"
,
"
background
"
],
**
kwargs
):
class
TFSummaryCallback
(
tf
.
keras
.
callbacks
.
Callback
):
def
__init__
(
self
,
**
kwargs
):
self
.
writer
=
tf
.
summary
.
create_file_writer
(
kwargs
.
pop
(
"
logdir
"
))
super
().
__init__
(
**
kwargs
)
class
PlotMulticlass
(
TFSummaryCallback
,
CustomValidation
):
def
__init__
(
self
,
class_names
=
[
"
signal
"
,
"
background
"
],
to_file
=
False
,
columns
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
x
=
kwargs
[
"
x
"
]
self
.
truth
=
kwargs
[
"
y
"
]
self
.
sample_weight
=
kwargs
.
get
(
"
sample_weight
"
,
None
)
self
.
class_names
=
class_names
self
.
file_writer
=
tf
.
summary
.
create_file_writer
(
logdir
)
self
.
columns
=
columns
self
.
to_file
=
to_file
def
on_train_begin
(
self
,
logs
=
None
):
if
self
.
columns
:
inps
=
self
.
kwargs
[
"
x
"
]
if
not
isinstance
(
inps
,
(
list
,
tuple
)):
inps
=
[
inps
]
imgs
=
{}
for
part
,
inp
in
zip
(
self
.
columns
.
keys
(),
inps
):
imgs
[
f
"
input_
{
part
}
"
]
=
figure_to_image
(
figure_multihist
(
inp
,
columns
=
self
.
columns
[
part
])
)
for
name
,
img
in
imgs
.
items
():
with
self
.
writer
.
as_default
():
tf
.
summary
.
image
(
name
,
img
,
step
=
0
)
def
on_epoch_end
(
self
,
epoch
,
logs
=
None
):
super
().
on_epoch_end
(
epoch
,
logs
)
...
...
@@ -407,7 +429,6 @@ class PlotMulticlass(CustomValidation):
def
make_plots
(
self
,
epoch
,
logs
):
prediction
=
self
.
model
.
predict
(
self
.
x
)
truth
=
self
.
truth
imgs
=
{}
imgs
[
"
roc_curve
"
]
=
figure_to_image
(
figure_roc_curve
(
...
...
@@ -465,7 +486,7 @@ class PlotMulticlass(CustomValidation):
)
)
for
name
,
img
in
imgs
.
items
():
with
self
.
file_
writer
.
as_default
():
with
self
.
writer
.
as_default
():
tf
.
summary
.
image
(
name
,
img
,
step
=
epoch
)
...
...
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