More descriptive attribute names for the Tensorflow predict response.

Using `outputs` instead of `values` and `predictions` instead of `labels`.
This commit is contained in:
Fabio Manganiello 2020-10-02 01:17:34 +02:00
parent daaa0050d1
commit 8d7e790eda
2 changed files with 12 additions and 12 deletions

View file

@ -44,19 +44,19 @@ class TensorflowPredictResponse(TensorflowResponse):
super().__init__(*args, **kwargs)
if output_labels and len(output_labels) == self.model.outputs[-1].shape[-1]:
self.output['values'] = [
self.output['outputs'] = [
{output_labels[i]: value for i, value in enumerate(p)}
for p in prediction
]
else:
self.output['values'] = prediction
self.output['outputs'] = prediction
if self.model.__class__.__name__ != 'LinearModel':
prediction = [int(np.argmax(p)) for p in prediction]
if output_labels:
self.output['labels'] = [output_labels[p] for p in prediction]
self.output['predictions'] = [output_labels[p] for p in prediction]
else:
self.output['labels'] = prediction
self.output['predictions'] = prediction
# vim:sw=4:ts=4:et:

View file

@ -1015,21 +1015,21 @@ class TensorflowPlugin(Plugin):
:return: :class:`platypush.message.response.tensorflow.TensorflowPredictResponse`. Format:
- For regression models with no output labels specified: ``values`` will contain the output vector:
- For regression models with no output labels specified: ``outputs`` will contain the output vector:
.. code-block:: json
{
"values": [[3.1415]]
"outputs": [[3.1415]]
}
- For regression models with output labels specified: ``values`` will be a list of ``{label -> value}``
- For regression models with output labels specified: ``outputs`` will be a list of ``{label -> value}``
maps:
.. code-block:: json
{
"values": [
"outputs": [
{
"x": 42.0,
"y": 43.0
@ -1037,17 +1037,17 @@ class TensorflowPlugin(Plugin):
]
}
- For neural networks: ``values`` will contain the list of the output vector like in the case of
regression, and ``labels`` will store the list of ``argmax`` (i.e. the index of the output unit with the
- For neural networks: ``outputs`` will contain the list of the output vector like in the case of
regression, and ``predictions`` will store the list of ``argmax`` (i.e. the index of the output unit with the
highest value) or their labels, if the model has output labels:
.. code-block:: json
{
"labels": [
"predictions": [
"positive"
],
"values": [
"outputs": [
{
"positive": 0.998,
"negative": 0.002