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
5654f290
Commit
5654f290
authored
Oct 31, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dump vars and visualizations
parent
3754faac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
14 deletions
+57
-14
opt-requirements.txt
opt-requirements.txt
+1
-0
scripts/checkpoint-manipulate.py
scripts/checkpoint-manipulate.py
+18
-7
tensorpack/tfutils/varmanip.py
tensorpack/tfutils/varmanip.py
+3
-5
tensorpack/utils/viz.py
tensorpack/utils/viz.py
+35
-2
No files found.
opt-requirements.txt
View file @
5654f290
...
@@ -5,3 +5,4 @@ h5py
...
@@ -5,3 +5,4 @@ h5py
pyzmq
pyzmq
tornado
; python_version < '3.0'
tornado
; python_version < '3.0'
lmdb
lmdb
matplotlib
scripts/checkpoint-manipulate.py
View file @
5654f290
...
@@ -6,13 +6,24 @@
...
@@ -6,13 +6,24 @@
import
numpy
as
np
import
numpy
as
np
from
tensorpack.tfutils.varmanip
import
dump_chkpt_vars
from
tensorpack.tfutils.varmanip
import
dump_chkpt_vars
from
tensorpack.utils
import
logger
import
tensorflow
as
tf
import
tensorflow
as
tf
import
sys
import
sys
import
argparse
model_path
=
sys
.
argv
[
1
]
parser
=
argparse
.
ArgumentParser
()
reader
=
tf
.
train
.
NewCheckpointReader
(
model_path
)
parser
.
add_argument
(
'checkpoint'
)
var_names
=
reader
.
get_variable_to_shape_map
()
.
keys
()
parser
.
add_argument
(
'--dump'
,
help
=
'dump to an npy file'
)
result
=
{}
parser
.
add_argument
(
'--shell'
,
action
=
'store_true'
,
help
=
'start a shell with the params'
)
for
n
in
var_names
:
args
=
parser
.
parse_args
()
result
[
n
]
=
reader
.
get_tensor
(
n
)
import
IPython
as
IP
;
IP
.
embed
(
config
=
IP
.
terminal
.
ipapp
.
load_default_config
())
if
args
.
checkpoint
.
endswith
(
'.npy'
):
params
=
np
.
load
(
args
.
checkpoint
)
.
item
()
else
:
params
=
dump_chkpt_vars
(
args
.
checkpoint
)
logger
.
info
(
"Variables in the checkpoint:"
)
logger
.
info
(
str
(
params
.
keys
()))
if
args
.
dump
:
np
.
save
(
args
.
dump
,
params
)
if
args
.
shell
:
import
IPython
as
IP
;
IP
.
embed
(
config
=
IP
.
terminal
.
ipapp
.
load_default_config
())
tensorpack/tfutils/varmanip.py
View file @
5654f290
...
@@ -87,13 +87,11 @@ the same name".format(v.name))
...
@@ -87,13 +87,11 @@ the same name".format(v.name))
logger
.
info
(
str
(
result
.
keys
()))
logger
.
info
(
str
(
result
.
keys
()))
np
.
save
(
path
,
result
)
np
.
save
(
path
,
result
)
def
dump_chkpt_vars
(
model_path
,
output
):
def
dump_chkpt_vars
(
model_path
):
""" Dump all variables from a checkpoint """
""" Dump all variables from a checkpoint
to a dict
"""
reader
=
tf
.
train
.
NewCheckpointReader
(
model_path
)
reader
=
tf
.
train
.
NewCheckpointReader
(
model_path
)
var_names
=
reader
.
get_variable_to_shape_map
()
.
keys
()
var_names
=
reader
.
get_variable_to_shape_map
()
.
keys
()
result
=
{}
result
=
{}
for
n
in
var_names
:
for
n
in
var_names
:
result
[
n
]
=
reader
.
get_tensor
(
n
)
result
[
n
]
=
reader
.
get_tensor
(
n
)
logger
.
info
(
"Variables to save to {}:"
.
format
(
output
))
return
result
logger
.
info
(
str
(
result
.
keys
()))
np
.
save
(
output
,
result
)
tensorpack/utils/viz.py
View file @
5654f290
...
@@ -4,6 +4,37 @@
...
@@ -4,6 +4,37 @@
# Credit: zxytim
# Credit: zxytim
import
numpy
as
np
import
numpy
as
np
import
io
import
cv2
try
:
import
matplotlib.pyplot
as
plt
except
ImportError
:
pass
__all__
=
[
'pyplot2img'
,
'build_patch_list'
,
'pyplot_viz'
]
def
pyplot2img
(
plt
):
buf
=
io
.
BytesIO
()
plt
.
axis
(
'off'
)
plt
.
savefig
(
buf
,
format
=
'png'
,
bbox_inches
=
'tight'
,
pad_inches
=
0
)
buf
.
seek
(
0
)
rawbuf
=
np
.
frombuffer
(
buf
.
getvalue
(),
dtype
=
'uint8'
)
im
=
cv2
.
imdecode
(
rawbuf
,
cv2
.
IMREAD_COLOR
)
buf
.
close
()
return
im
def
pyplot_viz
(
img
,
shape
=
None
):
""" use pyplot to visualize the image
Note: this is quite slow. and the returned image will have a border
"""
plt
.
clf
()
plt
.
axes
([
0
,
0
,
1
,
1
])
plt
.
imshow
(
img
)
ret
=
pyplot2img
(
plt
)
if
shape
is
not
None
:
ret
=
cv2
.
resize
(
ret
,
shape
)
return
ret
def
minnone
(
x
,
y
):
def
minnone
(
x
,
y
):
if
x
is
None
:
x
=
y
if
x
is
None
:
x
=
y
...
@@ -25,8 +56,10 @@ def build_patch_list(patch_list,
...
@@ -25,8 +56,10 @@ def build_patch_list(patch_list,
np
.
random
.
shuffle
(
patch_list
)
np
.
random
.
shuffle
(
patch_list
)
ph
,
pw
=
patch_list
.
shape
[
1
:
3
]
ph
,
pw
=
patch_list
.
shape
[
1
:
3
]
mh
,
mw
=
max
(
max_height
,
ph
+
border
),
max
(
max_width
,
pw
+
border
)
mh
,
mw
=
max
(
max_height
,
ph
+
border
),
max
(
max_width
,
pw
+
border
)
nr_row
=
minnone
(
nr_row
,
max_height
/
(
ph
+
border
))
if
nr_row
is
None
:
nr_col
=
minnone
(
nr_col
,
max_width
/
(
pw
+
border
))
nr_row
=
minnone
(
nr_row
,
max_height
/
(
ph
+
border
))
if
nr_col
is
None
:
nr_col
=
minnone
(
nr_col
,
max_width
/
(
pw
+
border
))
canvas
=
np
.
zeros
((
nr_row
*
(
ph
+
border
)
-
border
,
canvas
=
np
.
zeros
((
nr_row
*
(
ph
+
border
)
-
border
,
nr_col
*
(
pw
+
border
)
-
border
,
nr_col
*
(
pw
+
border
)
-
border
,
...
...
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