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
0f5803bd
Unverified
Commit
0f5803bd
authored
Dec 20, 2017
by
Mark Daoust
Committed by
GitHub
Dec 20, 2017
Browse files
Merge pull request #3028 from tensorflow/mhyttsten-patch-2
Update blog_custom_estimators.py
parents
d19587e4
688143ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
6 deletions
+5
-6
samples/outreach/blogs/blog_custom_estimators.py
samples/outreach/blogs/blog_custom_estimators.py
+5
-6
No files found.
samples/outreach/blogs/blog_custom_estimators.py
View file @
0f5803bd
...
@@ -14,8 +14,7 @@
...
@@ -14,8 +14,7 @@
# ==============================================================================
# ==============================================================================
# This is the complete code for the following blogpost:
# This is the complete code for the following blogpost:
# https://developers.googleblog.com/2017/09/introducing-tensorflow-datasets.html
# https://developers.googleblog.com/2017/12/creating-custom-estimators-in-tensorflow.html
# (https://goo.gl/Ujm2Ep)
import
tensorflow
as
tf
import
tensorflow
as
tf
import
os
import
os
...
@@ -116,7 +115,7 @@ def my_model_fn(
...
@@ -116,7 +115,7 @@ def my_model_fn(
h2
=
tf
.
layers
.
Dense
(
10
,
activation
=
tf
.
nn
.
relu
)(
h1
)
h2
=
tf
.
layers
.
Dense
(
10
,
activation
=
tf
.
nn
.
relu
)(
h1
)
# Output 'logits' layer is three number = probability distribution
# Output 'logits' layer is three number = probability distribution
# between Iris Se
n
tosa, Versicolor, and Viginica
# between Iris Setosa, Versicolor, and Viginica
logits
=
tf
.
layers
.
Dense
(
3
)(
h2
)
logits
=
tf
.
layers
.
Dense
(
3
)(
h2
)
# class_ids will be the model prediction for the class (Iris flower type)
# class_ids will be the model prediction for the class (Iris flower type)
...
@@ -206,14 +205,14 @@ predict_results = classifier.predict(
...
@@ -206,14 +205,14 @@ predict_results = classifier.predict(
tf
.
logging
.
info
(
"Prediction on test file"
)
tf
.
logging
.
info
(
"Prediction on test file"
)
for
prediction
in
predict_results
:
for
prediction
in
predict_results
:
# Will print the predicted class, i.e: 0, 1, or 2 if the prediction
# Will print the predicted class, i.e: 0, 1, or 2 if the prediction
# is Iris Se
n
tosa, Vericolor, Virginica, respectively.
# is Iris Setosa, Vericolor, Virginica, respectively.
tf
.
logging
.
info
(
"...{}"
.
format
(
prediction
[
"class_ids"
]))
tf
.
logging
.
info
(
"...{}"
.
format
(
prediction
[
"class_ids"
]))
# Let create a dataset for prediction
# Let create a dataset for prediction
# We've taken the first 3 examples in FILE_TEST
# We've taken the first 3 examples in FILE_TEST
prediction_input
=
[[
5.9
,
3.0
,
4.2
,
1.5
],
# -> 1, Iris Versicolor
prediction_input
=
[[
5.9
,
3.0
,
4.2
,
1.5
],
# -> 1, Iris Versicolor
[
6.9
,
3.1
,
5.4
,
2.1
],
# -> 2, Iris Virginica
[
6.9
,
3.1
,
5.4
,
2.1
],
# -> 2, Iris Virginica
[
5.1
,
3.3
,
1.7
,
0.5
]]
# -> 0, Iris Se
n
tosa
[
5.1
,
3.3
,
1.7
,
0.5
]]
# -> 0, Iris Setosa
def
new_input_fn
():
def
new_input_fn
():
def
decode
(
x
):
def
decode
(
x
):
...
@@ -234,7 +233,7 @@ tf.logging.info("Predictions on memory")
...
@@ -234,7 +233,7 @@ tf.logging.info("Predictions on memory")
for
idx
,
prediction
in
enumerate
(
predict_results
):
for
idx
,
prediction
in
enumerate
(
predict_results
):
type
=
prediction
[
"class_ids"
]
# Get the predicted class (index)
type
=
prediction
[
"class_ids"
]
# Get the predicted class (index)
if
type
==
0
:
if
type
==
0
:
tf
.
logging
.
info
(
"...I think: {}, is Iris Se
n
tosa"
.
format
(
prediction_input
[
idx
]))
tf
.
logging
.
info
(
"...I think: {}, is Iris Setosa"
.
format
(
prediction_input
[
idx
]))
elif
type
==
1
:
elif
type
==
1
:
tf
.
logging
.
info
(
"...I think: {}, is Iris Versicolor"
.
format
(
prediction_input
[
idx
]))
tf
.
logging
.
info
(
"...I think: {}, is Iris Versicolor"
.
format
(
prediction_input
[
idx
]))
else
:
else
:
...
...
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