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
1188b56d
Commit
1188b56d
authored
Nov 07, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix resnet training
parent
efbf256e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
26 deletions
+24
-26
examples/ResNet/imagenet-resnet.py
examples/ResNet/imagenet-resnet.py
+24
-26
No files found.
examples/ResNet/imagenet-resnet.py
View file @
1188b56d
...
@@ -93,7 +93,7 @@ class Model(ModelDesc):
...
@@ -93,7 +93,7 @@ class Model(ModelDesc):
50
:
([
3
,
4
,
6
,
3
],
bottleneck
),
50
:
([
3
,
4
,
6
,
3
],
bottleneck
),
101
:
([
3
,
4
,
23
,
3
],
bottleneck
)
101
:
([
3
,
4
,
23
,
3
],
bottleneck
)
}
}
defs
,
block_func
=
cfg
[
50
]
defs
,
block_func
=
cfg
[
34
]
with
argscope
(
Conv2D
,
nl
=
tf
.
identity
,
use_bias
=
False
,
with
argscope
(
Conv2D
,
nl
=
tf
.
identity
,
use_bias
=
False
,
W_init
=
variance_scaling_initializer
(
mode
=
'FAN_OUT'
)):
W_init
=
variance_scaling_initializer
(
mode
=
'FAN_OUT'
)):
...
@@ -119,8 +119,7 @@ class Model(ModelDesc):
...
@@ -119,8 +119,7 @@ class Model(ModelDesc):
add_moving_summary
(
tf
.
reduce_mean
(
wrong
,
name
=
'train-error-top5'
))
add_moving_summary
(
tf
.
reduce_mean
(
wrong
,
name
=
'train-error-top5'
))
# weight decay on all W of fc layers
# weight decay on all W of fc layers
wd_w
=
tf
.
train
.
exponential_decay
(
1e-4
,
get_global_step_var
(),
wd_w
=
1e-4
200000
,
0.7
,
True
)
wd_cost
=
tf
.
mul
(
wd_w
,
regularize_cost
(
'.*/W'
,
tf
.
nn
.
l2_loss
),
name
=
'l2_regularize_loss'
)
wd_cost
=
tf
.
mul
(
wd_w
,
regularize_cost
(
'.*/W'
,
tf
.
nn
.
l2_loss
),
name
=
'l2_regularize_loss'
)
add_moving_summary
(
loss
,
wd_cost
)
add_moving_summary
(
loss
,
wd_cost
)
self
.
cost
=
tf
.
add_n
([
loss
,
wd_cost
],
name
=
'cost'
)
self
.
cost
=
tf
.
add_n
([
loss
,
wd_cost
],
name
=
'cost'
)
...
@@ -135,29 +134,30 @@ def get_data(train_or_test):
...
@@ -135,29 +134,30 @@ def get_data(train_or_test):
image_std
=
np
.
array
([
0.229
,
0.224
,
0.225
],
dtype
=
'float32'
)
image_std
=
np
.
array
([
0.229
,
0.224
,
0.225
],
dtype
=
'float32'
)
if
isTrain
:
if
isTrain
:
def
resize_func
(
img
):
class
Resize
(
imgaug
.
ImageAugmentor
):
# crop 8%~100% of the original image
def
_augment
(
self
,
img
,
_
):
# See `Going Deeper with Convolutions` by Google.
# crop 8%~100% of the original image
h
,
w
=
img
.
shape
[:
2
]
# See `Going Deeper with Convolutions` by Google.
area
=
h
*
w
h
,
w
=
img
.
shape
[:
2
]
for
_
in
range
(
10
):
area
=
h
*
w
targetArea
=
self
.
rng
.
uniform
(
0.08
,
1.0
)
*
area
for
_
in
range
(
10
):
aspectR
=
self
.
rng
.
uniform
(
0.75
,
1.333
)
targetArea
=
self
.
rng
.
uniform
(
0.08
,
1.0
)
*
area
ww
=
int
(
np
.
sqrt
(
targetArea
*
aspectR
))
aspectR
=
self
.
rng
.
uniform
(
0.75
,
1.333
)
hh
=
int
(
np
.
sqrt
(
targetArea
/
aspectR
))
ww
=
int
(
np
.
sqrt
(
targetArea
*
aspectR
))
if
self
.
rng
.
uniform
()
<
0.5
:
hh
=
int
(
np
.
sqrt
(
targetArea
/
aspectR
))
ww
,
hh
=
hh
,
ww
if
self
.
rng
.
uniform
()
<
0.5
:
if
hh
<=
h
and
ww
<=
w
:
ww
,
hh
=
hh
,
ww
x1
=
0
if
w
==
ww
else
self
.
rng
.
randint
(
0
,
w
-
ww
)
if
hh
<=
h
and
ww
<=
w
:
y1
=
0
if
h
==
hh
else
self
.
rng
.
randint
(
0
,
h
-
hh
)
x1
=
0
if
w
==
ww
else
self
.
rng
.
randint
(
0
,
w
-
ww
)
out
=
img
[
y1
:
y1
+
hh
,
x1
:
x1
+
ww
]
y1
=
0
if
h
==
hh
else
self
.
rng
.
randint
(
0
,
h
-
hh
)
out
=
cv2
.
resize
(
out
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
out
=
img
[
y1
:
y1
+
hh
,
x1
:
x1
+
ww
]
return
out
out
=
cv2
.
resize
(
out
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
out
=
cv2
.
resize
(
img
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
return
out
return
out
out
=
cv2
.
resize
(
img
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
return
out
augmentors
=
[
augmentors
=
[
imgaug
.
MapImage
(
resize_func
),
Resize
(
),
imgaug
.
RandomOrderAug
(
imgaug
.
RandomOrderAug
(
[
imgaug
.
Brightness
(
30
,
clip
=
False
),
[
imgaug
.
Brightness
(
30
,
clip
=
False
),
imgaug
.
Contrast
((
0.8
,
1.2
),
clip
=
False
),
imgaug
.
Contrast
((
0.8
,
1.2
),
clip
=
False
),
...
@@ -226,8 +226,6 @@ def eval_on_ILSVRC12(model_file, data_dir):
...
@@ -226,8 +226,6 @@ def eval_on_ILSVRC12(model_file, data_dir):
batch_size
=
o
[
0
]
.
shape
[
0
]
batch_size
=
o
[
0
]
.
shape
[
0
]
acc1
.
feed
(
o
[
0
]
.
sum
(),
batch_size
)
acc1
.
feed
(
o
[
0
]
.
sum
(),
batch_size
)
acc5
.
feed
(
o
[
1
]
.
sum
(),
batch_size
)
acc5
.
feed
(
o
[
1
]
.
sum
(),
batch_size
)
print
(
"Top1 Error: {}"
.
format
(
acc1
.
ratio
))
print
(
"Top5 Error: {}"
.
format
(
acc5
.
ratio
))
print
(
"Top1 Error: {}"
.
format
(
acc1
.
ratio
))
print
(
"Top1 Error: {}"
.
format
(
acc1
.
ratio
))
print
(
"Top5 Error: {}"
.
format
(
acc5
.
ratio
))
print
(
"Top5 Error: {}"
.
format
(
acc5
.
ratio
))
...
...
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