From 8d7e790edad5d7c369acebe4d4c11bcd4f53f49b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 2 Oct 2020 01:17:34 +0200 Subject: [PATCH] More descriptive attribute names for the Tensorflow predict response. Using `outputs` instead of `values` and `predictions` instead of `labels`. --- platypush/message/response/tensorflow.py | 8 ++++---- platypush/plugins/tensorflow/__init__.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/platypush/message/response/tensorflow.py b/platypush/message/response/tensorflow.py index 75656e5e..484a6fda 100644 --- a/platypush/message/response/tensorflow.py +++ b/platypush/message/response/tensorflow.py @@ -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: diff --git a/platypush/plugins/tensorflow/__init__.py b/platypush/plugins/tensorflow/__init__.py index c903fa4d..e6d423be 100644 --- a/platypush/plugins/tensorflow/__init__.py +++ b/platypush/plugins/tensorflow/__init__.py @@ -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