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
ffd78d7e
Commit
ffd78d7e
authored
Aug 17, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. catch closed session in enqueuethread
2. PrintGradient 3. validate boxes before drawing
parent
8c0106e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
14 deletions
+49
-14
tensorpack/graph_builder/input_source.py
tensorpack/graph_builder/input_source.py
+5
-2
tensorpack/tfutils/gradproc.py
tensorpack/tfutils/gradproc.py
+37
-10
tensorpack/tfutils/symbolic_functions.py
tensorpack/tfutils/symbolic_functions.py
+1
-1
tensorpack/utils/viz.py
tensorpack/utils/viz.py
+6
-1
No files found.
tensorpack/graph_builder/input_source.py
View file @
ffd78d7e
...
@@ -191,8 +191,11 @@ class EnqueueThread(ShareSessionThread):
...
@@ -191,8 +191,11 @@ class EnqueueThread(ShareSessionThread):
self
.
op
.
run
(
feed_dict
=
feed
)
self
.
op
.
run
(
feed_dict
=
feed
)
except
(
tf
.
errors
.
CancelledError
,
tf
.
errors
.
OutOfRangeError
,
DataFlowTerminated
):
except
(
tf
.
errors
.
CancelledError
,
tf
.
errors
.
OutOfRangeError
,
DataFlowTerminated
):
pass
pass
except
Exception
:
except
Exception
as
e
:
logger
.
exception
(
"Exception in {}:"
.
format
(
self
.
name
))
if
isinstance
(
e
,
RuntimeError
)
and
'closed Session'
in
str
(
e
):
pass
else
:
logger
.
exception
(
"Exception in {}:"
.
format
(
self
.
name
))
finally
:
finally
:
try
:
try
:
self
.
close_op
.
run
()
self
.
close_op
.
run
()
...
...
tensorpack/tfutils/gradproc.py
View file @
ffd78d7e
...
@@ -9,12 +9,12 @@ import re
...
@@ -9,12 +9,12 @@ import re
import
six
import
six
import
inspect
import
inspect
from
..utils
import
logger
from
..utils
import
logger
from
.symbolic_functions
import
rms
from
.symbolic_functions
import
rms
,
print_stat
from
.summary
import
add_moving_summary
from
.summary
import
add_moving_summary
__all__
=
[
'GradientProcessor'
,
__all__
=
[
'GradientProcessor'
,
'FilterNoneGrad'
,
'GlobalNormClip'
,
'MapGradient'
,
'SummaryGradient'
,
'FilterNoneGrad'
,
'GlobalNormClip'
,
'MapGradient'
,
'SummaryGradient'
,
'CheckGradient'
,
'ScaleGradient'
]
'
PrintGradient'
,
'
CheckGradient'
,
'ScaleGradient'
]
@
six
.
add_metaclass
(
ABCMeta
)
@
six
.
add_metaclass
(
ABCMeta
)
...
@@ -138,28 +138,55 @@ class MapGradient(GradientProcessor):
...
@@ -138,28 +138,55 @@ class MapGradient(GradientProcessor):
return
ret
return
ret
_summaried_gradient
=
set
()
# TODO has dependency problems: sess.run may not depend on grad
# TODO has dependency problems: sess.run may not depend on grad
# maybe group maintain op and grad ?
# maybe group maintain op and grad ?
class
SummaryGradient
(
MapGradient
):
class
SummaryGradient
(
MapGradient
):
"""
"""
Summary histogram and RMS for each gradient variable.
For each gradient tensor, summary its histogram and add it to moving
summaries.
"""
"""
# avoid duplicate summaries from towers
# TODO this is global. not good.
_summaried_gradient
=
set
()
def
__init__
(
self
):
def
__init__
(
self
,
regex
=
'.*'
):
super
(
SummaryGradient
,
self
)
.
__init__
(
self
.
_mapper
)
"""
Args:
regex(str): same as in :class:`MapGradient`.
"""
super
(
SummaryGradient
,
self
)
.
__init__
(
self
.
_mapper
,
regex
)
def
_mapper
(
self
,
grad
,
var
):
def
_mapper
(
self
,
grad
,
var
):
name
=
var
.
op
.
name
name
=
var
.
op
.
name
if
name
not
in
_summaried_gradient
:
if
name
not
in
SummaryGradient
.
_summaried_gradient
:
_summaried_gradient
.
add
(
name
)
SummaryGradient
.
_summaried_gradient
.
add
(
name
)
tf
.
summary
.
histogram
(
name
+
'-grad'
,
grad
)
tf
.
summary
.
histogram
(
name
+
'-grad'
,
grad
)
add_moving_summary
(
rms
(
grad
,
name
=
name
+
'/rms'
))
add_moving_summary
(
rms
(
grad
,
name
=
name
+
'/rms'
))
return
grad
return
grad
class
PrintGradient
(
MapGradient
):
"""
Print the gradients every step with :func:`symbolic_functions.print_stat`.
"""
_printed
=
set
()
# TODO this is global. not good.
def
__init__
(
self
,
regex
=
'.*'
):
"""
Args:
regex(str): same as in :class:`MapGradient`.
"""
super
(
PrintGradient
,
self
)
.
__init__
(
self
.
_mapper
,
regex
)
def
_mapper
(
self
,
grad
,
var
):
name
=
var
.
op
.
name
if
name
not
in
PrintGradient
.
_printed
:
PrintGradient
.
_printed
.
add
(
name
)
grad
=
print_stat
(
grad
,
message
=
name
+
'-grad'
)
return
grad
class
CheckGradient
(
MapGradient
):
class
CheckGradient
(
MapGradient
):
"""
"""
Check for numeric issue.
Check for numeric issue.
...
...
tensorpack/tfutils/symbolic_functions.py
View file @
ffd78d7e
...
@@ -105,7 +105,7 @@ def print_stat(x, message=None):
...
@@ -105,7 +105,7 @@ def print_stat(x, message=None):
"""
"""
if
message
is
None
:
if
message
is
None
:
message
=
x
.
op
.
name
message
=
x
.
op
.
name
return
tf
.
Print
(
x
,
[
tf
.
shape
(
x
),
tf
.
reduce_mean
(
x
),
x
],
summarize
=
20
,
return
tf
.
Print
(
x
,
[
tf
.
shape
(
x
),
tf
.
reduce_mean
(
x
),
rms
(
x
),
x
],
summarize
=
20
,
message
=
message
,
name
=
'print_'
+
x
.
op
.
name
)
message
=
message
,
name
=
'print_'
+
x
.
op
.
name
)
...
...
tensorpack/utils/viz.py
View file @
ffd78d7e
...
@@ -379,7 +379,12 @@ def draw_boxes(im, boxes, labels=None, color=None):
...
@@ -379,7 +379,12 @@ def draw_boxes(im, boxes, labels=None, color=None):
if
labels
is
not
None
:
if
labels
is
not
None
:
assert
len
(
labels
)
==
len
(
boxes
),
"{} != {}"
.
format
(
len
(
labels
),
len
(
boxes
))
assert
len
(
labels
)
==
len
(
boxes
),
"{} != {}"
.
format
(
len
(
labels
),
len
(
boxes
))
areas
=
(
boxes
[:,
2
]
-
boxes
[:,
0
]
+
1
)
*
(
boxes
[:,
3
]
-
boxes
[:,
1
]
+
1
)
areas
=
(
boxes
[:,
2
]
-
boxes
[:,
0
]
+
1
)
*
(
boxes
[:,
3
]
-
boxes
[:,
1
]
+
1
)
sorted_inds
=
np
.
argsort
(
-
areas
)
sorted_inds
=
np
.
argsort
(
-
areas
)
# draw large ones first
assert
areas
.
min
()
>
0
,
areas
.
min
()
# allow equal, because we are not very strict about rounding error here
assert
boxes
[:,
0
]
.
min
()
>=
0
and
boxes
[:,
1
]
.
min
()
>=
0
\
and
boxes
[:,
2
]
.
max
()
<=
im
.
shape
[
1
]
and
boxes
[:,
3
]
.
max
()
<=
im
.
shape
[
0
],
\
"Image shape: {}
\n
Boxes:
\n
{}"
.
format
(
str
(
im
.
shape
),
str
(
boxes
))
im
=
im
.
copy
()
im
=
im
.
copy
()
COLOR
=
(
218
,
218
,
218
)
if
color
is
None
else
color
COLOR
=
(
218
,
218
,
218
)
if
color
is
None
else
color
...
...
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