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
435ee4da
"vscode:/vscode.git/clone" did not exist on "854ece55e7a5f5b6a815359d6f2e10892d0f40c9"
Unverified
Commit
435ee4da
authored
Jan 29, 2018
by
Jon Shlens
Committed by
GitHub
Jan 29, 2018
Browse files
Merge branch 'master' into master
parents
d5e826e3
17f7d552
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
12 deletions
+11
-12
official/mnist/dataset.py
official/mnist/dataset.py
+4
-5
official/mnist/mnist.py
official/mnist/mnist.py
+3
-3
official/mnist/mnist_test.py
official/mnist/mnist_test.py
+2
-2
official/mnist/mnist_tpu.py
official/mnist/mnist_tpu.py
+2
-2
No files found.
official/mnist/dataset.py
View file @
435ee4da
...
@@ -89,15 +89,14 @@ def dataset(directory, images_file, labels_file):
...
@@ -89,15 +89,14 @@ def dataset(directory, images_file, labels_file):
image
=
tf
.
reshape
(
image
,
[
784
])
image
=
tf
.
reshape
(
image
,
[
784
])
return
image
/
255.0
return
image
/
255.0
def
one_hot_label
(
label
):
def
decode_label
(
label
):
label
=
tf
.
decode_raw
(
label
,
tf
.
uint8
)
# tf.string -> tf.uint8
label
=
tf
.
decode_raw
(
label
,
tf
.
uint8
)
# tf.string -> [tf.uint8]
label
=
tf
.
reshape
(
label
,
[])
# label is a scalar
return
tf
.
to_int32
(
label
)
return
tf
.
one_hot
(
label
,
10
)
images
=
tf
.
data
.
FixedLengthRecordDataset
(
images
=
tf
.
data
.
FixedLengthRecordDataset
(
images_file
,
28
*
28
,
header_bytes
=
16
).
map
(
decode_image
)
images_file
,
28
*
28
,
header_bytes
=
16
).
map
(
decode_image
)
labels
=
tf
.
data
.
FixedLengthRecordDataset
(
labels
=
tf
.
data
.
FixedLengthRecordDataset
(
labels_file
,
1
,
header_bytes
=
8
).
map
(
one_hot
_label
)
labels_file
,
1
,
header_bytes
=
8
).
map
(
decode
_label
)
return
tf
.
data
.
Dataset
.
zip
((
images
,
labels
))
return
tf
.
data
.
Dataset
.
zip
((
images
,
labels
))
...
...
official/mnist/mnist.py
View file @
435ee4da
...
@@ -102,9 +102,9 @@ def model_fn(features, labels, mode, params):
...
@@ -102,9 +102,9 @@ def model_fn(features, labels, mode, params):
optimizer
=
tf
.
contrib
.
estimator
.
TowerOptimizer
(
optimizer
)
optimizer
=
tf
.
contrib
.
estimator
.
TowerOptimizer
(
optimizer
)
logits
=
model
(
image
,
training
=
True
)
logits
=
model
(
image
,
training
=
True
)
loss
=
tf
.
losses
.
softmax_cross_entropy
(
onehot_
labels
=
labels
,
logits
=
logits
)
loss
=
tf
.
losses
.
sparse_
softmax_cross_entropy
(
labels
=
labels
,
logits
=
logits
)
accuracy
=
tf
.
metrics
.
accuracy
(
accuracy
=
tf
.
metrics
.
accuracy
(
labels
=
tf
.
argmax
(
labels
,
axis
=
1
)
,
predictions
=
tf
.
argmax
(
logits
,
axis
=
1
))
labels
=
labels
,
predictions
=
tf
.
argmax
(
logits
,
axis
=
1
))
# Name the accuracy tensor 'train_accuracy' to demonstrate the
# Name the accuracy tensor 'train_accuracy' to demonstrate the
# LoggingTensorHook.
# LoggingTensorHook.
tf
.
identity
(
accuracy
[
1
],
name
=
'train_accuracy'
)
tf
.
identity
(
accuracy
[
1
],
name
=
'train_accuracy'
)
...
@@ -115,7 +115,7 @@ def model_fn(features, labels, mode, params):
...
@@ -115,7 +115,7 @@ def model_fn(features, labels, mode, params):
train_op
=
optimizer
.
minimize
(
loss
,
tf
.
train
.
get_or_create_global_step
()))
train_op
=
optimizer
.
minimize
(
loss
,
tf
.
train
.
get_or_create_global_step
()))
if
mode
==
tf
.
estimator
.
ModeKeys
.
EVAL
:
if
mode
==
tf
.
estimator
.
ModeKeys
.
EVAL
:
logits
=
model
(
image
,
training
=
False
)
logits
=
model
(
image
,
training
=
False
)
loss
=
tf
.
losses
.
softmax_cross_entropy
(
onehot_
labels
=
labels
,
logits
=
logits
)
loss
=
tf
.
losses
.
sparse_
softmax_cross_entropy
(
labels
=
labels
,
logits
=
logits
)
return
tf
.
estimator
.
EstimatorSpec
(
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
tf
.
estimator
.
ModeKeys
.
EVAL
,
mode
=
tf
.
estimator
.
ModeKeys
.
EVAL
,
loss
=
loss
,
loss
=
loss
,
...
...
official/mnist/mnist_test.py
View file @
435ee4da
...
@@ -27,8 +27,8 @@ BATCH_SIZE = 100
...
@@ -27,8 +27,8 @@ BATCH_SIZE = 100
def
dummy_input_fn
():
def
dummy_input_fn
():
image
=
tf
.
random_uniform
([
BATCH_SIZE
,
784
])
image
=
tf
.
random_uniform
([
BATCH_SIZE
,
784
])
labels
=
tf
.
random_uniform
([
BATCH_SIZE
],
maxval
=
9
,
dtype
=
tf
.
int32
)
labels
=
tf
.
random_uniform
([
BATCH_SIZE
,
1
],
maxval
=
9
,
dtype
=
tf
.
int32
)
return
image
,
tf
.
one_hot
(
labels
,
10
)
return
image
,
labels
def
make_estimator
():
def
make_estimator
():
...
...
official/mnist/mnist_tpu.py
View file @
435ee4da
...
@@ -50,7 +50,7 @@ FLAGS = tf.flags.FLAGS
...
@@ -50,7 +50,7 @@ FLAGS = tf.flags.FLAGS
def
metric_fn
(
labels
,
logits
):
def
metric_fn
(
labels
,
logits
):
accuracy
=
tf
.
metrics
.
accuracy
(
accuracy
=
tf
.
metrics
.
accuracy
(
labels
=
tf
.
argmax
(
labels
,
axis
=
1
)
,
predictions
=
tf
.
argmax
(
logits
,
axis
=
1
))
labels
=
labels
,
predictions
=
tf
.
argmax
(
logits
,
axis
=
1
))
return
{
"accuracy"
:
accuracy
}
return
{
"accuracy"
:
accuracy
}
...
@@ -64,7 +64,7 @@ def model_fn(features, labels, mode, params):
...
@@ -64,7 +64,7 @@ def model_fn(features, labels, mode, params):
model
=
mnist
.
Model
(
"channels_last"
)
model
=
mnist
.
Model
(
"channels_last"
)
logits
=
model
(
image
,
training
=
(
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
))
logits
=
model
(
image
,
training
=
(
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
))
loss
=
tf
.
losses
.
softmax_cross_entropy
(
onehot_
labels
=
labels
,
logits
=
logits
)
loss
=
tf
.
losses
.
sparse_
softmax_cross_entropy
(
labels
=
labels
,
logits
=
logits
)
if
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
:
if
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
:
learning_rate
=
tf
.
train
.
exponential_decay
(
learning_rate
=
tf
.
train
.
exponential_decay
(
...
...
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