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
e6cf9885
Commit
e6cf9885
authored
Jun 23, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
standardize the range in put_image
parent
3c52b7c1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
9 deletions
+20
-9
tensorpack/RL/history.py
tensorpack/RL/history.py
+4
-0
tensorpack/callbacks/monitor.py
tensorpack/callbacks/monitor.py
+3
-3
tensorpack/tfutils/summary.py
tensorpack/tfutils/summary.py
+13
-6
No files found.
tensorpack/RL/history.py
View file @
e6cf9885
...
@@ -36,6 +36,10 @@ class HistoryBuffer(object):
...
@@ -36,6 +36,10 @@ class HistoryBuffer(object):
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
buf
)
return
len
(
self
.
buf
)
@
property
def
maxlen
(
self
):
return
self
.
buf
.
maxlen
class
HistoryFramePlayer
(
ProxyPlayer
):
class
HistoryFramePlayer
(
ProxyPlayer
):
""" Include history frames in state, or use black images.
""" Include history frames in state, or use black images.
...
...
tensorpack/callbacks/monitor.py
View file @
e6cf9885
...
@@ -70,7 +70,7 @@ class TrainingMonitor(Callback):
...
@@ -70,7 +70,7 @@ class TrainingMonitor(Callback):
def
put_image
(
self
,
name
,
val
):
def
put_image
(
self
,
name
,
val
):
"""
"""
Args:
Args:
val (np.ndarray): 4D (NHWC) numpy array of images.
val (np.ndarray): 4D (NHWC) numpy array of images
in range [0,255]
.
If channel is 3, assumed to be RGB.
If channel is 3, assumed to be RGB.
"""
"""
pass
pass
...
@@ -135,8 +135,8 @@ class Monitors(TrainingMonitor):
...
@@ -135,8 +135,8 @@ class Monitors(TrainingMonitor):
"""
"""
Args:
Args:
name (str):
name (str):
val (np.ndarray): 2D, 3D (HWC) or 4D (NHWC) numpy array of images
.
val (np.ndarray): 2D, 3D (HWC) or 4D (NHWC) numpy array of images
If channel is 3, assumed to be RGB.
in range [0,255].
If channel is 3, assumed to be RGB.
"""
"""
assert
isinstance
(
val
,
np
.
ndarray
)
assert
isinstance
(
val
,
np
.
ndarray
)
arr
=
image_to_nhwc
(
val
)
arr
=
image_to_nhwc
(
val
)
...
...
tensorpack/tfutils/summary.py
View file @
e6cf9885
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
six
import
six
import
tensorflow
as
tf
import
tensorflow
as
tf
import
re
import
re
import
io
from
six.moves
import
range
from
six.moves
import
range
from
..utils
import
logger
from
..utils
import
logger
...
@@ -20,6 +21,9 @@ __all__ = ['create_scalar_summary', 'add_param_summary', 'add_activation_summary
...
@@ -20,6 +21,9 @@ __all__ = ['create_scalar_summary', 'add_param_summary', 'add_activation_summary
def
create_scalar_summary
(
name
,
v
):
def
create_scalar_summary
(
name
,
v
):
"""
"""
Args:
name (str):
v (float): scalar value
Returns:
Returns:
tf.Summary: a tf.Summary object with name and simple scalar value v.
tf.Summary: a tf.Summary object with name and simple scalar value v.
"""
"""
...
@@ -35,25 +39,28 @@ def create_image_summary(name, val):
...
@@ -35,25 +39,28 @@ def create_image_summary(name, val):
Args:
Args:
name(str):
name(str):
val(np.ndarray): 4D tensor of NHWC. assume RGB if C==3.
val(np.ndarray): 4D tensor of NHWC. assume RGB if C==3.
Can be either float or uint8. Range has to be [0,255].
Returns:
Returns:
tf.Summary:
tf.Summary:
"""
"""
assert
isinstance
(
name
,
six
.
string_types
),
type
(
name
)
assert
isinstance
(
name
,
six
.
string_types
),
type
(
name
)
n
,
h
,
w
,
c
=
val
.
shape
n
,
h
,
w
,
c
=
val
.
shape
val
=
val
.
astype
(
'uint8'
)
s
=
tf
.
Summary
()
s
=
tf
.
Summary
()
for
k
in
range
(
n
):
for
k
in
range
(
n
):
tag
=
name
if
n
==
1
else
'{}/{}'
.
format
(
name
,
k
)
tag
=
name
if
n
==
1
else
'{}/{}'
.
format
(
name
,
k
)
# imencode assumes BGR
ret
,
buf
=
cv2
.
imencode
(
'.png'
,
val
[
k
,
:,
:,
::
-
1
])
buf
=
io
.
BytesIO
()
assert
ret
,
"imencode failed!"
# scipy assumes RGB
scipy
.
misc
.
toimage
(
val
[
k
])
.
save
(
buf
,
format
=
'png'
)
img
=
tf
.
Summary
.
Image
()
img
=
tf
.
Summary
.
Image
()
img
.
height
=
h
img
.
height
=
h
img
.
width
=
w
img
.
width
=
w
# 1 - grayscale 3 - RGB 4 - RGBA
# 1 - grayscale 3 - RGB 4 - RGBA
img
.
colorspace
=
c
img
.
colorspace
=
c
img
.
encoded_image_string
=
buf
.
tostring
()
img
.
encoded_image_string
=
buf
.
getvalue
()
s
.
value
.
add
(
tag
=
tag
,
image
=
img
)
s
.
value
.
add
(
tag
=
tag
,
image
=
img
)
return
s
return
s
...
@@ -171,7 +178,7 @@ def add_moving_summary(v, *args, **kwargs):
...
@@ -171,7 +178,7 @@ def add_moving_summary(v, *args, **kwargs):
try
:
try
:
import
cv2
import
scipy.misc
except
ImportError
:
except
ImportError
:
from
..utils.develop
import
create_dummy_func
from
..utils.develop
import
create_dummy_func
create_image_summary
=
create_dummy_func
(
'create_image_summary'
,
'
cv2
'
)
# noqa
create_image_summary
=
create_dummy_func
(
'create_image_summary'
,
'
scipy.misc
'
)
# noqa
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