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
79dbd183
You need to sign in or sign up before continuing.
Commit
79dbd183
authored
Nov 19, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name change
parent
1908fbe7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
28 deletions
+48
-28
README.md
README.md
+2
-2
examples/GAN/DCGAN-CelebA.py
examples/GAN/DCGAN-CelebA.py
+7
-5
examples/HED/hed.py
examples/HED/hed.py
+1
-1
examples/Inception/inception-bn.py
examples/Inception/inception-bn.py
+1
-0
tensorpack/models/regularize.py
tensorpack/models/regularize.py
+2
-2
tensorpack/tfutils/symbolic_functions.py
tensorpack/tfutils/symbolic_functions.py
+21
-17
tensorpack/utils/viz.py
tensorpack/utils/viz.py
+14
-1
No files found.
README.md
View file @
79dbd183
...
@@ -12,8 +12,8 @@ You can actually train them and reproduce the performance... not just to see how
...
@@ -12,8 +12,8 @@ You can actually train them and reproduce the performance... not just to see how
+
[
Fully-convolutional Network for Holistically-Nested Edge Detection
](
examples/HED
)
+
[
Fully-convolutional Network for Holistically-Nested Edge Detection
](
examples/HED
)
+
[
Spatial Transformer Networks on MNIST addition
](
examples/SpatialTransformer
)
+
[
Spatial Transformer Networks on MNIST addition
](
examples/SpatialTransformer
)
+
[
Generative Adversarial Networks
](
examples/GAN
)
+
[
Generative Adversarial Networks
](
examples/GAN
)
+
[
D
ouble DQN plays
Atari games
](
examples/Atari2600
)
+
[
D
QN variants on
Atari games
](
examples/Atari2600
)
+
[
Asynchronous Advantage Actor-Critic(A3C) with demos on OpenAI Gym
Atari games
](
examples/OpenAIGym
)
+
[
Asynchronous Advantage Actor-Critic(A3C) with demos on OpenAI Gym
](
examples/OpenAIGym
)
+
[
char-rnn language model
](
examples/char-rnn
)
+
[
char-rnn language model
](
examples/char-rnn
)
## Features:
## Features:
...
...
examples/GAN/
c
elebA.py
→
examples/GAN/
DCGAN-C
elebA.py
View file @
79dbd183
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File:
c
elebA.py
# File:
DCGAN-C
elebA.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import
numpy
as
np
import
numpy
as
np
...
@@ -68,8 +68,9 @@ class Model(ModelDesc):
...
@@ -68,8 +68,9 @@ class Model(ModelDesc):
def
_build_graph
(
self
,
input_vars
):
def
_build_graph
(
self
,
input_vars
):
image_pos
=
input_vars
[
0
]
image_pos
=
input_vars
[
0
]
image_pos
=
image_pos
/
128.0
-
1
image_pos
=
image_pos
/
128.0
-
1
z
=
tf
.
random_uniform
(
tf
.
pack
([
tf
.
shape
(
image_pos
)[
0
],
100
]),
-
1
,
1
,
name
=
'z'
)
z
.
set_shape
([
None
,
100
])
# issue#5680
z
=
tf
.
random_uniform
([
BATCH
,
100
],
-
1
,
1
,
name
=
'z_train'
)
z
=
tf
.
placeholder_with_default
(
z
,
[
None
,
100
],
name
=
'z'
)
with
argscope
([
Conv2D
,
Deconv2D
,
FullyConnected
],
with
argscope
([
Conv2D
,
Deconv2D
,
FullyConnected
],
W_init
=
tf
.
truncated_normal_initializer
(
stddev
=
0.02
)):
W_init
=
tf
.
truncated_normal_initializer
(
stddev
=
0.02
)):
...
@@ -110,7 +111,7 @@ def get_config():
...
@@ -110,7 +111,7 @@ def get_config():
session_config
=
get_default_sess_config
(
0.5
),
session_config
=
get_default_sess_config
(
0.5
),
model
=
Model
(),
model
=
Model
(),
step_per_epoch
=
300
,
step_per_epoch
=
300
,
max_epoch
=
5
00
,
max_epoch
=
3
00
,
)
)
def
sample
(
model_path
):
def
sample
(
model_path
):
...
@@ -119,7 +120,7 @@ def sample(model_path):
...
@@ -119,7 +120,7 @@ def sample(model_path):
model
=
Model
(),
model
=
Model
(),
input_names
=
[
'z'
],
input_names
=
[
'z'
],
output_names
=
[
'gen/gen'
])
output_names
=
[
'gen/gen'
])
pred
=
SimpleDatasetPredictor
(
pred
,
RandomZData
((
1
28
,
100
)))
pred
=
SimpleDatasetPredictor
(
pred
,
RandomZData
((
1
00
,
100
)))
for
o
in
pred
.
get_result
():
for
o
in
pred
.
get_result
():
o
=
o
[
0
]
+
1
o
=
o
[
0
]
+
1
o
=
o
*
128.0
o
=
o
*
128.0
...
@@ -141,6 +142,7 @@ if __name__ == '__main__':
...
@@ -141,6 +142,7 @@ if __name__ == '__main__':
if
args
.
sample
:
if
args
.
sample
:
sample
(
args
.
load
)
sample
(
args
.
load
)
else
:
else
:
assert
args
.
data
config
=
get_config
()
config
=
get_config
()
if
args
.
load
:
if
args
.
load
:
config
.
session_init
=
SaverRestore
(
args
.
load
)
config
.
session_init
=
SaverRestore
(
args
.
load
)
...
...
examples/HED/hed.py
View file @
79dbd183
...
@@ -70,7 +70,7 @@ class Model(ModelDesc):
...
@@ -70,7 +70,7 @@ class Model(ModelDesc):
costs
=
[]
costs
=
[]
for
idx
,
b
in
enumerate
([
b1
,
b2
,
b3
,
b4
,
b5
,
final_map
]):
for
idx
,
b
in
enumerate
([
b1
,
b2
,
b3
,
b4
,
b5
,
final_map
]):
output
=
tf
.
nn
.
sigmoid
(
b
,
name
=
'output{}'
.
format
(
idx
+
1
))
output
=
tf
.
nn
.
sigmoid
(
b
,
name
=
'output{}'
.
format
(
idx
+
1
))
xentropy
=
class_balanced_sigmoid_
binary_class_
cross_entropy
(
xentropy
=
class_balanced_sigmoid_cross_entropy
(
b
,
edgemap
,
b
,
edgemap
,
name
=
'xentropy{}'
.
format
(
idx
+
1
))
name
=
'xentropy{}'
.
format
(
idx
+
1
))
costs
.
append
(
xentropy
)
costs
.
append
(
xentropy
)
...
...
examples/Inception/inception-bn.py
View file @
79dbd183
...
@@ -124,6 +124,7 @@ def get_data(train_or_test):
...
@@ -124,6 +124,7 @@ def get_data(train_or_test):
pp_mean
=
meta
.
get_per_pixel_mean
()
pp_mean
=
meta
.
get_per_pixel_mean
()
if
isTrain
:
if
isTrain
:
# TODO use the augmentor in GoogleNet
augmentors
=
[
augmentors
=
[
imgaug
.
Resize
((
256
,
256
)),
imgaug
.
Resize
((
256
,
256
)),
imgaug
.
Brightness
(
30
,
False
),
imgaug
.
Brightness
(
30
,
False
),
...
...
tensorpack/models/regularize.py
View file @
79dbd183
...
@@ -40,8 +40,8 @@ def regularize_cost(regex, func, name=None):
...
@@ -40,8 +40,8 @@ def regularize_cost(regex, func, name=None):
@
layer_register
(
log_shape
=
False
)
@
layer_register
(
log_shape
=
False
)
def
Dropout
(
x
,
prob
=
0.5
):
def
Dropout
(
x
,
keep_
prob
=
0.5
):
is_training
=
get_current_tower_context
()
.
is_training
is_training
=
get_current_tower_context
()
.
is_training
keep_prob
=
tf
.
constant
(
prob
if
is_training
else
1.0
)
keep_prob
=
tf
.
constant
(
keep_
prob
if
is_training
else
1.0
)
return
tf
.
nn
.
dropout
(
x
,
keep_prob
)
return
tf
.
nn
.
dropout
(
x
,
keep_prob
)
tensorpack/tfutils/symbolic_functions.py
View file @
79dbd183
...
@@ -27,18 +27,18 @@ def batch_flatten(x):
...
@@ -27,18 +27,18 @@ def batch_flatten(x):
"""
"""
shape
=
x
.
get_shape
()
.
as_list
()[
1
:]
shape
=
x
.
get_shape
()
.
as_list
()[
1
:]
if
None
not
in
shape
:
if
None
not
in
shape
:
return
tf
.
reshape
(
x
,
[
-
1
,
np
.
prod
(
shape
)])
return
tf
.
reshape
(
x
,
[
-
1
,
int
(
np
.
prod
(
shape
)
)])
return
tf
.
reshape
(
x
,
tf
.
pack
([
tf
.
shape
(
x
)[
0
],
-
1
]))
return
tf
.
reshape
(
x
,
tf
.
pack
([
tf
.
shape
(
x
)[
0
],
-
1
]))
def
class_balanced_
binary_class_
cross_entropy
(
pred
,
label
,
name
=
'cross_entropy_loss'
):
def
class_balanced_cross_entropy
(
pred
,
label
,
name
=
'cross_entropy_loss'
):
"""
"""
The class-balanced cross entropy loss
for binary classification
,
The class-balanced cross entropy loss,
as in `Holistically-Nested Edge Detection
as in `Holistically-Nested Edge Detection
<http://arxiv.org/abs/1504.06375>`_.
<http://arxiv.org/abs/1504.06375>`_.
:param pred: size: b x ANYTHING. the predictions in [0,1].
:param pred: size: b x ANYTHING. the predictions in [0,1].
:param label: size: b x ANYTHING. the ground truth in {0,1}.
:param label: size: b x ANYTHING. the ground truth in {0,1}.
:returns: class-balanced
binary classification
cross entropy loss
:returns: class-balanced cross entropy loss
"""
"""
z
=
batch_flatten
(
pred
)
z
=
batch_flatten
(
pred
)
y
=
tf
.
cast
(
batch_flatten
(
label
),
tf
.
float32
)
y
=
tf
.
cast
(
batch_flatten
(
label
),
tf
.
float32
)
...
@@ -53,30 +53,34 @@ def class_balanced_binary_class_cross_entropy(pred, label, name='cross_entropy_l
...
@@ -53,30 +53,34 @@ def class_balanced_binary_class_cross_entropy(pred, label, name='cross_entropy_l
cost
=
tf
.
sub
(
loss_pos
,
loss_neg
,
name
=
name
)
cost
=
tf
.
sub
(
loss_pos
,
loss_neg
,
name
=
name
)
return
cost
return
cost
def
class_balanced_sigmoid_
binary_class_cross_entropy
(
pred
,
label
,
name
=
'cross_entropy_loss'
):
def
class_balanced_sigmoid_
cross_entropy
(
logits
,
label
,
name
=
'cross_entropy_loss'
):
"""
"""
The class-balanced cross entropy loss
for binary classification
,
The class-balanced cross entropy loss,
as in `Holistically-Nested Edge Detection
as in `Holistically-Nested Edge Detection
<http://arxiv.org/abs/1504.06375>`_.
<http://arxiv.org/abs/1504.06375>`_.
This is more numerically stable than class_balanced_cross_entropy
:param
pred: size: b x ANYTHING.
the logits.
:param
logits: size:
the logits.
:param label: size:
b x ANYTHING. the ground truth in {0,1}
.
:param label: size:
the ground truth in {0,1}, of the same shape as logits
.
:returns:
class-balanced binary classification
cross entropy loss
:returns:
a scalar. class-balanced
cross entropy loss
"""
"""
z
=
batch_flatten
(
pred
)
z
=
batch_flatten
(
logits
)
y
=
tf
.
cast
(
batch_flatten
(
label
),
tf
.
float32
)
y
=
tf
.
cast
(
batch_flatten
(
label
),
tf
.
float32
)
count_neg
=
tf
.
reduce_sum
(
1.
-
y
)
count_neg
=
tf
.
reduce_sum
(
1.
-
y
)
count_pos
=
tf
.
reduce_sum
(
y
)
count_pos
=
tf
.
reduce_sum
(
y
)
beta
=
count_neg
/
(
count_neg
+
count_pos
)
beta
=
count_neg
/
(
count_neg
+
count_pos
)
#eps = 1e-12
pos_weight
=
beta
/
(
1
-
beta
)
logstable
=
tf
.
log
(
1
+
tf
.
exp
(
-
tf
.
abs
(
z
)))
cost
=
tf
.
nn
.
weighted_cross_entropy_with_logits
(
z
,
y
,
pos_weight
)
loss_pos
=
-
beta
*
tf
.
reduce_mean
(
-
y
*
cost
=
tf
.
reduce_mean
(
cost
*
(
1
-
beta
),
name
=
name
)
(
logstable
-
tf
.
minimum
(
0.0
,
z
)))
loss_neg
=
(
1.
-
beta
)
*
tf
.
reduce_mean
((
y
-
1.
)
*
#logstable = tf.log(1 + tf.exp(-tf.abs(z)))
(
logstable
+
tf
.
maximum
(
z
,
0.0
)))
#loss_pos = -beta * tf.reduce_mean(-y *
cost
=
tf
.
sub
(
loss_pos
,
loss_neg
,
name
=
name
)
#(logstable - tf.minimum(0.0, z)))
#loss_neg = (1. - beta) * tf.reduce_mean((y - 1.) *
#(logstable + tf.maximum(z, 0.0)))
#cost = tf.sub(loss_pos, loss_neg, name=name)
return
cost
return
cost
def
print_stat
(
x
,
message
=
None
):
def
print_stat
(
x
,
message
=
None
):
...
...
tensorpack/utils/viz.py
View file @
79dbd183
...
@@ -98,7 +98,20 @@ def build_patch_list(patch_list,
...
@@ -98,7 +98,20 @@ def build_patch_list(patch_list,
def
dump_dataflow_images
(
df
,
index
=
0
,
batched
=
True
,
def
dump_dataflow_images
(
df
,
index
=
0
,
batched
=
True
,
number
=
300
,
output_dir
=
None
,
number
=
300
,
output_dir
=
None
,
scale
=
1
,
resize
=
None
,
viz
=
None
,
flipRGB
=
False
,
exit_after
=
True
):
scale
=
1
,
resize
=
None
,
viz
=
None
,
flipRGB
=
False
,
exit_after
=
True
):
"""
:param df: a DataFlow
:param index: the index of the image component
:param batched: whether the component contains batched images or not
:param number: how many datapoint to take from the DataFlow
:param output_dir: output directory to save images, default to not save.
:param scale: scale the value, usually either 1 or 255
:param resize: (h, w) or Nne, resize the images
:param viz: (h, w) or None, visualize the images in grid with imshow
:param flipRGB: apply a RGB<->BGR conversion or not
:param exit_after: exit the process after this function
"""
if
output_dir
:
if
output_dir
:
mkdir_p
(
output_dir
)
mkdir_p
(
output_dir
)
if
viz
is
not
None
:
if
viz
is
not
None
:
...
...
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