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
e02c7995
You need to sign in or sign up before continuing.
Commit
e02c7995
authored
Mar 20, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
_build_graph(inputs) -> build_graph(*inputs) (#318)
parent
95bd4af5
Changes
36
Hide whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
46 additions
and
90 deletions
+46
-90
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
+1
-2
examples/Char-RNN/char-rnn.py
examples/Char-RNN/char-rnn.py
+1
-3
examples/DeepQNetwork/DQNModel.py
examples/DeepQNetwork/DQNModel.py
+1
-2
examples/DisturbLabel/mnist-disturb.py
examples/DisturbLabel/mnist-disturb.py
+1
-2
examples/DoReFa-Net/alexnet-dorefa.py
examples/DoReFa-Net/alexnet-dorefa.py
+1
-2
examples/DoReFa-Net/resnet-dorefa.py
examples/DoReFa-Net/resnet-dorefa.py
+1
-2
examples/DoReFa-Net/svhn-digit-dorefa.py
examples/DoReFa-Net/svhn-digit-dorefa.py
+1
-2
examples/DynamicFilterNetwork/steering-filter.py
examples/DynamicFilterNetwork/steering-filter.py
+1
-2
examples/FasterRCNN/train.py
examples/FasterRCNN/train.py
+1
-1
examples/GAN/BEGAN.py
examples/GAN/BEGAN.py
+1
-2
examples/GAN/ConditionalGAN-mnist.py
examples/GAN/ConditionalGAN-mnist.py
+1
-2
examples/GAN/CycleGAN.py
examples/GAN/CycleGAN.py
+1
-2
examples/GAN/DCGAN.py
examples/GAN/DCGAN.py
+1
-2
examples/GAN/DiscoGAN-CelebA.py
examples/GAN/DiscoGAN-CelebA.py
+1
-2
examples/GAN/GAN.py
examples/GAN/GAN.py
+1
-1
examples/GAN/Image2Image.py
examples/GAN/Image2Image.py
+1
-2
examples/GAN/Improved-WGAN.py
examples/GAN/Improved-WGAN.py
+1
-2
examples/GAN/InfoGAN-mnist.py
examples/GAN/InfoGAN-mnist.py
+1
-2
examples/HED/hed.py
examples/HED/hed.py
+1
-2
examples/ImageNetModels/imagenet_utils.py
examples/ImageNetModels/imagenet_utils.py
+1
-2
examples/ImageNetModels/inception-bn.py
examples/ImageNetModels/inception-bn.py
+1
-2
examples/PennTreebank/PTB-LSTM.py
examples/PennTreebank/PTB-LSTM.py
+1
-2
examples/ResNet/cifar10-preact18-mixup.py
examples/ResNet/cifar10-preact18-mixup.py
+1
-2
examples/ResNet/cifar10-resnet.py
examples/ResNet/cifar10-resnet.py
+1
-2
examples/ResNet/load-resnet.py
examples/ResNet/load-resnet.py
+1
-2
examples/Saliency/CAM-resnet.py
examples/Saliency/CAM-resnet.py
+1
-2
examples/Saliency/saliency-maps.py
examples/Saliency/saliency-maps.py
+1
-2
examples/SimilarityLearning/mnist-embeddings.py
examples/SimilarityLearning/mnist-embeddings.py
+4
-10
examples/SpatialTransformer/mnist-addition.py
examples/SpatialTransformer/mnist-addition.py
+1
-3
examples/SuperResolution/enet-pat.py
examples/SuperResolution/enet-pat.py
+2
-2
examples/basics/cifar-convnet.py
examples/basics/cifar-convnet.py
+1
-2
examples/basics/mnist-tflayers.py
examples/basics/mnist-tflayers.py
+1
-4
examples/basics/mnist-visualizations.py
examples/basics/mnist-visualizations.py
+2
-4
examples/basics/svhn-digit-convnet.py
examples/basics/svhn-digit-convnet.py
+1
-3
examples/boilerplate.py
examples/boilerplate.py
+6
-7
No files found.
examples/A3C-Gym/train-atari.py
View file @
e02c7995
...
...
@@ -94,8 +94,7 @@ class Model(ModelDesc):
value
=
FullyConnected
(
'fc-v'
,
l
,
1
)
return
logits
,
value
def
_build_graph
(
self
,
inputs
):
state
,
action
,
futurereward
,
action_prob
=
inputs
def
build_graph
(
self
,
state
,
action
,
futurereward
,
action_prob
):
logits
,
value
=
self
.
_get_NN_prediction
(
state
)
value
=
tf
.
squeeze
(
value
,
[
1
],
name
=
'pred_value'
)
# (B,)
policy
=
tf
.
nn
.
softmax
(
logits
,
name
=
'policy'
)
...
...
examples/CTC-TIMIT/train-timit.py
View file @
e02c7995
...
...
@@ -33,8 +33,7 @@ class Model(ModelDesc):
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'seqlen'
),
# b
]
def
_build_graph
(
self
,
inputs
):
feat
,
labelidx
,
labelvalue
,
labelshape
,
seqlen
=
inputs
def
build_graph
(
self
,
feat
,
labelidx
,
labelvalue
,
labelshape
,
seqlen
):
label
=
tf
.
SparseTensor
(
labelidx
,
labelvalue
,
labelshape
)
cell
=
rnn
.
MultiRNNCell
([
rnn
.
LSTMBlockCell
(
num_units
=
HIDDEN
)
for
_
in
range
(
NLAYER
)])
...
...
examples/Char-RNN/char-rnn.py
View file @
e02c7995
...
...
@@ -74,9 +74,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
int32
,
(
None
,
param
.
seq_len
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,
param
.
seq_len
),
'nextinput'
)]
def
_build_graph
(
self
,
inputs
):
input
,
nextinput
=
inputs
def
build_graph
(
self
,
input
,
nextinput
):
cell
=
rnn
.
MultiRNNCell
([
rnn
.
LSTMBlockCell
(
num_units
=
param
.
rnn_size
)
for
_
in
range
(
param
.
num_rnn_layer
)])
...
...
examples/DeepQNetwork/DQNModel.py
View file @
e02c7995
...
...
@@ -43,8 +43,7 @@ class Model(ModelDesc):
def
get_DQN_prediction
(
self
,
image
):
return
self
.
_get_DQN_prediction
(
image
)
def
_build_graph
(
self
,
inputs
):
comb_state
,
action
,
reward
,
isOver
=
inputs
def
build_graph
(
self
,
comb_state
,
action
,
reward
,
isOver
):
comb_state
=
tf
.
cast
(
comb_state
,
tf
.
float32
)
state
=
tf
.
slice
(
comb_state
,
[
0
,
0
,
0
,
0
],
[
-
1
,
-
1
,
-
1
,
self
.
channel
],
name
=
'state'
)
self
.
predict_value
=
self
.
get_DQN_prediction
(
state
)
...
...
examples/DisturbLabel/mnist-disturb.py
View file @
e02c7995
...
...
@@ -29,8 +29,7 @@ IMAGE_SIZE = 28
class
Model
(
mnist_example
.
Model
):
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
tf
.
expand_dims
(
image
,
3
)
logits
=
(
LinearWrap
(
image
)
# the starting brace is oactivationy for line-breaking
...
...
examples/DoReFa-Net/alexnet-dorefa.py
View file @
e02c7995
...
...
@@ -81,8 +81,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
image
/
255.0
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
...
...
examples/DoReFa-Net/resnet-dorefa.py
View file @
e02c7995
...
...
@@ -36,8 +36,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
image
/
256.0
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
...
...
examples/DoReFa-Net/svhn-digit-dorefa.py
View file @
e02c7995
...
...
@@ -47,8 +47,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
40
,
40
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
is_training
=
get_current_tower_context
()
.
is_training
fw
,
fa
,
fg
=
get_dorefa
(
BITW
,
BITA
,
BITG
)
...
...
examples/DynamicFilterNetwork/steering-filter.py
View file @
e02c7995
...
...
@@ -120,9 +120,8 @@ class Model(ModelDesc):
logger
.
info
(
'Parameter net output: {}'
.
format
(
pred_filter
.
get_shape
()
.
as_list
()))
return
pred_filter
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
theta
,
image
,
gt_image
,
gt_filter
):
kernel_size
=
9
theta
,
image
,
gt_image
,
gt_filter
=
inputs
image
=
image
gt_image
=
gt_image
...
...
examples/FasterRCNN/train.py
View file @
e02c7995
...
...
@@ -90,7 +90,7 @@ class Model(ModelDesc):
-
1
,
-
1
]),
name
=
'fm_anchors'
)
return
fm_anchors
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
*
inputs
):
is_training
=
get_current_tower_context
()
.
is_training
if
config
.
MODE_MASK
:
image
,
anchor_labels
,
anchor_boxes
,
gt_boxes
,
gt_labels
,
gt_masks
=
inputs
...
...
examples/GAN/BEGAN.py
View file @
e02c7995
...
...
@@ -73,8 +73,7 @@ class Model(GANModelDesc):
.
FullyConnected
(
'fc'
,
NH
)())
return
l
def
_build_graph
(
self
,
inputs
):
image_pos
=
inputs
[
0
]
def
build_graph
(
self
,
image_pos
):
image_pos
=
image_pos
/
128.0
-
1
z
=
tf
.
random_uniform
([
args
.
batch
,
args
.
z_dim
],
minval
=-
1
,
maxval
=
1
,
name
=
'z_train'
)
...
...
examples/GAN/ConditionalGAN-mnist.py
View file @
e02c7995
...
...
@@ -84,8 +84,7 @@ class Model(GANModelDesc):
.
FullyConnected
(
'fct'
,
1
,
activation
=
tf
.
identity
)())
return
l
def
_build_graph
(
self
,
inputs
):
image_pos
,
y
=
inputs
def
build_graph
(
self
,
image_pos
,
y
):
image_pos
=
tf
.
expand_dims
(
image_pos
*
2.0
-
1
,
-
1
)
y
=
tf
.
one_hot
(
y
,
10
,
name
=
'label_onehot'
)
...
...
examples/GAN/CycleGAN.py
View file @
e02c7995
...
...
@@ -85,8 +85,7 @@ class Model(GANModelDesc):
.
Conv2D
(
'conv4'
,
1
,
strides
=
1
,
activation
=
tf
.
identity
,
use_bias
=
True
)())
return
l
def
_build_graph
(
self
,
inputs
):
A
,
B
=
inputs
def
build_graph
(
self
,
A
,
B
):
with
tf
.
name_scope
(
'preprocess'
):
A
=
tf
.
transpose
(
A
/
128.0
-
1.0
,
[
0
,
3
,
1
,
2
])
B
=
tf
.
transpose
(
B
/
128.0
-
1.0
,
[
0
,
3
,
1
,
2
])
...
...
examples/GAN/DCGAN.py
View file @
e02c7995
...
...
@@ -76,8 +76,7 @@ class Model(GANModelDesc):
.
FullyConnected
(
'fct'
,
1
)())
return
l
def
_build_graph
(
self
,
inputs
):
image_pos
=
inputs
[
0
]
def
build_graph
(
self
,
image_pos
):
image_pos
=
image_pos
/
128.0
-
1
z
=
tf
.
random_uniform
([
self
.
batch
,
self
.
zdim
],
-
1
,
1
,
name
=
'z_train'
)
...
...
examples/GAN/DiscoGAN-CelebA.py
View file @
e02c7995
...
...
@@ -78,8 +78,7 @@ class Model(GANModelDesc):
add_moving_summary
(
ret
)
return
ret
def
_build_graph
(
self
,
inputs
):
A
,
B
=
inputs
def
build_graph
(
self
,
A
,
B
):
A
=
tf
.
transpose
(
A
/
255.0
,
[
0
,
3
,
1
,
2
])
B
=
tf
.
transpose
(
B
/
255.0
,
[
0
,
3
,
1
,
2
])
...
...
examples/GAN/GAN.py
View file @
e02c7995
...
...
@@ -61,7 +61,7 @@ class GANModelDesc(ModelDescBase):
add_moving_summary
(
self
.
g_loss
,
self
.
d_loss
,
d_accuracy
,
g_accuracy
)
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
*
inputs
):
"""
Have to build one tower and set the following attributes:
g_loss, d_loss, g_vars, d_vars.
...
...
examples/GAN/Image2Image.py
View file @
e02c7995
...
...
@@ -117,8 +117,7 @@ class Model(GANModelDesc):
.
Conv2D
(
'convlast'
,
1
,
strides
=
1
,
padding
=
'VALID'
,
activation
=
tf
.
identity
)())
return
l
def
_build_graph
(
self
,
inputs
):
input
,
output
=
inputs
def
build_graph
(
self
,
input
,
output
):
input
,
output
=
input
/
128.0
-
1
,
output
/
128.0
-
1
with
argscope
([
Conv2D
,
Conv2DTranspose
],
kernel_initializer
=
tf
.
truncated_normal_initializer
(
stddev
=
0.02
)):
...
...
examples/GAN/Improved-WGAN.py
View file @
e02c7995
...
...
@@ -41,8 +41,7 @@ class Model(DCGAN.Model):
.
FullyConnected
(
'fct'
,
1
,
activation
=
tf
.
identity
)())
return
tf
.
reshape
(
l
,
[
-
1
])
def
_build_graph
(
self
,
inputs
):
image_pos
=
inputs
[
0
]
def
build_graph
(
self
,
image_pos
):
image_pos
=
image_pos
/
128.0
-
1
z
=
tf
.
random_normal
([
self
.
batch
,
self
.
zdim
],
name
=
'z_train'
)
...
...
examples/GAN/InfoGAN-mnist.py
View file @
e02c7995
...
...
@@ -138,8 +138,7 @@ class Model(GANModelDesc):
.
FullyConnected
(
'fce-out'
,
DIST_PARAM_DIM
)())
return
logits
,
encoder
def
_build_graph
(
self
,
inputs
):
real_sample
=
inputs
[
0
]
def
build_graph
(
self
,
real_sample
):
real_sample
=
tf
.
expand_dims
(
real_sample
,
-
1
)
# sample the latent code:
...
...
examples/HED/hed.py
View file @
e02c7995
...
...
@@ -48,8 +48,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
None
,
None
,
3
],
'image'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
,
None
,
None
],
'edgemap'
)]
def
_build_graph
(
self
,
inputs
):
image
,
edgemap
=
inputs
def
build_graph
(
self
,
image
,
edgemap
):
image
=
image
-
tf
.
constant
([
104
,
116
,
122
],
dtype
=
'float32'
)
edgemap
=
tf
.
expand_dims
(
edgemap
,
3
,
name
=
'edgemap4d'
)
...
...
examples/ImageNetModels/imagenet_utils.py
View file @
e02c7995
...
...
@@ -152,8 +152,7 @@ class ImageNetModel(ModelDesc):
return
[
tf
.
placeholder
(
self
.
image_dtype
,
[
None
,
self
.
image_shape
,
self
.
image_shape
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
ImageNetModel
.
image_preprocess
(
image
,
bgr
=
True
)
if
self
.
data_format
==
'NCHW'
:
image
=
tf
.
transpose
(
image
,
[
0
,
3
,
1
,
2
])
...
...
examples/ImageNetModels/inception-bn.py
View file @
e02c7995
...
...
@@ -28,8 +28,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
image
/
128.0
def
inception
(
name
,
x
,
nr1x1
,
nr3x3r
,
nr3x3
,
nr233r
,
nr233
,
nrpool
,
pooltype
):
...
...
examples/PennTreebank/PTB-LSTM.py
View file @
e02c7995
...
...
@@ -50,9 +50,8 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
int32
,
(
None
,
SEQ_LEN
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,
SEQ_LEN
),
'nextinput'
)]
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
input
,
nextinput
):
is_training
=
get_current_tower_context
()
.
is_training
input
,
nextinput
=
inputs
initializer
=
tf
.
random_uniform_initializer
(
-
0.05
,
0.05
)
def
get_basic_cell
():
...
...
examples/ResNet/cifar10-preact18-mixup.py
View file @
e02c7995
...
...
@@ -43,9 +43,8 @@ class ResNet_Cifar(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
32
,
32
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
float32
,
[
None
,
CLASS_NUM
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
image
,
label
):
assert
tf
.
test
.
is_gpu_available
()
image
,
label
=
inputs
MEAN_IMAGE
=
tf
.
constant
([
0.4914
,
0.4822
,
0.4465
],
dtype
=
tf
.
float32
)
STD_IMAGE
=
tf
.
constant
([
0.2023
,
0.1994
,
0.2010
],
dtype
=
tf
.
float32
)
...
...
examples/ResNet/cifar10-resnet.py
View file @
e02c7995
...
...
@@ -44,8 +44,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
32
,
32
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
image
/
128.0
assert
tf
.
test
.
is_gpu_available
()
image
=
tf
.
transpose
(
image
,
[
0
,
3
,
1
,
2
])
...
...
examples/ResNet/load-resnet.py
View file @
e02c7995
...
...
@@ -32,8 +32,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
224
,
224
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
blocks
=
CFG
[
DEPTH
]
bottleneck
=
functools
.
partial
(
resnet_bottleneck
,
stride_first
=
True
)
...
...
examples/Saliency/CAM-resnet.py
View file @
e02c7995
...
...
@@ -35,8 +35,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
uint8
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
image_preprocess
(
image
,
bgr
=
True
)
image
=
tf
.
transpose
(
image
,
[
0
,
3
,
1
,
2
])
...
...
examples/Saliency/saliency-maps.py
View file @
e02c7995
...
...
@@ -57,8 +57,7 @@ class Model(tp.ModelDescBase):
def
inputs
(
self
):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
IMAGE_SIZE
,
IMAGE_SIZE
,
3
),
'image'
)]
def
_build_graph
(
self
,
inputs
):
orig_image
=
inputs
[
0
]
def
build_graph
(
self
,
orig_image
):
mean
=
tf
.
get_variable
(
'resnet_v1_50/mean_rgb'
,
shape
=
[
3
])
with
guided_relu
():
with
slim
.
arg_scope
(
resnet_v1
.
resnet_arg_scope
(
is_training
=
False
)):
...
...
examples/SimilarityLearning/mnist-embeddings.py
View file @
e02c7995
...
...
@@ -241,9 +241,7 @@ class SiameseModel(EmbeddingModel):
tf
.
placeholder
(
tf
.
float32
,
(
None
,
28
,
28
),
'input_y'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
inputs
):
# get inputs
x
,
y
,
label
=
inputs
def
build_graph
(
self
,
x
,
y
,
label
):
# embed them
x
,
y
=
self
.
embed
([
x
,
y
])
...
...
@@ -261,8 +259,7 @@ class SiameseModel(EmbeddingModel):
class
CosineModel
(
SiameseModel
):
def
_build_graph
(
self
,
inputs
):
x
,
y
,
label
=
inputs
def
build_graph
(
self
,
x
,
y
,
label
):
x
,
y
=
self
.
embed
([
x
,
y
])
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
...
...
@@ -289,8 +286,7 @@ class TripletModel(EmbeddingModel):
def
loss
(
self
,
a
,
p
,
n
):
return
triplet_loss
(
a
,
p
,
n
,
5.
,
extra
=
True
,
scope
=
"loss"
)
def
_build_graph
(
self
,
inputs
):
a
,
p
,
n
=
inputs
def
build_graph
(
self
,
a
,
p
,
n
):
a
,
p
,
n
=
self
.
embed
([
a
,
p
,
n
])
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
reuse
=
True
):
...
...
@@ -319,9 +315,7 @@ class CenterModel(EmbeddingModel):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
28
,
28
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
inputs
):
# get inputs
x
,
label
=
inputs
def
build_graph
(
self
,
x
,
label
):
# embed them
x
=
self
.
embed
(
x
)
...
...
examples/SpatialTransformer/mnist-addition.py
View file @
e02c7995
...
...
@@ -24,13 +24,11 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
,
2
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
image
,
label
):
xys
=
np
.
array
([(
y
,
x
,
1
)
for
y
in
range
(
WARP_TARGET_SIZE
)
for
x
in
range
(
WARP_TARGET_SIZE
)],
dtype
=
'float32'
)
xys
=
tf
.
constant
(
xys
,
dtype
=
tf
.
float32
,
name
=
'xys'
)
# p x 3
image
,
label
=
inputs
image
=
image
/
255.0
-
0.5
# bhw2
def
get_stn
(
image
):
...
...
examples/SuperResolution/enet-pat.py
View file @
e02c7995
...
...
@@ -52,9 +52,9 @@ class Model(GANModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
self
.
height
*
1
,
self
.
width
*
1
,
CHANNELS
),
'Ilr'
),
tf
.
placeholder
(
tf
.
float32
,
(
None
,
self
.
height
*
4
,
self
.
width
*
4
,
CHANNELS
),
'Ihr'
)]
def
_build_graph
(
self
,
inputs
):
def
build_graph
(
self
,
Ilr
,
Ihr
):
Ilr
,
Ihr
=
Ilr
/
255.0
,
Ihr
/
255.0
ctx
=
get_current_tower_context
()
Ilr
,
Ihr
=
inputs
[
0
]
/
255.0
,
inputs
[
1
]
/
255.0
Ibicubic
=
tf
.
image
.
resize_bicubic
(
Ilr
,
[
4
*
self
.
height
,
4
*
self
.
width
],
align_corners
=
True
,
name
=
'bicubic_baseline'
)
# (0,1)
...
...
examples/basics/cifar-convnet.py
View file @
e02c7995
...
...
@@ -30,8 +30,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
30
,
30
,
3
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
is_training
=
get_current_tower_context
()
.
is_training
keep_prob
=
tf
.
constant
(
0.5
if
is_training
else
1.0
)
...
...
examples/basics/mnist-tflayers.py
View file @
e02c7995
...
...
@@ -31,10 +31,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
inputs
):
# inputs contains a list of input variables defined above
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
# In tensorflow, inputs to convolution function are assumed to be
# NHWC. Add a single channel here.
image
=
tf
.
expand_dims
(
image
,
3
)
...
...
examples/basics/mnist-visualizations.py
View file @
e02c7995
...
...
@@ -72,9 +72,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
IMAGE_SIZE
,
IMAGE_SIZE
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
tf
.
expand_dims
(
image
*
2
-
1
,
3
)
with
argscope
(
Conv2D
,
kernel_shape
=
3
,
nl
=
tf
.
nn
.
relu
,
out_channel
=
32
):
...
...
@@ -103,7 +101,7 @@ class Model(ModelDesc):
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
accuracy
=
tf
.
reduce_mean
(
tf
.
to_float
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
)),
name
=
'accuracy'
)
tf
.
reduce_mean
(
tf
.
to_float
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
)),
name
=
'accuracy'
)
wd_cost
=
tf
.
multiply
(
1e-5
,
regularize_cost
(
'fc.*/W'
,
tf
.
nn
.
l2_loss
),
...
...
examples/basics/svhn-digit-convnet.py
View file @
e02c7995
...
...
@@ -26,9 +26,7 @@ class Model(ModelDesc):
return
[
tf
.
placeholder
(
tf
.
float32
,
[
None
,
40
,
40
,
3
],
'input'
),
tf
.
placeholder
(
tf
.
int32
,
[
None
],
'label'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
def
build_graph
(
self
,
image
,
label
):
image
=
image
/
128.0
-
1
with
argscope
(
Conv2D
,
activation
=
BNReLU
,
use_bias
=
False
):
...
...
examples/boilerplate.py
View file @
e02c7995
...
...
@@ -20,15 +20,14 @@ CHANNELS = 3
class
Model
(
ModelDesc
):
def
inputs
(
self
):
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
SHAPE
,
SHAPE
,
CHANNELS
),
'input'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'
label
'
)]
return
[
tf
.
placeholder
(
tf
.
float32
,
(
None
,
SHAPE
,
SHAPE
,
CHANNELS
),
'input
1
'
),
tf
.
placeholder
(
tf
.
int32
,
(
None
,),
'
input2
'
)]
def
_build_graph
(
self
,
inputs
):
image
,
label
=
inputs
image
=
image
*
2
-
1
def
build_graph
(
self
,
input1
,
input2
):
self
.
cost
=
tf
.
identity
(
0.
,
name
=
'total_costs'
)
summary
.
add_moving_summary
(
self
.
cost
)
cost
=
tf
.
identity
(
input1
-
input2
,
name
=
'total_costs'
)
summary
.
add_moving_summary
(
cost
)
return
cost
def
_get_optimizer
(
self
):
lr
=
tf
.
get_variable
(
'learning_rate'
,
initializer
=
5e-3
,
trainable
=
False
)
...
...
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