Hello! I have a keras classification model saved remotely, and I use RESTful API to call the model from my site and make predictions. The JSON request is done as follows
URL:
POST https://my.site/models/v1:predict
JSON:
{"instances": [["...something useful to predict a label..."]]}
and what I obtain is of the form (one value for each label)
{
"predictions": [
[
0.001
0.832
...
0.104
]
]
}
However, I would like to also get the label corresponding to each prediction probability, is it possible? That is, I’d like to get something in the form
{
"predictions": [
[
"label_1": 0.001
"label_2": 0.832
...
"label_n": 0.104
]
]
}
or
{
"predictions": [
[
0.001
0.832
...
0.104
]
[
"label_1"
"label_2"
...
"label_n"
]
]
}
I read the official documentation about specifying signatures when exporting a model, which seems to be related to my question, but it is not very clear about what has to be done. Basically it consists of adding the argument signatures
when saving the model:
@tf.function()
def my_predict(my_prediction_inputs):
...
my_signatures = my_predict.get_concrete_function(...)
tf.keras.models.save_model(model, path, signatures=my_signatures, ...)
Any hint/help would be appreciated, many thanks.