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
14b3578a
Commit
14b3578a
authored
Jan 29, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a rename in examples (not a breaking change)
parent
88af1f1d
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
88 additions
and
98 deletions
+88
-98
examples/A3C-Gym/run-atari.py
examples/A3C-Gym/run-atari.py
+1
-2
examples/A3C-Gym/train-atari.py
examples/A3C-Gym/train-atari.py
+1
-2
examples/CTC-TIMIT/train-timit.py
examples/CTC-TIMIT/train-timit.py
+3
-4
examples/Char-RNN/char-rnn.py
examples/Char-RNN/char-rnn.py
+8
-8
examples/ConvolutionalPoseMachines/load-cpm.py
examples/ConvolutionalPoseMachines/load-cpm.py
+1
-1
examples/DeepQNetwork/DQN.py
examples/DeepQNetwork/DQN.py
+1
-2
examples/DisturbLabel/mnist-disturb.py
examples/DisturbLabel/mnist-disturb.py
+2
-3
examples/DoReFa-Net/alexnet-dorefa.py
examples/DoReFa-Net/alexnet-dorefa.py
+3
-4
examples/DoReFa-Net/resnet-dorefa.py
examples/DoReFa-Net/resnet-dorefa.py
+3
-3
examples/DoReFa-Net/svhn-digit-dorefa.py
examples/DoReFa-Net/svhn-digit-dorefa.py
+3
-4
examples/GAN/DCGAN-CelebA.py
examples/GAN/DCGAN-CelebA.py
+3
-4
examples/GAN/Image2Image.py
examples/GAN/Image2Image.py
+3
-4
examples/GAN/InfoGAN-mnist.py
examples/GAN/InfoGAN-mnist.py
+3
-3
examples/HED/hed.py
examples/HED/hed.py
+3
-4
examples/Inception/inception-bn.py
examples/Inception/inception-bn.py
+3
-3
examples/Inception/inceptionv3.py
examples/Inception/inceptionv3.py
+3
-3
examples/PennTreebank/PTB-LSTM.py
examples/PennTreebank/PTB-LSTM.py
+3
-3
examples/ResNet/cifar10-resnet.py
examples/ResNet/cifar10-resnet.py
+3
-3
examples/ResNet/imagenet-resnet.py
examples/ResNet/imagenet-resnet.py
+3
-3
examples/Saliency/saliency-maps.py
examples/Saliency/saliency-maps.py
+3
-3
examples/SimilarityLearning/mnist-embeddings.py
examples/SimilarityLearning/mnist-embeddings.py
+11
-11
examples/SpatialTransformer/mnist-addition.py
examples/SpatialTransformer/mnist-addition.py
+3
-4
examples/cifar-convnet.py
examples/cifar-convnet.py
+3
-4
examples/load-alexnet.py
examples/load-alexnet.py
+1
-1
examples/load-vgg16.py
examples/load-vgg16.py
+1
-2
examples/mnist-convnet.py
examples/mnist-convnet.py
+4
-4
examples/svhn-digit-convnet.py
examples/svhn-digit-convnet.py
+3
-3
tensorpack/models/model_desc.py
tensorpack/models/model_desc.py
+6
-3
No files found.
examples/A3C-Gym/run-atari.py
View file @
14b3578a
...
@@ -38,8 +38,7 @@ def get_player(dumpdir=None):
...
@@ -38,8 +38,7 @@ def get_player(dumpdir=None):
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
assert
NUM_ACTIONS
is
not
None
assert
NUM_ACTIONS
is
not
None
return
[
InputVar
(
tf
.
float32
,
(
None
,)
+
IMAGE_SHAPE3
,
'state'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,)
+
IMAGE_SHAPE3
,
'state'
),
InputVar
(
tf
.
int32
,
(
None
,),
'action'
),
InputVar
(
tf
.
int32
,
(
None
,),
'action'
),
...
...
examples/A3C-Gym/train-atari.py
View file @
14b3578a
...
@@ -75,8 +75,7 @@ class MySimulatorWorker(SimulatorProcess):
...
@@ -75,8 +75,7 @@ class MySimulatorWorker(SimulatorProcess):
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
assert
NUM_ACTIONS
is
not
None
assert
NUM_ACTIONS
is
not
None
return
[
InputVar
(
tf
.
float32
,
(
None
,)
+
IMAGE_SHAPE3
,
'state'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,)
+
IMAGE_SHAPE3
,
'state'
),
InputVar
(
tf
.
int64
,
(
None
,),
'action'
),
InputVar
(
tf
.
int64
,
(
None
,),
'action'
),
...
...
examples/CTC-TIMIT/train-timit.py
View file @
14b3578a
...
@@ -27,8 +27,7 @@ FEATUREDIM = 39
...
@@ -27,8 +27,7 @@ FEATUREDIM = 39
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
None
,
FEATUREDIM
],
'feat'
),
# bxmaxseqx39
return
[
InputVar
(
tf
.
float32
,
[
None
,
None
,
FEATUREDIM
],
'feat'
),
# bxmaxseqx39
InputVar
(
tf
.
int64
,
None
,
'labelidx'
),
# label is b x maxlen, sparse
InputVar
(
tf
.
int64
,
None
,
'labelidx'
),
# label is b x maxlen, sparse
InputVar
(
tf
.
int32
,
None
,
'labelvalue'
),
InputVar
(
tf
.
int32
,
None
,
'labelvalue'
),
...
@@ -36,8 +35,8 @@ class Model(ModelDesc):
...
@@ -36,8 +35,8 @@ class Model(ModelDesc):
InputVar
(
tf
.
int32
,
[
None
],
'seqlen'
),
# b
InputVar
(
tf
.
int32
,
[
None
],
'seqlen'
),
# b
]
]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
feat
,
labelidx
,
labelvalue
,
labelshape
,
seqlen
=
input
_var
s
feat
,
labelidx
,
labelvalue
,
labelshape
,
seqlen
=
inputs
label
=
tf
.
SparseTensor
(
labelidx
,
labelvalue
,
labelshape
)
label
=
tf
.
SparseTensor
(
labelidx
,
labelvalue
,
labelshape
)
cell
=
tf
.
contrib
.
rnn
.
BasicLSTMCell
(
num_units
=
HIDDEN
)
cell
=
tf
.
contrib
.
rnn
.
BasicLSTMCell
(
num_units
=
HIDDEN
)
...
...
examples/Char-RNN/char-rnn.py
View file @
14b3578a
...
@@ -60,12 +60,12 @@ class CharRNNData(RNGDataFlow):
...
@@ -60,12 +60,12 @@ class CharRNNData(RNGDataFlow):
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
int32
,
(
None
,
param
.
seq_len
),
'input'
),
return
[
InputVar
(
tf
.
int32
,
(
None
,
param
.
seq_len
),
'input'
),
InputVar
(
tf
.
int32
,
(
None
,
param
.
seq_len
),
'nextinput'
)]
InputVar
(
tf
.
int32
,
(
None
,
param
.
seq_len
),
'nextinput'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
input
,
nextinput
=
input
_var
s
input
,
nextinput
=
inputs
cell
=
tf
.
contrib
.
rnn
.
BasicLSTMCell
(
num_units
=
param
.
rnn_size
)
cell
=
tf
.
contrib
.
rnn
.
BasicLSTMCell
(
num_units
=
param
.
rnn_size
)
cell
=
tf
.
contrib
.
rnn
.
MultiRNNCell
([
cell
]
*
param
.
num_rnn_layer
)
cell
=
tf
.
contrib
.
rnn
.
MultiRNNCell
([
cell
]
*
param
.
num_rnn_layer
)
...
@@ -131,18 +131,18 @@ def sample(path, start, length):
...
@@ -131,18 +131,18 @@ def sample(path, start, length):
ds
=
CharRNNData
(
param
.
corpus
,
100000
)
ds
=
CharRNNData
(
param
.
corpus
,
100000
)
model
=
Model
()
model
=
Model
()
input
_vars
=
model
.
get_input_va
rs
()
input
s
=
model
.
get_reuse_placehd
rs
()
model
.
build_graph
(
input
_var
s
,
False
)
model
.
build_graph
(
inputs
,
False
)
sess
=
tf
.
Session
()
sess
=
tf
.
Session
()
tfutils
.
SaverRestore
(
path
)
.
init
(
sess
)
tfutils
.
SaverRestore
(
path
)
.
init
(
sess
)
dummy_input
=
np
.
zeros
((
1
,
1
),
dtype
=
'int32'
)
dummy_input
=
np
.
zeros
((
1
,
1
),
dtype
=
'int32'
)
with
sess
.
as_default
():
with
sess
.
as_default
():
# feed the starting sentence
# feed the starting sentence
state
=
model
.
initial
.
eval
({
input
_var
s
[
0
]:
dummy_input
})
state
=
model
.
initial
.
eval
({
inputs
[
0
]:
dummy_input
})
for
c
in
start
[:
-
1
]:
for
c
in
start
[:
-
1
]:
x
=
np
.
array
([[
ds
.
lut
.
get_idx
(
c
)]],
dtype
=
'int32'
)
x
=
np
.
array
([[
ds
.
lut
.
get_idx
(
c
)]],
dtype
=
'int32'
)
state
=
model
.
last_state
.
eval
({
input
_var
s
[
0
]:
x
,
model
.
initial
:
state
})
state
=
model
.
last_state
.
eval
({
inputs
[
0
]:
x
,
model
.
initial
:
state
})
def
pick
(
prob
):
def
pick
(
prob
):
t
=
np
.
cumsum
(
prob
)
t
=
np
.
cumsum
(
prob
)
...
@@ -155,7 +155,7 @@ def sample(path, start, length):
...
@@ -155,7 +155,7 @@ def sample(path, start, length):
for
k
in
range
(
length
):
for
k
in
range
(
length
):
x
=
np
.
array
([[
ds
.
lut
.
get_idx
(
c
)]],
dtype
=
'int32'
)
x
=
np
.
array
([[
ds
.
lut
.
get_idx
(
c
)]],
dtype
=
'int32'
)
[
prob
,
state
]
=
sess
.
run
([
model
.
prob
,
model
.
last_state
],
[
prob
,
state
]
=
sess
.
run
([
model
.
prob
,
model
.
last_state
],
{
input
_var
s
[
0
]:
x
,
model
.
initial
:
state
})
{
inputs
[
0
]:
x
,
model
.
initial
:
state
})
c
=
ds
.
lut
.
get_obj
(
pick
(
prob
[
0
]))
c
=
ds
.
lut
.
get_obj
(
pick
(
prob
[
0
]))
ret
+=
c
ret
+=
c
print
(
ret
)
print
(
ret
)
...
...
examples/ConvolutionalPoseMachines/load-cpm.py
View file @
14b3578a
...
@@ -44,7 +44,7 @@ def get_gaussian_map():
...
@@ -44,7 +44,7 @@ def get_gaussian_map():
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
368
,
368
,
3
),
'input'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,
368
,
368
,
3
),
'input'
),
InputVar
(
tf
.
float32
,
(
None
,
368
,
368
,
15
),
'label'
),
InputVar
(
tf
.
float32
,
(
None
,
368
,
368
,
15
),
'label'
),
]
]
...
...
examples/DeepQNetwork/DQN.py
View file @
14b3578a
...
@@ -68,8 +68,7 @@ common.get_player = get_player # so that eval functions in common can use the p
...
@@ -68,8 +68,7 @@ common.get_player = get_player # so that eval functions in common can use the p
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
if
NUM_ACTIONS
is
None
:
if
NUM_ACTIONS
is
None
:
p
=
get_player
()
p
=
get_player
()
del
p
del
p
...
...
examples/DisturbLabel/mnist-disturb.py
View file @
14b3578a
...
@@ -29,9 +29,8 @@ IMAGE_SIZE = 28
...
@@ -29,9 +29,8 @@ IMAGE_SIZE = 28
class
Model
(
mnist_example
.
Model
):
class
Model
(
mnist_example
.
Model
):
def
_build_graph
(
self
,
inputs
):
def
_build_graph
(
self
,
input_vars
):
image
,
label
=
inputs
image
,
label
=
input_vars
image
=
tf
.
expand_dims
(
image
,
3
)
image
=
tf
.
expand_dims
(
image
,
3
)
with
argscope
(
Conv2D
,
kernel_shape
=
5
,
nl
=
tf
.
nn
.
relu
):
with
argscope
(
Conv2D
,
kernel_shape
=
5
,
nl
=
tf
.
nn
.
relu
):
...
...
examples/DoReFa-Net/alexnet-dorefa.py
View file @
14b3578a
...
@@ -74,13 +74,12 @@ BATCH_SIZE = None
...
@@ -74,13 +74,12 @@ BATCH_SIZE = None
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
255.0
image
=
image
/
255.0
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
...
...
examples/DoReFa-Net/resnet-dorefa.py
View file @
14b3578a
...
@@ -33,12 +33,12 @@ BITG = 32
...
@@ -33,12 +33,12 @@ BITG = 32
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
256.0
image
=
image
/
256.0
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
...
...
examples/DoReFa-Net/svhn-digit-dorefa.py
View file @
14b3578a
...
@@ -43,13 +43,12 @@ BITG = 4
...
@@ -43,13 +43,12 @@ BITG = 4
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
40
,
40
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
40
,
40
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
is_training
=
get_current_tower_context
()
.
is_training
is_training
=
get_current_tower_context
()
.
is_training
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
...
...
examples/GAN/DCGAN-CelebA.py
View file @
14b3578a
...
@@ -36,8 +36,7 @@ CFG.Z_DIM = 100
...
@@ -36,8 +36,7 @@ CFG.Z_DIM = 100
class
Model
(
GANModelDesc
):
class
Model
(
GANModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
CFG
.
SHAPE
,
CFG
.
SHAPE
,
3
),
'input'
)]
return
[
InputVar
(
tf
.
float32
,
(
None
,
CFG
.
SHAPE
,
CFG
.
SHAPE
,
3
),
'input'
)]
def
generator
(
self
,
z
):
def
generator
(
self
,
z
):
...
@@ -70,8 +69,8 @@ class Model(GANModelDesc):
...
@@ -70,8 +69,8 @@ class Model(GANModelDesc):
.
FullyConnected
(
'fct'
,
1
,
nl
=
tf
.
identity
)())
.
FullyConnected
(
'fct'
,
1
,
nl
=
tf
.
identity
)())
return
l
return
l
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image_pos
=
input
_var
s
[
0
]
image_pos
=
inputs
[
0
]
image_pos
=
image_pos
/
128.0
-
1
image_pos
=
image_pos
/
128.0
-
1
z
=
tf
.
random_uniform
([
CFG
.
BATCH
,
CFG
.
Z_DIM
],
-
1
,
1
,
name
=
'z_train'
)
z
=
tf
.
random_uniform
([
CFG
.
BATCH
,
CFG
.
Z_DIM
],
-
1
,
1
,
name
=
'z_train'
)
...
...
examples/GAN/Image2Image.py
View file @
14b3578a
...
@@ -43,8 +43,7 @@ NF = 64 # number of filter
...
@@ -43,8 +43,7 @@ NF = 64 # number of filter
class
Model
(
GANModelDesc
):
class
Model
(
GANModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
SHAPE
,
SHAPE
,
IN_CH
),
'input'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,
SHAPE
,
SHAPE
,
IN_CH
),
'input'
),
InputVar
(
tf
.
float32
,
(
None
,
SHAPE
,
SHAPE
,
OUT_CH
),
'output'
)]
InputVar
(
tf
.
float32
,
(
None
,
SHAPE
,
SHAPE
,
OUT_CH
),
'output'
)]
...
@@ -100,8 +99,8 @@ class Model(GANModelDesc):
...
@@ -100,8 +99,8 @@ class Model(GANModelDesc):
.
Conv2D
(
'convlast'
,
1
,
stride
=
1
,
padding
=
'VALID'
)())
.
Conv2D
(
'convlast'
,
1
,
stride
=
1
,
padding
=
'VALID'
)())
return
l
return
l
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
input
,
output
=
input
_var
s
input
,
output
=
inputs
input
,
output
=
input
/
128.0
-
1
,
output
/
128.0
-
1
input
,
output
=
input
/
128.0
-
1
,
output
/
128.0
-
1
with
argscope
([
Conv2D
,
Deconv2D
],
with
argscope
([
Conv2D
,
Deconv2D
],
...
...
examples/GAN/InfoGAN-mnist.py
View file @
14b3578a
...
@@ -32,7 +32,7 @@ class GaussianWithUniformSample(GaussianDistribution):
...
@@ -32,7 +32,7 @@ class GaussianWithUniformSample(GaussianDistribution):
class
Model
(
GANModelDesc
):
class
Model
(
GANModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
)]
return
[
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
)]
def
generator
(
self
,
z
):
def
generator
(
self
,
z
):
...
@@ -62,8 +62,8 @@ class Model(GANModelDesc):
...
@@ -62,8 +62,8 @@ class Model(GANModelDesc):
.
FullyConnected
(
'fce-out'
,
self
.
factors
.
param_dim
,
nl
=
tf
.
identity
)())
.
FullyConnected
(
'fce-out'
,
self
.
factors
.
param_dim
,
nl
=
tf
.
identity
)())
return
logits
,
encoder
return
logits
,
encoder
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
real_sample
=
input
_var
s
[
0
]
real_sample
=
inputs
[
0
]
real_sample
=
tf
.
expand_dims
(
real_sample
*
2.0
-
1
,
-
1
)
real_sample
=
tf
.
expand_dims
(
real_sample
*
2.0
-
1
,
-
1
)
# latent space is cat(10) x uni(1) x uni(1) x noise(NOISE_DIM)
# latent space is cat(10) x uni(1) x uni(1) x noise(NOISE_DIM)
...
...
examples/HED/hed.py
View file @
14b3578a
...
@@ -17,13 +17,12 @@ from tensorpack.tfutils.summary import *
...
@@ -17,13 +17,12 @@ from tensorpack.tfutils.summary import *
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
None
,
None
,
3
],
'image'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
None
,
None
,
3
],
'image'
),
InputVar
(
tf
.
int32
,
[
None
,
None
,
None
],
'edgemap'
)]
InputVar
(
tf
.
int32
,
[
None
,
None
,
None
],
'edgemap'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
edgemap
=
input
_var
s
image
,
edgemap
=
inputs
image
=
image
-
tf
.
constant
([
104
,
116
,
122
],
dtype
=
'float32'
)
image
=
image
-
tf
.
constant
([
104
,
116
,
122
],
dtype
=
'float32'
)
edgemap
=
tf
.
expand_dims
(
edgemap
,
3
,
name
=
'edgemap4d'
)
edgemap
=
tf
.
expand_dims
(
edgemap
,
3
,
name
=
'edgemap4d'
)
...
...
examples/Inception/inception-bn.py
View file @
14b3578a
...
@@ -29,12 +29,12 @@ Learning rate may need a different schedule for different number of GPUs (becaus
...
@@ -29,12 +29,12 @@ Learning rate may need a different schedule for different number of GPUs (becaus
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
128.0
image
=
image
/
128.0
def
inception
(
name
,
x
,
nr1x1
,
nr3x3r
,
nr3x3
,
nr233r
,
nr233
,
nrpool
,
pooltype
):
def
inception
(
name
,
x
,
nr1x1
,
nr3x3r
,
nr3x3
,
nr233r
,
nr233
,
nrpool
,
pooltype
):
...
...
examples/Inception/inceptionv3.py
View file @
14b3578a
...
@@ -35,12 +35,12 @@ INPUT_SHAPE = 299
...
@@ -35,12 +35,12 @@ INPUT_SHAPE = 299
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
255.0
# ?
image
=
image
/
255.0
# ?
def
proj_kk
(
l
,
k
,
ch_r
,
ch
,
stride
=
1
):
def
proj_kk
(
l
,
k
,
ch_r
,
ch
,
stride
=
1
):
...
...
examples/PennTreebank/PTB-LSTM.py
View file @
14b3578a
...
@@ -44,13 +44,13 @@ def get_PennTreeBank(data_dir=None):
...
@@ -44,13 +44,13 @@ def get_PennTreeBank(data_dir=None):
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
int32
,
(
None
,
SEQ_LEN
),
'input'
),
return
[
InputVar
(
tf
.
int32
,
(
None
,
SEQ_LEN
),
'input'
),
InputVar
(
tf
.
int32
,
(
None
,
SEQ_LEN
),
'nextinput'
)]
InputVar
(
tf
.
int32
,
(
None
,
SEQ_LEN
),
'nextinput'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
is_training
=
get_current_tower_context
()
.
is_training
is_training
=
get_current_tower_context
()
.
is_training
input
,
nextinput
=
input
_var
s
input
,
nextinput
=
inputs
initializer
=
tf
.
random_uniform_initializer
(
-
0.05
,
0.05
)
initializer
=
tf
.
random_uniform_initializer
(
-
0.05
,
0.05
)
cell
=
rnn
.
BasicLSTMCell
(
num_units
=
HIDDEN_SIZE
,
forget_bias
=
0.0
)
cell
=
rnn
.
BasicLSTMCell
(
num_units
=
HIDDEN_SIZE
,
forget_bias
=
0.0
)
...
...
examples/ResNet/cifar10-resnet.py
View file @
14b3578a
...
@@ -37,12 +37,12 @@ class Model(ModelDesc):
...
@@ -37,12 +37,12 @@ class Model(ModelDesc):
super
(
Model
,
self
)
.
__init__
()
super
(
Model
,
self
)
.
__init__
()
self
.
n
=
n
self
.
n
=
n
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
32
,
32
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
32
,
32
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
128.0
-
1
image
=
image
/
128.0
-
1
def
residual
(
name
,
l
,
increase_dim
=
False
,
first
=
False
):
def
residual
(
name
,
l
,
increase_dim
=
False
,
first
=
False
):
...
...
examples/ResNet/imagenet-resnet.py
View file @
14b3578a
...
@@ -28,12 +28,12 @@ DEPTH = None
...
@@ -28,12 +28,12 @@ DEPTH = None
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
def
shortcut
(
l
,
n_in
,
n_out
,
stride
):
def
shortcut
(
l
,
n_in
,
n_out
,
stride
):
if
n_in
!=
n_out
:
if
n_in
!=
n_out
:
...
...
examples/Saliency/saliency-maps.py
View file @
14b3578a
...
@@ -16,11 +16,11 @@ IMAGE_SIZE = 224
...
@@ -16,11 +16,11 @@ IMAGE_SIZE = 224
class
Model
(
tp
.
ModelDesc
):
class
Model
(
tp
.
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
tp
.
InputVar
(
tf
.
float32
,
(
IMAGE_SIZE
,
IMAGE_SIZE
,
3
),
'image'
)]
return
[
tp
.
InputVar
(
tf
.
float32
,
(
IMAGE_SIZE
,
IMAGE_SIZE
,
3
),
'image'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
orig_image
=
input
_var
s
[
0
]
orig_image
=
inputs
[
0
]
mean
=
tf
.
get_variable
(
'resnet_v1_50/mean_rgb'
,
shape
=
[
3
])
mean
=
tf
.
get_variable
(
'resnet_v1_50/mean_rgb'
,
shape
=
[
3
])
with
tp
.
symbolic_functions
.
guided_relu
():
with
tp
.
symbolic_functions
.
guided_relu
():
with
slim
.
arg_scope
(
resnet_v1
.
resnet_arg_scope
(
is_training
=
False
)):
with
slim
.
arg_scope
(
resnet_v1
.
resnet_arg_scope
(
is_training
=
False
)):
...
...
examples/SimilarityLearning/mnist-embeddings.py
View file @
14b3578a
...
@@ -61,20 +61,20 @@ class SiameseModel(EmbeddingModel):
...
@@ -61,20 +61,20 @@ class SiameseModel(EmbeddingModel):
ds
=
BatchData
(
ds
,
128
//
2
)
ds
=
BatchData
(
ds
,
128
//
2
)
return
ds
return
ds
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
),
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_y'
),
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_y'
),
InputVar
(
tf
.
int32
,
(
None
,),
'label'
)]
InputVar
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
# get inputs
# get inputs
x
,
y
,
label
=
input
_var
s
x
,
y
,
label
=
inputs
# embed them
# embed them
x
,
y
=
self
.
embed
([
x
,
y
])
x
,
y
=
self
.
embed
([
x
,
y
])
# tag the embedding of 'input' with name 'emb', just for inference later on
# tag the embedding of 'input' with name 'emb', just for inference later on
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
tf
.
identity
(
self
.
embed
(
input
_var
s
[
0
]),
name
=
"emb"
)
tf
.
identity
(
self
.
embed
(
inputs
[
0
]),
name
=
"emb"
)
# compute the actual loss
# compute the actual loss
cost
,
pos_dist
,
neg_dist
=
symbf
.
contrastive_loss
(
x
,
y
,
label
,
5.
,
extra
=
True
)
cost
,
pos_dist
,
neg_dist
=
symbf
.
contrastive_loss
(
x
,
y
,
label
,
5.
,
extra
=
True
)
...
@@ -85,12 +85,12 @@ class SiameseModel(EmbeddingModel):
...
@@ -85,12 +85,12 @@ class SiameseModel(EmbeddingModel):
class
CosineModel
(
SiameseModel
):
class
CosineModel
(
SiameseModel
):
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
x
,
y
,
label
=
input
_var
s
x
,
y
,
label
=
inputs
x
,
y
=
self
.
embed
([
x
,
y
])
x
,
y
=
self
.
embed
([
x
,
y
])
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
tf
.
identity
(
self
.
embed
(
input
_var
s
[
0
]),
name
=
"emb"
)
tf
.
identity
(
self
.
embed
(
inputs
[
0
]),
name
=
"emb"
)
cost
=
symbf
.
cosine_loss
(
x
,
y
,
label
)
cost
=
symbf
.
cosine_loss
(
x
,
y
,
label
)
self
.
cost
=
tf
.
identity
(
cost
,
name
=
"cost"
)
self
.
cost
=
tf
.
identity
(
cost
,
name
=
"cost"
)
...
@@ -104,7 +104,7 @@ class TripletModel(EmbeddingModel):
...
@@ -104,7 +104,7 @@ class TripletModel(EmbeddingModel):
ds
=
BatchData
(
ds
,
128
//
3
)
ds
=
BatchData
(
ds
,
128
//
3
)
return
ds
return
ds
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
),
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_p'
),
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_p'
),
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_n'
)]
InputVar
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_n'
)]
...
@@ -112,12 +112,12 @@ class TripletModel(EmbeddingModel):
...
@@ -112,12 +112,12 @@ class TripletModel(EmbeddingModel):
def
loss
(
self
,
a
,
p
,
n
):
def
loss
(
self
,
a
,
p
,
n
):
return
symbf
.
triplet_loss
(
a
,
p
,
n
,
5.
,
extra
=
True
)
return
symbf
.
triplet_loss
(
a
,
p
,
n
,
5.
,
extra
=
True
)
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
a
,
p
,
n
=
input
_var
s
a
,
p
,
n
=
inputs
a
,
p
,
n
=
self
.
embed
([
a
,
p
,
n
])
a
,
p
,
n
=
self
.
embed
([
a
,
p
,
n
])
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
tf
.
identity
(
self
.
embed
(
input
_var
s
[
0
]),
name
=
"emb"
)
tf
.
identity
(
self
.
embed
(
inputs
[
0
]),
name
=
"emb"
)
cost
,
pos_dist
,
neg_dist
=
self
.
loss
(
a
,
p
,
n
)
cost
,
pos_dist
,
neg_dist
=
self
.
loss
(
a
,
p
,
n
)
self
.
cost
=
tf
.
identity
(
cost
,
name
=
"cost"
)
self
.
cost
=
tf
.
identity
(
cost
,
name
=
"cost"
)
...
...
examples/SpatialTransformer/mnist-addition.py
View file @
14b3578a
...
@@ -18,17 +18,16 @@ HALF_DIFF = (IMAGE_SIZE - WARP_TARGET_SIZE) // 2
...
@@ -18,17 +18,16 @@ HALF_DIFF = (IMAGE_SIZE - WARP_TARGET_SIZE) // 2
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
,
2
),
'input'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
,
2
),
'input'
),
InputVar
(
tf
.
int32
,
(
None
,),
'label'
)]
InputVar
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
xys
=
np
.
array
([(
y
,
x
,
1
)
for
y
in
range
(
WARP_TARGET_SIZE
)
xys
=
np
.
array
([(
y
,
x
,
1
)
for
y
in
range
(
WARP_TARGET_SIZE
)
for
x
in
range
(
WARP_TARGET_SIZE
)],
dtype
=
'float32'
)
for
x
in
range
(
WARP_TARGET_SIZE
)],
dtype
=
'float32'
)
xys
=
tf
.
constant
(
xys
,
dtype
=
tf
.
float32
,
name
=
'xys'
)
# p x 3
xys
=
tf
.
constant
(
xys
,
dtype
=
tf
.
float32
,
name
=
'xys'
)
# p x 3
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
255.0
-
0.5
# bhw2
image
=
image
/
255.0
-
0.5
# bhw2
...
...
examples/cifar-convnet.py
View file @
14b3578a
...
@@ -24,18 +24,17 @@ Not a good model for Cifar100, just for demonstration.
...
@@ -24,18 +24,17 @@ Not a good model for Cifar100, just for demonstration.
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
__init__
(
self
,
cifar_classnum
):
def
__init__
(
self
,
cifar_classnum
):
super
(
Model
,
self
)
.
__init__
()
super
(
Model
,
self
)
.
__init__
()
self
.
cifar_classnum
=
cifar_classnum
self
.
cifar_classnum
=
cifar_classnum
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
30
,
30
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
30
,
30
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)
InputVar
(
tf
.
int32
,
[
None
],
'label'
)
]
]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
is_training
=
get_current_tower_context
()
.
is_training
is_training
=
get_current_tower_context
()
.
is_training
keep_prob
=
tf
.
constant
(
0.5
if
is_training
else
1.0
)
keep_prob
=
tf
.
constant
(
0.5
if
is_training
else
1.0
)
...
...
examples/load-alexnet.py
View file @
14b3578a
...
@@ -24,7 +24,7 @@ Usage:
...
@@ -24,7 +24,7 @@ Usage:
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
227
,
227
,
3
),
'input'
)]
return
[
InputVar
(
tf
.
float32
,
(
None
,
227
,
227
,
3
),
'input'
)]
def
_build_graph
(
self
,
inputs
):
def
_build_graph
(
self
,
inputs
):
...
...
examples/load-vgg16.py
View file @
14b3578a
...
@@ -24,8 +24,7 @@ Usage:
...
@@ -24,8 +24,7 @@ Usage:
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_inputs
(
self
):
def
_get_input_vars
(
self
):
return
[
InputVar
(
tf
.
float32
,
(
None
,
224
,
224
,
3
),
'input'
)]
return
[
InputVar
(
tf
.
float32
,
(
None
,
224
,
224
,
3
),
'input'
)]
def
_build_graph
(
self
,
inputs
):
def
_build_graph
(
self
,
inputs
):
...
...
examples/mnist-convnet.py
View file @
14b3578a
...
@@ -23,18 +23,18 @@ USE_SLIM = False
...
@@ -23,18 +23,18 @@ USE_SLIM = False
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
"""Define all the input variables (with type, shape, name) that'll be
"""Define all the input variables (with type, shape, name) that'll be
fed into the graph to produce a cost. """
fed into the graph to produce a cost. """
return
[
InputVar
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
),
'input'
),
return
[
InputVar
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
),
'input'
),
InputVar
(
tf
.
int32
,
(
None
,),
'label'
)]
InputVar
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
"""This function should build the model which takes the input variables
"""This function should build the model which takes the input variables
and define self.cost at the end"""
and define self.cost at the end"""
# input
_var
s contains a list of input variables defined above
# inputs contains a list of input variables defined above
image
,
label
=
input
_var
s
image
,
label
=
inputs
# In tensorflow, inputs to convolution function are assumed to be
# In tensorflow, inputs to convolution function are assumed to be
# NHWC. Add a single channel here.
# NHWC. Add a single channel here.
image
=
tf
.
expand_dims
(
image
,
3
)
image
=
tf
.
expand_dims
(
image
,
3
)
...
...
examples/svhn-digit-convnet.py
View file @
14b3578a
...
@@ -23,12 +23,12 @@ Speed is about 43 it/s on TitanX.
...
@@ -23,12 +23,12 @@ Speed is about 43 it/s on TitanX.
class
Model
(
ModelDesc
):
class
Model
(
ModelDesc
):
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
return
[
InputVar
(
tf
.
float32
,
[
None
,
40
,
40
,
3
],
'input'
),
return
[
InputVar
(
tf
.
float32
,
[
None
,
40
,
40
,
3
],
'input'
),
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
InputVar
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
input
_var
s
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
input
_var
s
image
,
label
=
inputs
image
=
image
/
128.0
-
1
image
=
image
/
128.0
-
1
...
...
tensorpack/models/model_desc.py
View file @
14b3578a
...
@@ -87,11 +87,14 @@ class ModelDesc(object):
...
@@ -87,11 +87,14 @@ class ModelDesc(object):
"""
"""
return
self
.
_get_input_vars
()
return
self
.
_get_input_vars
()
@
abstractmethod
def
_get_input_vars
(
self
):
# keep backward compatibility
def
_get_input_vars
(
self
):
"""
"""
:returns: a list of InputVar
:returns: a list of InputVar
"""
"""
return
self
.
_get_inputs
()
def
_get_inputs
(
self
):
# this is a better name than _get_input_vars
raise
NotImplementedError
()
def
build_graph
(
self
,
model_inputs
):
def
build_graph
(
self
,
model_inputs
):
"""
"""
...
@@ -171,7 +174,7 @@ class ModelFromMetaGraph(ModelDesc):
...
@@ -171,7 +174,7 @@ class ModelFromMetaGraph(ModelDesc):
assert
k
in
all_coll
,
\
assert
k
in
all_coll
,
\
"Collection {} not found in metagraph!"
.
format
(
k
)
"Collection {} not found in metagraph!"
.
format
(
k
)
def
_get_input
_var
s
(
self
):
def
_get_inputs
(
self
):
col
=
tf
.
get_collection
(
INPUT_VARS_KEY
)
col
=
tf
.
get_collection
(
INPUT_VARS_KEY
)
col
=
[
InputVar
.
loads
(
v
)
for
v
in
col
]
col
=
[
InputVar
.
loads
(
v
)
for
v
in
col
]
return
col
return
col
...
...
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