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
32f4366f
Commit
32f4366f
authored
May 11, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better bilinear & xentropy
parent
1e71e8f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
14 deletions
+13
-14
examples/load-vgg16.py
examples/load-vgg16.py
+6
-6
tensorpack/models/conv2d.py
tensorpack/models/conv2d.py
+0
-1
tensorpack/models/pool.py
tensorpack/models/pool.py
+4
-3
tensorpack/tfutils/symbolic_functions.py
tensorpack/tfutils/symbolic_functions.py
+3
-4
No files found.
examples/load-vgg16.py
View file @
32f4366f
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: load
_
vgg16.py
# File: load
-
vgg16.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
...
@@ -41,30 +41,30 @@ class Model(ModelDesc):
...
@@ -41,30 +41,30 @@ class Model(ModelDesc):
# 224
# 224
l
=
Conv2D
(
'conv1_1'
,
image
,
64
)
l
=
Conv2D
(
'conv1_1'
,
image
,
64
)
l
=
Conv2D
(
'conv1_2'
,
l
,
64
)
l
=
Conv2D
(
'conv1_2'
,
l
,
64
)
l
=
MaxPooling
(
'pool1'
,
l
,
2
,
stride
=
2
,
padding
=
'VALID'
)
l
=
MaxPooling
(
'pool1'
,
l
,
2
)
# 112
# 112
l
=
Conv2D
(
'conv2_1'
,
l
,
128
)
l
=
Conv2D
(
'conv2_1'
,
l
,
128
)
l
=
Conv2D
(
'conv2_2'
,
l
,
128
)
l
=
Conv2D
(
'conv2_2'
,
l
,
128
)
l
=
MaxPooling
(
'pool2'
,
l
,
2
,
stride
=
2
,
padding
=
'VALID'
)
l
=
MaxPooling
(
'pool2'
,
l
,
2
)
# 56
# 56
l
=
Conv2D
(
'conv3_1'
,
l
,
256
)
l
=
Conv2D
(
'conv3_1'
,
l
,
256
)
l
=
Conv2D
(
'conv3_2'
,
l
,
256
)
l
=
Conv2D
(
'conv3_2'
,
l
,
256
)
l
=
Conv2D
(
'conv3_3'
,
l
,
256
)
l
=
Conv2D
(
'conv3_3'
,
l
,
256
)
l
=
MaxPooling
(
'pool3'
,
l
,
2
,
stride
=
2
,
padding
=
'VALID'
)
l
=
MaxPooling
(
'pool3'
,
l
,
2
)
# 28
# 28
l
=
Conv2D
(
'conv4_1'
,
l
,
512
)
l
=
Conv2D
(
'conv4_1'
,
l
,
512
)
l
=
Conv2D
(
'conv4_2'
,
l
,
512
)
l
=
Conv2D
(
'conv4_2'
,
l
,
512
)
l
=
Conv2D
(
'conv4_3'
,
l
,
512
)
l
=
Conv2D
(
'conv4_3'
,
l
,
512
)
l
=
MaxPooling
(
'pool4'
,
l
,
2
,
stride
=
2
,
padding
=
'VALID'
)
l
=
MaxPooling
(
'pool4'
,
l
,
2
)
# 14
# 14
l
=
Conv2D
(
'conv5_1'
,
l
,
512
)
l
=
Conv2D
(
'conv5_1'
,
l
,
512
)
l
=
Conv2D
(
'conv5_2'
,
l
,
512
)
l
=
Conv2D
(
'conv5_2'
,
l
,
512
)
l
=
Conv2D
(
'conv5_3'
,
l
,
512
)
l
=
Conv2D
(
'conv5_3'
,
l
,
512
)
l
=
MaxPooling
(
'pool5'
,
l
,
2
,
stride
=
2
,
padding
=
'VALID'
)
l
=
MaxPooling
(
'pool5'
,
l
,
2
)
# 7
# 7
l
=
FullyConnected
(
'fc6'
,
l
,
4096
)
l
=
FullyConnected
(
'fc6'
,
l
,
4096
)
...
...
tensorpack/models/conv2d.py
View file @
32f4366f
...
@@ -30,7 +30,6 @@ def Conv2D(x, out_channel, kernel_shape,
...
@@ -30,7 +30,6 @@ def Conv2D(x, out_channel, kernel_shape,
:returns: a NHWC tensor
:returns: a NHWC tensor
"""
"""
in_shape
=
x
.
get_shape
()
.
as_list
()
in_shape
=
x
.
get_shape
()
.
as_list
()
num_in
=
np
.
prod
(
in_shape
[
1
:])
in_channel
=
in_shape
[
-
1
]
in_channel
=
in_shape
[
-
1
]
assert
in_channel
%
split
==
0
assert
in_channel
%
split
==
0
assert
out_channel
%
split
==
0
assert
out_channel
%
split
==
0
...
...
tensorpack/models/pool.py
View file @
32f4366f
...
@@ -121,6 +121,10 @@ def BilinearUpSample(x, shape):
...
@@ -121,6 +121,10 @@ def BilinearUpSample(x, shape):
ch
=
x
.
get_shape
()
.
as_list
()[
3
]
ch
=
x
.
get_shape
()
.
as_list
()[
3
]
shape
=
int
(
shape
)
shape
=
int
(
shape
)
unpool_mat
=
np
.
zeros
((
shape
,
shape
),
dtype
=
'float32'
)
unpool_mat
[
-
1
,
-
1
]
=
1
x
=
FixedUnPooling
(
'unpool'
,
x
,
shape
,
unpool_mat
)
filter_shape
=
2
*
shape
filter_shape
=
2
*
shape
w
=
bilinear_conv_filler
(
filter_shape
)
w
=
bilinear_conv_filler
(
filter_shape
)
w
=
np
.
repeat
(
w
,
ch
*
ch
)
.
reshape
((
filter_shape
,
filter_shape
,
ch
,
ch
))
w
=
np
.
repeat
(
w
,
ch
*
ch
)
.
reshape
((
filter_shape
,
filter_shape
,
ch
,
ch
))
...
@@ -128,9 +132,6 @@ def BilinearUpSample(x, shape):
...
@@ -128,9 +132,6 @@ def BilinearUpSample(x, shape):
tf
.
float32
,
tf
.
float32
,
shape
=
(
filter_shape
,
filter_shape
,
ch
,
ch
))
shape
=
(
filter_shape
,
filter_shape
,
ch
,
ch
))
unpool_mat
=
np
.
zeros
((
shape
,
shape
),
dtype
=
'float32'
)
unpool_mat
[
-
1
,
-
1
]
=
1
x
=
FixedUnPooling
(
'unpool'
,
x
,
shape
,
unpool_mat
)
output
=
tf
.
nn
.
conv2d
(
x
,
weight_var
,
[
1
,
1
,
1
,
1
],
padding
=
'SAME'
)
output
=
tf
.
nn
.
conv2d
(
x
,
weight_var
,
[
1
,
1
,
1
,
1
],
padding
=
'SAME'
)
return
output
return
output
...
...
tensorpack/tfutils/symbolic_functions.py
View file @
32f4366f
...
@@ -69,12 +69,11 @@ def class_balanced_binary_class_cross_entropy(pred, label, name='cross_entropy_l
...
@@ -69,12 +69,11 @@ def class_balanced_binary_class_cross_entropy(pred, label, name='cross_entropy_l
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
)
total
=
tf
.
add
(
count_neg
,
count_pos
)
beta
=
count_neg
/
(
count_neg
+
count_pos
)
beta
=
tf
.
truediv
(
count_neg
,
total
)
eps
=
1e-8
eps
=
1e-8
loss_pos
=
tf
.
mul
(
-
beta
,
tf
.
reduce_sum
(
tf
.
mul
(
tf
.
log
(
tf
.
abs
(
z
)
+
eps
),
y
),
1
)
)
loss_pos
=
-
beta
*
tf
.
reduce_mean
(
y
*
tf
.
log
(
tf
.
abs
(
z
)
+
eps
),
1
)
loss_neg
=
tf
.
mul
(
1.
-
beta
,
tf
.
reduce_sum
(
tf
.
mul
(
tf
.
log
(
tf
.
abs
(
1.
-
z
)
+
eps
),
1.
-
y
),
1
)
)
loss_neg
=
(
1.
-
beta
)
*
tf
.
reduce_mean
((
1.
-
y
)
*
tf
.
log
(
tf
.
abs
(
1.
-
z
)
+
eps
),
1
)
cost
=
tf
.
sub
(
loss_pos
,
loss_neg
)
cost
=
tf
.
sub
(
loss_pos
,
loss_neg
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
name
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
name
)
return
cost
return
cost
...
...
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