How to use a TF metric with a model?language modeling - model loss and accuracy not improving, model is underfittingTest Accuracy Increases Whilst Loss Increaseshow to randomly initialize weights in tensorflow?Tensorflow ReLu doesn't work?ANN regression model behaviourKeras metric based on output of an intermediate layerDoes tf.keras.layers.Conv2D as first layer in model truly need input_shape?MNIST Classification: mean_squared_error loss function and tanh activation functiontensorflow: distillation from resnet based model to VGG based modelMetrics values are equal while training and testing a model
When an imagined world resembles or has similarities with a famous world
How should I tell my manager I'm not paying for an optional after work event I'm not going to?
Prove that a definite integral is an infinite sum
Are sleeping system R-ratings additive?
Why is "breaking the mould" positively connoted?
Is it normal for gliders not to have attitude indicators?
Has the Hulk always been able to talk?
Can I use a Cat5e cable with an RJ45 and Cat6 port?
Why did WWI include Japan?
Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?
Why would a military not separate its forces into different branches?
How can Internet speed be 10 times slower without a router than when using the same connection with a router?
Why aren't nationalizations in Russia described as socialist?
Would you use "llamarse" for an animal's name?
As a GM, is it bad form to ask for a moment to think when improvising?
Is there a word for food that's gone 'bad', but is still edible?
Is 'contemporary' ambiguous and if so is there a better word?
To kill a cuckoo
Is an HNN extension of a virtually torsion-free group virtually torsion-free?
Install LibreOffice-Writer Only not LibreOffice whole package
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
Handling Null values (and equivalents) routinely in Python
How do I calculate how many of an item I'll have in this inventory system?
Is the book wrong about the Nyquist Sampling Criterion?
How to use a TF metric with a model?
language modeling - model loss and accuracy not improving, model is underfittingTest Accuracy Increases Whilst Loss Increaseshow to randomly initialize weights in tensorflow?Tensorflow ReLu doesn't work?ANN regression model behaviourKeras metric based on output of an intermediate layerDoes tf.keras.layers.Conv2D as first layer in model truly need input_shape?MNIST Classification: mean_squared_error loss function and tanh activation functiontensorflow: distillation from resnet based model to VGG based modelMetrics values are equal while training and testing a model
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to compile a simple model and the following works just fine:
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])
However, I would like to use this metric: tf.metrics.precision_at_k and I am not sure how I can get it to work. It requires two arguments and that is causing an issue as I don't know how to pass predictions as an argument. I tried a
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=[tf.metrics.precision_at_k])
And certain variations but did not help.
Minimal working code:
import tensorflow as tf
from tensorflow.keras import layers
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, (3,3), padding='same', activation=tf.nn.relu, input_shape=(5, 5, 1)),
tf.keras.layers.MaxPooling2D((2, 2), strides=2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(2, activation=tf.nn.softmax)
])
tensorflow
add a comment |
I am trying to compile a simple model and the following works just fine:
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])
However, I would like to use this metric: tf.metrics.precision_at_k and I am not sure how I can get it to work. It requires two arguments and that is causing an issue as I don't know how to pass predictions as an argument. I tried a
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=[tf.metrics.precision_at_k])
And certain variations but did not help.
Minimal working code:
import tensorflow as tf
from tensorflow.keras import layers
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, (3,3), padding='same', activation=tf.nn.relu, input_shape=(5, 5, 1)),
tf.keras.layers.MaxPooling2D((2, 2), strides=2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(2, activation=tf.nn.softmax)
])
tensorflow
1
Keras models only support metrics undertf.keras.metrics
. For TensorFlow metrics you need to retrieve the tensors from the Keras model and use them.
– Shubham Panchal
Mar 23 at 1:57
"retrieve the tensors from the Keras model and use them" - Can you guide me on how this can be done?
– ste_kwr
Mar 23 at 2:01
1
For the output of the last layer :output _tensor = model.layers[last_layer_index].output
– Shubham Panchal
Mar 23 at 2:31
Thanks, this helps with the "retrieve" part. I'm also fairly clueless about the "use them" part. How do I construct an optimizer with this tensor?
– ste_kwr
Mar 23 at 2:35
1
Theoutput_tensor
could be used intf.metrics
to compute the desired metrics.
– Shubham Panchal
Mar 23 at 4:54
add a comment |
I am trying to compile a simple model and the following works just fine:
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])
However, I would like to use this metric: tf.metrics.precision_at_k and I am not sure how I can get it to work. It requires two arguments and that is causing an issue as I don't know how to pass predictions as an argument. I tried a
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=[tf.metrics.precision_at_k])
And certain variations but did not help.
Minimal working code:
import tensorflow as tf
from tensorflow.keras import layers
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, (3,3), padding='same', activation=tf.nn.relu, input_shape=(5, 5, 1)),
tf.keras.layers.MaxPooling2D((2, 2), strides=2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(2, activation=tf.nn.softmax)
])
tensorflow
I am trying to compile a simple model and the following works just fine:
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])
However, I would like to use this metric: tf.metrics.precision_at_k and I am not sure how I can get it to work. It requires two arguments and that is causing an issue as I don't know how to pass predictions as an argument. I tried a
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=[tf.metrics.precision_at_k])
And certain variations but did not help.
Minimal working code:
import tensorflow as tf
from tensorflow.keras import layers
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, (3,3), padding='same', activation=tf.nn.relu, input_shape=(5, 5, 1)),
tf.keras.layers.MaxPooling2D((2, 2), strides=2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(2, activation=tf.nn.softmax)
])
tensorflow
tensorflow
asked Mar 23 at 0:51
ste_kwrste_kwr
18511
18511
1
Keras models only support metrics undertf.keras.metrics
. For TensorFlow metrics you need to retrieve the tensors from the Keras model and use them.
– Shubham Panchal
Mar 23 at 1:57
"retrieve the tensors from the Keras model and use them" - Can you guide me on how this can be done?
– ste_kwr
Mar 23 at 2:01
1
For the output of the last layer :output _tensor = model.layers[last_layer_index].output
– Shubham Panchal
Mar 23 at 2:31
Thanks, this helps with the "retrieve" part. I'm also fairly clueless about the "use them" part. How do I construct an optimizer with this tensor?
– ste_kwr
Mar 23 at 2:35
1
Theoutput_tensor
could be used intf.metrics
to compute the desired metrics.
– Shubham Panchal
Mar 23 at 4:54
add a comment |
1
Keras models only support metrics undertf.keras.metrics
. For TensorFlow metrics you need to retrieve the tensors from the Keras model and use them.
– Shubham Panchal
Mar 23 at 1:57
"retrieve the tensors from the Keras model and use them" - Can you guide me on how this can be done?
– ste_kwr
Mar 23 at 2:01
1
For the output of the last layer :output _tensor = model.layers[last_layer_index].output
– Shubham Panchal
Mar 23 at 2:31
Thanks, this helps with the "retrieve" part. I'm also fairly clueless about the "use them" part. How do I construct an optimizer with this tensor?
– ste_kwr
Mar 23 at 2:35
1
Theoutput_tensor
could be used intf.metrics
to compute the desired metrics.
– Shubham Panchal
Mar 23 at 4:54
1
1
Keras models only support metrics under
tf.keras.metrics
. For TensorFlow metrics you need to retrieve the tensors from the Keras model and use them.– Shubham Panchal
Mar 23 at 1:57
Keras models only support metrics under
tf.keras.metrics
. For TensorFlow metrics you need to retrieve the tensors from the Keras model and use them.– Shubham Panchal
Mar 23 at 1:57
"retrieve the tensors from the Keras model and use them" - Can you guide me on how this can be done?
– ste_kwr
Mar 23 at 2:01
"retrieve the tensors from the Keras model and use them" - Can you guide me on how this can be done?
– ste_kwr
Mar 23 at 2:01
1
1
For the output of the last layer :
output _tensor = model.layers[last_layer_index].output
– Shubham Panchal
Mar 23 at 2:31
For the output of the last layer :
output _tensor = model.layers[last_layer_index].output
– Shubham Panchal
Mar 23 at 2:31
Thanks, this helps with the "retrieve" part. I'm also fairly clueless about the "use them" part. How do I construct an optimizer with this tensor?
– ste_kwr
Mar 23 at 2:35
Thanks, this helps with the "retrieve" part. I'm also fairly clueless about the "use them" part. How do I construct an optimizer with this tensor?
– ste_kwr
Mar 23 at 2:35
1
1
The
output_tensor
could be used in tf.metrics
to compute the desired metrics.– Shubham Panchal
Mar 23 at 4:54
The
output_tensor
could be used in tf.metrics
to compute the desired metrics.– Shubham Panchal
Mar 23 at 4:54
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309561%2fhow-to-use-a-tf-metric-with-a-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309561%2fhow-to-use-a-tf-metric-with-a-model%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Keras models only support metrics under
tf.keras.metrics
. For TensorFlow metrics you need to retrieve the tensors from the Keras model and use them.– Shubham Panchal
Mar 23 at 1:57
"retrieve the tensors from the Keras model and use them" - Can you guide me on how this can be done?
– ste_kwr
Mar 23 at 2:01
1
For the output of the last layer :
output _tensor = model.layers[last_layer_index].output
– Shubham Panchal
Mar 23 at 2:31
Thanks, this helps with the "retrieve" part. I'm also fairly clueless about the "use them" part. How do I construct an optimizer with this tensor?
– ste_kwr
Mar 23 at 2:35
1
The
output_tensor
could be used intf.metrics
to compute the desired metrics.– Shubham Panchal
Mar 23 at 4:54