-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
what metrics can be used in keras #2607
Comments
One of the doc pages says the accuracy is the only thing implemented right now. There really should be a tab for metrics that says that and can be expanded later. |
I found funcitons name which like 'mae' or 'mean_absolute_error' in keras.metrics can be used in metrics, just like the parameter loss. It seems like the metrics is just used for logging, not joined in the training work. |
Precision, Recall and F1-score were added by someone: https://github.com/fchollet/keras/blob/master/keras/metrics.py Example usage: model.compile(loss='binary_crossentropy', |
After updating I still get this error: |
Hey Greg, As of now, the latest Keras package doesn't contain this yet. You can download the metrics code from GitHub, then copy it over your current one:
|
Thanks! That worked great |
I think the document is already updated? https://keras.io/metrics/ |
What is the difference between loss (objectives) and metrics? |
@wqp89324 |
@wqp89324 Another way to put it, expanding on @jhli973's answer, is that the evaluation metric is what you as the researcher will use to judge the model's performance (on training, test, and/or evaluation data); it's the bottom line number that you would publish. The loss function is what the network will use to try to improve itself, hopefully in a way that leads to improved evaluation for the researcher's sake. For example, in a binary classification problem, the network might train using a binary crossentropy loss function with gradient descent, whereas the modeler's goal is to design a network to improve binary category accuracy on hold-out data. |
It looks like many of the helpful metrics that used to be supported have been removed with Keras 2.0. I'm working on a classification problem where f-score would be much more valuable to me than accuracy. Is there a way that I can use that as a metric, or am I encouraged to use |
I resolved my problem by getting the old code from https://github.com/fchollet/keras/blob/53e541f7bf55de036f4f5641bd2947b96dd8c4c3/keras/metrics.py Maybe someone would put together a keras-contrib package. |
I agree with @brannondorsey. According to @fchollet, he explained in #5794 that it was intentionally removed in version 2.0 because it performs only approximation by batchwise evaluation. Unfortunately, there seems to be no evidence (#6002 #5705), that someone is working on a global measurement. Probably the best thing to do currently is to store the predictions and then use Scikit for calculating global measurements. For me the following worked out quite well on a classification task:
|
@apacha While using "predict_generator", How to ensure that the prediction is done on all test samples once. For example- So the dimensions of predicted_classes and true_classes is different since total samples is not divisible by batch size. The size of my test_set is not consistent, so the no. of steps in predict_generator would change each time depending upon the batch size. I am using flow_from_directory and cannot use predict_on_batch since my data is organized in a directory structure. One solution is running with batch size of 1, but makes it very slow. I hope my question is clear. Thanks in advance. |
@sxs4337 I am happy to tell you, that you don't have to worry about that, when using the ImageDataGenerator, as it automatically takes care of the last batch, if your samples are not divisible by the batch size. For example, if you have 10 samples and a minibatch-size of 4, By using |
@apacha I have 505 test samples and tried running with a batch size of 4. Below is my code snippet-
Here is the error- Found 505 images belonging to 10 classes. So the prediction has 504 values where as ground truth is 505 values. Thanks again and I appreciate the help. |
Maybe this is a bug, when having more than one worker? Try it with If all that fails, I'm afraid that I can't help you. If you think this is a Keras bug, create a issue with detailed steps to reproduce the issue. |
@apacha Found 505 images belonging to 10 classes.
BTW, my keras version is 2.0.5 |
Well. Looks obvious to me now. See the number of steps? 126! 126x4=504. For
some reason the calculation of the number of steps seems to have an issue.
It should be 127, not 126
…On 21 Jun 2017 6:19 pm, "sxs4337" ***@***.***> wrote:
@apacha <https://github.com/apacha>
It has the same issue with workers=1. I put a debugger after
model.predict_generator to check the shapes. prediction is getting just 504
samples out of 505 with batch size of 4.
Found 505 images belonging to 10 classes.
126/126 [==============================] - 34s
/home/shagan/maya/landmark/keras_finetune_vgg16_
landmarks10k.py(170)test_mode()
-> predicted_classes = np.argmax(predictions, axis=1)
(Pdb) predictions.shape
(504, 10)
(Pdb) test_generator.classes.shape
(505,)
(Pdb)
BTW, my keras version is 2.0.5
Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2607 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAkSQQ3LUJ00Q2hruyxiXOIc3LkR2gQPks5sGUKVgaJpZM4IXJpS>
.
|
Yes. That was the issue. Thanks a lot! |
what are the available "metrics" if I'm doing time series prediction(regression) in keras? |
@NourozR am I correct in assuming that you are using a mean squared error loss function? If so popular metrics include mean absolute error ( model.compile(loss='mean_squared_error',
optimizer='sgd',
metrics=['mae', 'acc']) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
Why are mean absolute error ( |
@damienrj, nothing is hidden is you look at the code: https://github.com/fchollet/keras/blob/master/keras/metrics.py If you look deep enough, you'll see that many loss functions are added as metrics. Look then at the loss page: https://keras.io/losses/ |
Is there is anyway to calculate precission@k and recall@k using the above-mentioned code ??? @mimoralea |
@apacha How can I extend your code to work for multiclass classification? |
As far as I know, scikit's classification_report does support multiclass cases, but I am not sure if we are talking about the same thing. What exactly do you mean by multiclass classification: One object potentially belonging to multiple classes? Or just having 12 different classes in total? Maybe you need some one-hot encoding for the ground truth before computing the metrics. Apart from that, I'm afraid I can't help you unless you give more details, but I don't think this is the right place to answer such questions. Preferably, you should ask such questions on Stackoverflow. |
Closing, as the metrics docs have been updated on both keras.io and tensorflow.org. 🙂 |
Most examples are use metrics=['accuracy'], but accuracy is not always suitable for every task.
The text was updated successfully, but these errors were encountered: