Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
ea364a9e
Commit
ea364a9e
authored
Jan 26, 2017
by
Xin Pan
Committed by
GitHub
Jan 26, 2017
Browse files
Merge pull request #959 from yaroslavvb/resnet-tf10-compatibility
Changes to Resnet for TF 1.0 compatibility
parents
d66941ac
4ec3452d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
9 deletions
+10
-9
resnet/cifar_input.py
resnet/cifar_input.py
+1
-2
resnet/resnet_main.py
resnet/resnet_main.py
+2
-1
resnet/resnet_model.py
resnet/resnet_model.py
+7
-6
No files found.
resnet/cifar_input.py
View file @
ea364a9e
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
import
tensorflow
as
tf
import
tensorflow
as
tf
def
build_input
(
dataset
,
data_path
,
batch_size
,
mode
):
def
build_input
(
dataset
,
data_path
,
batch_size
,
mode
):
"""Build CIFAR image and labels.
"""Build CIFAR image and labels.
...
@@ -101,7 +100,7 @@ def build_input(dataset, data_path, batch_size, mode):
...
@@ -101,7 +100,7 @@ def build_input(dataset, data_path, batch_size, mode):
labels
=
tf
.
reshape
(
labels
,
[
batch_size
,
1
])
labels
=
tf
.
reshape
(
labels
,
[
batch_size
,
1
])
indices
=
tf
.
reshape
(
tf
.
range
(
0
,
batch_size
,
1
),
[
batch_size
,
1
])
indices
=
tf
.
reshape
(
tf
.
range
(
0
,
batch_size
,
1
),
[
batch_size
,
1
])
labels
=
tf
.
sparse_to_dense
(
labels
=
tf
.
sparse_to_dense
(
tf
.
concat
(
1
,
[
indices
,
labels
]),
tf
.
concat
_v2
(
values
=
[
indices
,
labels
]
,
axis
=
1
),
[
batch_size
,
num_classes
],
1.0
,
0.0
)
[
batch_size
,
num_classes
],
1.0
,
0.0
)
assert
len
(
images
.
get_shape
())
==
4
assert
len
(
images
.
get_shape
())
==
4
...
...
resnet/resnet_main.py
View file @
ea364a9e
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
"""ResNet Train/Eval module.
"""ResNet Train/Eval module.
"""
"""
import
time
import
time
import
six
import
sys
import
sys
import
cifar_input
import
cifar_input
...
@@ -140,7 +141,7 @@ def evaluate(hps):
...
@@ -140,7 +141,7 @@ def evaluate(hps):
saver
.
restore
(
sess
,
ckpt_state
.
model_checkpoint_path
)
saver
.
restore
(
sess
,
ckpt_state
.
model_checkpoint_path
)
total_prediction
,
correct_prediction
=
0
,
0
total_prediction
,
correct_prediction
=
0
,
0
for
_
in
x
range
(
FLAGS
.
eval_batch_count
):
for
_
in
six
.
moves
.
range
(
FLAGS
.
eval_batch_count
):
(
summaries
,
loss
,
predictions
,
truth
,
train_step
)
=
sess
.
run
(
(
summaries
,
loss
,
predictions
,
truth
,
train_step
)
=
sess
.
run
(
[
model
.
summaries
,
model
.
cost
,
model
.
predictions
,
[
model
.
summaries
,
model
.
cost
,
model
.
predictions
,
model
.
labels
,
model
.
global_step
])
model
.
labels
,
model
.
global_step
])
...
...
resnet/resnet_model.py
View file @
ea364a9e
...
@@ -24,6 +24,7 @@ from collections import namedtuple
...
@@ -24,6 +24,7 @@ from collections import namedtuple
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
import
six
from
tensorflow.python.training
import
moving_averages
from
tensorflow.python.training
import
moving_averages
...
@@ -89,21 +90,21 @@ class ResNet(object):
...
@@ -89,21 +90,21 @@ class ResNet(object):
with
tf
.
variable_scope
(
'unit_1_0'
):
with
tf
.
variable_scope
(
'unit_1_0'
):
x
=
res_func
(
x
,
filters
[
0
],
filters
[
1
],
self
.
_stride_arr
(
strides
[
0
]),
x
=
res_func
(
x
,
filters
[
0
],
filters
[
1
],
self
.
_stride_arr
(
strides
[
0
]),
activate_before_residual
[
0
])
activate_before_residual
[
0
])
for
i
in
x
range
(
1
,
self
.
hps
.
num_residual_units
):
for
i
in
six
.
moves
.
range
(
1
,
self
.
hps
.
num_residual_units
):
with
tf
.
variable_scope
(
'unit_1_%d'
%
i
):
with
tf
.
variable_scope
(
'unit_1_%d'
%
i
):
x
=
res_func
(
x
,
filters
[
1
],
filters
[
1
],
self
.
_stride_arr
(
1
),
False
)
x
=
res_func
(
x
,
filters
[
1
],
filters
[
1
],
self
.
_stride_arr
(
1
),
False
)
with
tf
.
variable_scope
(
'unit_2_0'
):
with
tf
.
variable_scope
(
'unit_2_0'
):
x
=
res_func
(
x
,
filters
[
1
],
filters
[
2
],
self
.
_stride_arr
(
strides
[
1
]),
x
=
res_func
(
x
,
filters
[
1
],
filters
[
2
],
self
.
_stride_arr
(
strides
[
1
]),
activate_before_residual
[
1
])
activate_before_residual
[
1
])
for
i
in
x
range
(
1
,
self
.
hps
.
num_residual_units
):
for
i
in
six
.
moves
.
range
(
1
,
self
.
hps
.
num_residual_units
):
with
tf
.
variable_scope
(
'unit_2_%d'
%
i
):
with
tf
.
variable_scope
(
'unit_2_%d'
%
i
):
x
=
res_func
(
x
,
filters
[
2
],
filters
[
2
],
self
.
_stride_arr
(
1
),
False
)
x
=
res_func
(
x
,
filters
[
2
],
filters
[
2
],
self
.
_stride_arr
(
1
),
False
)
with
tf
.
variable_scope
(
'unit_3_0'
):
with
tf
.
variable_scope
(
'unit_3_0'
):
x
=
res_func
(
x
,
filters
[
2
],
filters
[
3
],
self
.
_stride_arr
(
strides
[
2
]),
x
=
res_func
(
x
,
filters
[
2
],
filters
[
3
],
self
.
_stride_arr
(
strides
[
2
]),
activate_before_residual
[
2
])
activate_before_residual
[
2
])
for
i
in
x
range
(
1
,
self
.
hps
.
num_residual_units
):
for
i
in
six
.
moves
.
range
(
1
,
self
.
hps
.
num_residual_units
):
with
tf
.
variable_scope
(
'unit_3_%d'
%
i
):
with
tf
.
variable_scope
(
'unit_3_%d'
%
i
):
x
=
res_func
(
x
,
filters
[
3
],
filters
[
3
],
self
.
_stride_arr
(
1
),
False
)
x
=
res_func
(
x
,
filters
[
3
],
filters
[
3
],
self
.
_stride_arr
(
1
),
False
)
...
@@ -118,7 +119,7 @@ class ResNet(object):
...
@@ -118,7 +119,7 @@ class ResNet(object):
with
tf
.
variable_scope
(
'costs'
):
with
tf
.
variable_scope
(
'costs'
):
xent
=
tf
.
nn
.
softmax_cross_entropy_with_logits
(
xent
=
tf
.
nn
.
softmax_cross_entropy_with_logits
(
logits
,
self
.
labels
)
logits
=
logits
,
labels
=
self
.
labels
)
self
.
cost
=
tf
.
reduce_mean
(
xent
,
name
=
'xent'
)
self
.
cost
=
tf
.
reduce_mean
(
xent
,
name
=
'xent'
)
self
.
cost
+=
self
.
_decay
()
self
.
cost
+=
self
.
_decay
()
...
@@ -266,7 +267,7 @@ class ResNet(object):
...
@@ -266,7 +267,7 @@ class ResNet(object):
costs
.
append
(
tf
.
nn
.
l2_loss
(
var
))
costs
.
append
(
tf
.
nn
.
l2_loss
(
var
))
# tf.histogram_summary(var.op.name, var)
# tf.histogram_summary(var.op.name, var)
return
tf
.
mul
(
self
.
hps
.
weight_decay_rate
,
tf
.
add_n
(
costs
))
return
tf
.
mul
tiply
(
self
.
hps
.
weight_decay_rate
,
tf
.
add_n
(
costs
))
def
_conv
(
self
,
name
,
x
,
filter_size
,
in_filters
,
out_filters
,
strides
):
def
_conv
(
self
,
name
,
x
,
filter_size
,
in_filters
,
out_filters
,
strides
):
"""Convolution."""
"""Convolution."""
...
@@ -280,7 +281,7 @@ class ResNet(object):
...
@@ -280,7 +281,7 @@ class ResNet(object):
def
_relu
(
self
,
x
,
leakiness
=
0.0
):
def
_relu
(
self
,
x
,
leakiness
=
0.0
):
"""Relu, with optional leaky support."""
"""Relu, with optional leaky support."""
return
tf
.
select
(
tf
.
less
(
x
,
0.0
),
leakiness
*
x
,
x
,
name
=
'leaky_relu'
)
return
tf
.
where
(
tf
.
less
(
x
,
0.0
),
leakiness
*
x
,
x
,
name
=
'leaky_relu'
)
def
_fully_connected
(
self
,
x
,
out_dim
):
def
_fully_connected
(
self
,
x
,
out_dim
):
"""FullyConnected layer for final output."""
"""FullyConnected layer for final output."""
...
...
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