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
745ad4f0
Commit
745ad4f0
authored
Dec 28, 2015
by
ppwwyyxx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean-ups
parent
585f0837
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
56 additions
and
47 deletions
+56
-47
LICENSE
LICENSE
+1
-1
README.md
README.md
+4
-3
dataflow/base.py
dataflow/base.py
+0
-1
dataflow/common.py
dataflow/common.py
+4
-3
example_mnist.py
example_mnist.py
+2
-2
models/_common.py
models/_common.py
+13
-16
train.py
train.py
+2
-4
utils/__init__.py
utils/__init__.py
+0
-14
utils/naming.py
utils/naming.py
+0
-3
utils/summary.py
utils/summary.py
+30
-0
No files found.
LICENSE
View file @
745ad4f0
...
...
@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright
{yyyy} {name of copyright owner}
Copyright
Yuxin Wu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
...
...
README.md
View file @
745ad4f0
...
...
@@ -3,7 +3,8 @@ Neural Network Toolbox based on TensorFlow
## Features:
+
Scoped
A
bstraction of common models.
+
Scoped
a
bstraction of common models.
+
Provide callbacks to control training behavior (as in
[
Keras
](
http://keras.io
)
).
+
Use
`Dataflow`
to fine-grained control data preprocessing.
+
Write a config file, tensorpack will do the rest.
+
Use
`Dataflow`
to own fine-grained control on data preprocessing.
+
Automatically use the Queue operator in tensorflow to speed up input.
+
Training and testing graph are modeled together, automatically.
dataflow/base.py
View file @
745ad4f0
...
...
@@ -8,7 +8,6 @@ from abc import abstractmethod
__all__
=
[
'DataFlow'
]
class
DataFlow
(
object
):
# TODO private impl
@
abstractmethod
def
get_data
(
self
):
"""
...
...
dataflow/
batch
.py
→
dataflow/
common
.py
View file @
745ad4f0
...
...
@@ -11,9 +11,10 @@ __all__ = ['BatchData', 'FixedSizeData']
class
BatchData
(
DataFlow
):
def
__init__
(
self
,
ds
,
batch_size
,
remainder
=
False
):
"""
Args:
ds: a dataflow
remainder: whether to return the remaining data smaller than a batch_size
Group data in ds into batches
ds: a DataFlow instance
remainder: whether to return the remaining data smaller than a batch_size.
if set, might return a data point of a different shape
"""
self
.
ds
=
ds
self
.
batch_size
=
batch_size
...
...
example_mnist.py
100644 → 100755
View file @
745ad4f0
...
...
@@ -90,8 +90,8 @@ def get_config():
dataset_train
=
BatchData
(
Mnist
(
'train'
),
BATCH_SIZE
)
dataset_test
=
BatchData
(
Mnist
(
'test'
),
256
,
remainder
=
True
)
dataset_train
=
FixedSizeData
(
dataset_train
,
20
)
dataset_test
=
FixedSizeData
(
dataset_test
,
20
)
#
dataset_train = FixedSizeData(dataset_train, 20)
#
dataset_test = FixedSizeData(dataset_test, 20)
sess_config
=
tf
.
ConfigProto
()
sess_config
.
device_count
[
'GPU'
]
=
1
...
...
models/_common.py
View file @
745ad4f0
...
...
@@ -12,7 +12,12 @@ _layer_logged = set()
def
layer_register
(
summary_activation
=
False
):
"""
summary_activation: default behavior of whether to summary the output of this layer
Register a layer.
Args:
summary_activation:
Define the default behavior of whether to
summary the output(activation) of this layer.
Can be overriden when creating the layer.
"""
def
wrapper
(
func
):
def
inner
(
*
args
,
**
kwargs
):
...
...
@@ -26,24 +31,17 @@ def layer_register(summary_activation=False):
outputs
=
func
(
*
args
,
**
kwargs
)
if
name
not
in
_layer_logged
:
# log shape info and add activation
if
isinstance
(
inputs
,
list
):
shape_str
=
","
.
join
(
map
(
str
(
x
.
get_shape
()
.
as_list
()),
inputs
))
else
:
shape_str
=
str
(
inputs
.
get_shape
()
.
as_list
())
logger
.
info
(
"{} input: {}"
.
format
(
name
,
shape_str
))
logger
.
info
(
"{} input: {}"
.
format
(
name
,
get_shape_str
(
inputs
)))
logger
.
info
(
"{} output: {}"
.
format
(
name
,
get_shape_str
(
outputs
)))
if
isinstance
(
outputs
,
list
):
shape_str
=
","
.
join
(
map
(
str
(
x
.
get_shape
()
.
as_list
()),
outputs
))
if
do_summary
:
if
do_summary
:
if
isinstance
(
outputs
,
list
):
for
x
in
outputs
:
add_activation_summary
(
x
,
scope
.
name
)
else
:
shape_str
=
str
(
outputs
.
get_shape
()
.
as_list
())
if
do_summary
:
else
:
add_activation_summary
(
outputs
,
scope
.
name
)
logger
.
info
(
"{} output: {}"
.
format
(
name
,
shape_str
))
_layer_logged
.
add
(
name
)
return
outputs
return
inner
...
...
@@ -63,4 +61,3 @@ def shape2d(a):
def
shape4d
(
a
):
# for use with tensorflow
return
[
1
]
+
shape2d
(
a
)
+
[
1
]
train.py
View file @
745ad4f0
...
...
@@ -5,9 +5,8 @@
import
tensorflow
as
tf
from
utils
import
*
from
utils.concurrency
import
*
from
utils.callback
import
*
from
utils.summary
import
*
from
utils.concurrency
import
EnqueueThread
,
coordinator_guard
from
utils.summary
import
summary_moving_average
,
describe_model
from
dataflow
import
DataFlow
from
itertools
import
count
import
argparse
...
...
@@ -97,7 +96,6 @@ def start_train(config):
# note that summary_op will take a data from the queue.
callbacks
.
trigger_epoch
()
sess
.
close
()
def
main
(
get_config_func
):
parser
=
argparse
.
ArgumentParser
()
...
...
utils/__init__.py
View file @
745ad4f0
...
...
@@ -27,20 +27,6 @@ def timed_operation(msg, log_start=False):
logger
.
info
(
'finished {}, time={:.2f}sec.'
.
format
(
msg
,
time
.
time
()
-
start
))
def
describe_model
():
train_vars
=
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
msg
=
[
""
]
total
=
0
for
v
in
train_vars
:
shape
=
v
.
get_shape
()
ele
=
shape
.
num_elements
()
total
+=
ele
msg
.
append
(
"{}: shape={}, dim={}"
.
format
(
v
.
name
,
shape
.
as_list
(),
ele
))
msg
.
append
(
"Total dim={}"
.
format
(
total
))
logger
.
info
(
"Model Params: {}"
.
format
(
'
\n
'
.
join
(
msg
)))
# TODO disable shape output in get_model
@
contextmanager
def
create_test_graph
():
G
=
tf
.
get_default_graph
()
...
...
utils/naming.py
View file @
745ad4f0
...
...
@@ -3,9 +3,6 @@
# File: naming.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
IS_TRAINING_OP_NAME
=
'is_training'
IS_TRAINING_VAR_NAME
=
'is_training:0'
GLOBAL_STEP_OP_NAME
=
'global_step'
GLOBAL_STEP_VAR_NAME
=
'global_step:0'
...
...
utils/summary.py
View file @
745ad4f0
...
...
@@ -4,6 +4,7 @@
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import
tensorflow
as
tf
import
logger
from
.naming
import
*
def
create_summary
(
name
,
v
):
...
...
@@ -44,6 +45,10 @@ def add_histogram_summary(regex):
tf
.
histogram_summary
(
name
,
p
)
def
summary_moving_average
(
cost_var
):
""" Create a MovingAverage op and summary for all variables in
COST_VARS_KEY, SUMMARY_VARS_KEY, as well as the argument
Return a op to maintain these average
"""
global_step_var
=
tf
.
get_default_graph
()
.
get_tensor_by_name
(
GLOBAL_STEP_VAR_NAME
)
averager
=
tf
.
train
.
ExponentialMovingAverage
(
0.9
,
num_updates
=
global_step_var
,
name
=
'avg'
)
...
...
@@ -54,3 +59,28 @@ def summary_moving_average(cost_var):
for
c
in
vars_to_summary
:
tf
.
scalar_summary
(
c
.
op
.
name
,
averager
.
average
(
c
))
return
avg_maintain_op
def
describe_model
():
""" describe the current model parameters"""
train_vars
=
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
msg
=
[
""
]
total
=
0
for
v
in
train_vars
:
shape
=
v
.
get_shape
()
ele
=
shape
.
num_elements
()
total
+=
ele
msg
.
append
(
"{}: shape={}, dim={}"
.
format
(
v
.
name
,
shape
.
as_list
(),
ele
))
msg
.
append
(
"Total dim={}"
.
format
(
total
))
logger
.
info
(
"Model Params: {}"
.
format
(
'
\n
'
.
join
(
msg
)))
def
get_shape_str
(
tensors
):
""" return the shape string for a tensor or a list of tensors"""
if
isinstance
(
tensors
,
list
):
shape_str
=
","
.
join
(
map
(
str
(
x
.
get_shape
()
.
as_list
()),
tensors
))
else
:
shape_str
=
str
(
tensors
.
get_shape
()
.
as_list
())
return
shape_str
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