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
fbf93d44
Commit
fbf93d44
authored
Sep 20, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug in inferencer, and better naming
parent
941093a9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
30 deletions
+31
-30
scripts/plot-point.py
scripts/plot-point.py
+7
-6
tensorpack/callbacks/inference.py
tensorpack/callbacks/inference.py
+24
-24
No files found.
scripts/plot-point.py
View file @
fbf93d44
...
...
@@ -9,7 +9,7 @@ A simplest example:
$ cat examples/train_log/mnist-convnet/stat.json
\
| jq '.[] | .train_error, .validation_error'
\
| paste - -
\
| plot-point.py --legend 'train,val' --
title
'error'
| plot-point.py --legend 'train,val' --
xlabel 'epoch' --ylabel
'error'
For more usage, see `plot-point.py -h` or the code.
"""
...
...
@@ -23,8 +23,9 @@ import argparse, sys
from
collections
import
defaultdict
from
itertools
import
chain
#
from matplotlib import rc
from
matplotlib
import
rc
#rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
#rc('font',**{'family':'sans-serif','sans-serif':['Microsoft Yahei']})
#rc('text', usetex=True)
STDIN_FNAME
=
'-'
...
...
@@ -168,7 +169,7 @@ def plot_args_from_column_desc(desc):
def
do_plot
(
data_xs
,
data_ys
):
"""
data_xs: list of 1d array, either of size 1 o
f
size len(data_ys)
data_xs: list of 1d array, either of size 1 o
r
size len(data_ys)
data_ys: list of 1d array
"""
fig
=
plt
.
figure
(
figsize
=
(
16.18
/
1.2
,
10
/
1.2
))
...
...
@@ -214,8 +215,8 @@ def do_plot(data_xs, data_ys):
if
args
.
annotate_maximum
or
args
.
annotate_minimum
:
annotate_min_max
(
truncate_data_x
,
data_y
,
ax
)
plt
.
xlabel
(
args
.
xlabel
,
fontsize
=
'xx-large'
)
plt
.
ylabel
(
args
.
ylabel
,
fontsize
=
'xx-large'
)
plt
.
xlabel
(
args
.
xlabel
.
decode
(
'utf-8'
)
,
fontsize
=
'xx-large'
)
plt
.
ylabel
(
args
.
ylabel
.
decode
(
'utf-8'
)
,
fontsize
=
'xx-large'
)
plt
.
legend
(
loc
=
'best'
,
fontsize
=
'xx-large'
)
# adjust maxx
...
...
@@ -232,7 +233,7 @@ def do_plot(data_xs, data_ys):
plt
.
title
(
args
.
title
,
fontdict
=
{
'fontsize'
:
'20'
})
if
args
.
output
!=
''
:
plt
.
savefig
(
args
.
output
)
plt
.
savefig
(
args
.
output
,
bbox_inches
=
'tight'
)
if
args
.
show
:
plt
.
show
()
...
...
tensorpack/callbacks/inference.py
View file @
fbf93d44
...
...
@@ -55,7 +55,7 @@ class Inferencer(object):
"""
Return a list of tensor names needed for this inference
"""
return
self
.
_get_output_
va
rs
()
return
self
.
_get_output_
tenso
rs
()
@
abstractmethod
def
_get_output_tensors
(
self
):
...
...
@@ -66,18 +66,18 @@ class InferenceRunner(Callback):
A callback that runs different kinds of inferencer.
"""
def
__init__
(
self
,
ds
,
vc
s
):
def
__init__
(
self
,
ds
,
inf
s
):
"""
:param ds: inference dataset. a `DataFlow` instance.
:param
vc
s: a list of `Inferencer` instance.
:param
inf
s: a list of `Inferencer` instance.
"""
assert
isinstance
(
ds
,
DataFlow
),
type
(
ds
)
self
.
ds
=
ds
if
not
isinstance
(
vc
s
,
list
):
self
.
vcs
=
[
vc
s
]
if
not
isinstance
(
inf
s
,
list
):
self
.
infs
=
[
inf
s
]
else
:
self
.
vcs
=
vc
s
for
v
in
self
.
vc
s
:
self
.
infs
=
inf
s
for
v
in
self
.
inf
s
:
assert
isinstance
(
v
,
Inferencer
),
str
(
v
)
def
_setup_graph
(
self
):
...
...
@@ -89,21 +89,21 @@ class InferenceRunner(Callback):
def
_find_output_tensors
(
self
):
self
.
output_tensors
=
[]
# list of names
self
.
vc_to_va
rs
=
[]
# list of list of (var_name: output_idx)
for
vc
in
self
.
vc
s
:
vc_vars
=
vc
.
_
get_output_tensors
()
def
find_oid
(
var
):
if
var
in
self
.
output_tensors
:
return
self
.
output_tensors
.
index
(
var
)
self
.
inf_to_tenso
rs
=
[]
# list of list of (var_name: output_idx)
for
inf
in
self
.
inf
s
:
inf_tensors
=
inf
.
get_output_tensors
()
def
find_oid
(
t
):
if
t
in
self
.
output_tensors
:
return
self
.
output_tensors
.
index
(
t
)
else
:
self
.
output_tensors
.
append
(
var
)
self
.
output_tensors
.
append
(
t
)
return
len
(
self
.
output_tensors
)
-
1
vc_vars
=
[(
var
,
find_oid
(
var
))
for
var
in
vc_va
rs
]
self
.
vc_to_vars
.
append
(
vc_va
rs
)
inf_tensors
=
[(
t
,
find_oid
(
t
))
for
t
in
inf_tenso
rs
]
self
.
inf_to_tensors
.
append
(
inf_tenso
rs
)
def
_trigger_epoch
(
self
):
for
vc
in
self
.
vc
s
:
vc
.
before_inference
()
for
inf
in
self
.
inf
s
:
inf
.
before_inference
()
sess
=
tf
.
get_default_session
()
self
.
ds
.
reset_state
()
...
...
@@ -112,18 +112,18 @@ class InferenceRunner(Callback):
#feed = dict(zip(self.input_vars, dp)) # TODO custom dp mapping?
#outputs = sess.run(self.output_tensors, feed_dict=feed)
outputs
=
self
.
pred_func
(
dp
)
for
vc
,
varsmap
in
zip
(
self
.
vcs
,
self
.
vc_to_va
rs
):
vc_output
=
[
outputs
[
k
[
1
]]
for
k
in
vars
map
]
vc
.
datapoint
(
dp
,
vc
_output
)
for
inf
,
tensormap
in
zip
(
self
.
infs
,
self
.
inf_to_tenso
rs
):
inf_output
=
[
outputs
[
k
[
1
]]
for
k
in
tensor
map
]
inf
.
datapoint
(
dp
,
inf
_output
)
pbar
.
update
()
for
vc
in
self
.
vc
s
:
ret
=
vc
.
after_inference
()
for
inf
in
self
.
inf
s
:
ret
=
inf
.
after_inference
()
for
k
,
v
in
six
.
iteritems
(
ret
):
try
:
v
=
float
(
v
)
except
:
logger
.
warn
(
"{} returns a non-scalar statistics!"
.
format
(
type
(
vc
)
.
__name__
))
logger
.
warn
(
"{} returns a non-scalar statistics!"
.
format
(
type
(
inf
)
.
__name__
))
continue
self
.
trainer
.
write_scalar_summary
(
k
,
v
)
...
...
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