platypush/plugins/tensorflow/__init__.py
def predict(self,
                model: str,
                inputs: Union[str, np.ndarray, Iterable, Dict[str, Union[Iterable, np.ndarray]]],
                batch_size: Optional[int] = None,
                verbose: int = 0,
                steps: Optional[int] = None,
                max_queue_size: int = 10,
                workers: int = 1,
                use_multiprocessing: bool = False) -> TensorflowPredictResponse:
        """
        Generates output predictions for the input samples.

        :param model: Name of the model. It can be a folder name stored under ``<workdir>/models``, or an absolute path
            to a model directory or file (Tensorflow directories, Protobuf models and HDF5 files are supported).
        :param inputs: Input data. It can be:

          - A numpy array (or array-like), or a list of arrays in case the model has multiple inputs.
          - A TensorFlow tensor, or a list of tensors in case the model has multiple inputs.
          - A dict mapping input names to the corresponding array/tensors, if the model has named inputs.
          - A ``tf.data`` dataset. Should return a tuple of either ``(inputs, targets)`` or
            ``(inputs, targets, sample_weights)``.
          - A generator or ``keras.utils.Sequence`` returning ``(inputs, targets)`` or
            ``(inputs, targets, sample weights)``.
          - A string that points to a file. Supported formats:

              - CSV with header (``.csv`` extension``)
              - Numpy raw or compressed files (``.npy`` or ``.npz`` extension)
              - Image files
              - An HTTP URL pointing to one of the file types listed above

        :param batch_size: Number of samples per gradient update. If unspecified, ``batch_size`` will default to 32.
            Do not specify the ``batch_size`` if your data is in the form of symbolic tensors, datasets,
            generators, or ``keras.utils.Sequence`` instances (since they generate batches).

        :param verbose: Verbosity mode, 0 or 1.

        :param steps: Total number of steps (batches of samples) before declaring the prediction round finished.
            Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, ``predict``
            will run until the input dataset is exhausted.

        :param max_queue_size: Integer. Used for generator or ``keras.utils.Sequence`` input only. Maximum size for
            the generator queue (default: 10).

        :param workers: Used for generator or ``keras.utils.Sequence`` input only. Maximum number of processes
            to spin up when using process-based threading. If unspecified, ``workers`` will default to 1. If 0, will
            execute the generator on the main thread.

        :param use_multiprocessing: Used for generator or ``keras.utils.Sequence`` input only. If ``True``,
            use process-based threading. If unspecified, ``use_multiprocessing`` will default to ``False``.
            Note that because this implementation relies on multiprocessing, you should not pass non-picklable
            arguments to the generator as they can't be passed easily to children processes.

        :return: :class:`platypush.message.response.tensorflow.TensorflowPredictResponse`. Format:

            - For regression models with no output labels specified: ``outputs`` will contain the output vector:

                .. code-block:: json

                  {
                      "outputs": [[3.1415]]
                  }

            - For regression models with output labels specified: ``outputs`` will be a list of ``{label -> value}``
              maps:

                .. code-block:: json

                  {
                      "outputs": [
                          {
                              "x": 42.0,
                              "y": 43.0
                          }
                      ]
                  }

            - 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

                  {
                      "predictions": [
                          "positive"
                      ],
                      "outputs": [
                          {
                              "positive": 0.998,
                              "negative": 0.002
                          }
                      ]
                  }

        """
        name = model
        model = self._load_model(model)
        inputs = self._get_data(inputs, model)
        if isinstance(inputs, np.ndarray) and \
                len(model.inputs[0].shape) == len(inputs.shape) + 1 and \
                (model.inputs[0].shape[0] is None or model.inputs[0].shape[0].value is None):
            inputs = np.asarray([inputs])

        ret = model.predict(
            inputs,
            batch_size=batch_size,
            verbose=verbose,
            steps=steps,
            callbacks=self._generate_callbacks(name),
            max_queue_size=max_queue_size,
            workers=workers,
            use_multiprocessing=use_multiprocessing
        )

        return TensorflowPredictResponse(model=model, model_name=name, prediction=ret,
                                         output_labels=model.output_labels)

        Generates output predictions for the input samples.

        :param model: Name of the model. It can be a folder name stored under ``<workdir>/models``, or an absolute path
            to a model directory or file (Tensorflow directories, Protobuf models and HDF5 files are supported).
        :param inputs: Input data. It can be:

          - A numpy array (or array-like), or a list of arrays in case the model has multiple inputs.
          - A TensorFlow tensor, or a list of tensors in case the model has multiple inputs.
          - A dict mapping input names to the corresponding array/tensors, if the model has named inputs.
          - A ``tf.data`` dataset. Should return a tuple of either ``(inputs, targets)`` or
            ``(inputs, targets, sample_weights)``.
          - A generator or ``keras.utils.Sequence`` returning ``(inputs, targets)`` or
            ``(inputs, targets, sample weights)``.
          - A string that points to a file. Supported formats:

              - CSV with header (``.csv`` extension``)
              - Numpy raw or compressed files (``.npy`` or ``.npz`` extension)
              - Image files
              - An HTTP URL pointing to one of the file types listed above

        :param batch_size: Number of samples per gradient update. If unspecified, ``batch_size`` will default to 32.
            Do not specify the ``batch_size`` if your data is in the form of symbolic tensors, datasets,
            generators, or ``keras.utils.Sequence`` instances (since they generate batches).

        :param verbose: Verbosity mode, 0 or 1.

        :param steps: Total number of steps (batches of samples) before declaring the prediction round finished.
            Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, ``predict``
            will run until the input dataset is exhausted.

        :param max_queue_size: Integer. Used for generator or ``keras.utils.Sequence`` input only. Maximum size for
            the generator queue (default: 10).

        :param workers: Used for generator or ``keras.utils.Sequence`` input only. Maximum number of processes
            to spin up when using process-based threading. If unspecified, ``workers`` will default to 1. If 0, will
            execute the generator on the main thread.

        :param use_multiprocessing: Used for generator or ``keras.utils.Sequence`` input only. If ``True``,
            use process-based threading. If unspecified, ``use_multiprocessing`` will default to ``False``.
            Note that because this implementation relies on multiprocessing, you should not pass non-picklable
            arguments to the generator as they can't be passed easily to children processes.

        :return: :class:`platypush.message.response.tensorflow.TensorflowPredictResponse`. Format:

            - For regression models with no output labels specified: ``outputs`` will contain the output vector:

                .. code-block:: json

                  {
                      "outputs": [[3.1415]]
                  }

            - For regression models with output labels specified: ``outputs`` will be a list of ``{label -> value}``
              maps:

                .. code-block:: json

                  {
                      "outputs": [
                          {
                              "x": 42.0,
                              "y": 43.0
                          }
                      ]
                  }

            - 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

                  {
                      "predictions": [
                          "positive"
                      ],
                      "outputs": [
                          {
                              "positive": 0.998,
                              "negative": 0.002
                          }
                      ]
                  }

        
Generates output predictions for the input samples.
Generates output predictions for the input samples .
def predict(self,
                model: str,
                inputs: Union[str, np.ndarray, Iterable, Dict[str, Union[Iterable, np.ndarray]]],
                batch_size: Optional[int] = None,
                verbose: int = 0,
                steps: Optional[int] = None,
                max_queue_size: int = 10,
                workers: int = 1,
                use_multiprocessing: bool = False) -> TensorflowPredictResponse:
        name = model
        model = self._load_model(model)
        inputs = self._get_data(inputs, model)
        if isinstance(inputs, np.ndarray) and \
                len(model.inputs[0].shape) == len(inputs.shape) + 1 and \
                (model.inputs[0].shape[0] is None or model.inputs[0].shape[0].value is None):
            inputs = np.asarray([inputs])
        ret = model.predict(
            inputs,
            batch_size=batch_size,
            verbose=verbose,
            steps=steps,
            callbacks=self._generate_callbacks(name),
            max_queue_size=max_queue_size,
            workers=workers,
            use_multiprocessing=use_multiprocessing
        )
        return TensorflowPredictResponse(model=model, model_name=name, prediction=ret,
                                         output_labels=model.output_labels)
def predict ( self , model : str , inputs : Union [ str , np . ndarray , Iterable , Dict [ str , Union [ Iterable , np . ndarray ] ] ] , batch_size : Optional [ int ] = None , verbose : int = 0 , steps : Optional [ int ] = None , max_queue_size : int = 10 , workers : int = 1 , use_multiprocessing : bool = False ) -> TensorflowPredictResponse : name = model model = self . _load_model ( model ) inputs = self . _get_data ( inputs , model ) if isinstance ( inputs , np . ndarray ) and len ( model . inputs [ 0 ] . shape ) == len ( inputs . shape ) + 1 and ( model . inputs [ 0 ] . shape [ 0 ] is None or model . inputs [ 0 ] . shape [ 0 ] . value is None ) : inputs = np . asarray ( [ inputs ] ) ret = model . predict ( inputs , batch_size = batch_size , verbose = verbose , steps = steps , callbacks = self . _generate_callbacks ( name ) , max_queue_size = max_queue_size , workers = workers , use_multiprocessing = use_multiprocessing ) return TensorflowPredictResponse ( model = model , model_name = name , prediction = ret , output_labels = model . output_labels )
Generates output predictions for the input samples.
Generates output predictions for the input samples .
"""
        Generates output predictions for the input samples.

        :param model: Name of the model. It can be a folder name stored under ``<workdir>/models``, or an absolute path
            to a model directory or file (Tensorflow directories, Protobuf models and HDF5 files are supported).
        :param inputs: Input data. It can be:

          - A numpy array (or array-like), or a list of arrays in case the model has multiple inputs.
          - A TensorFlow tensor, or a list of tensors in case the model has multiple inputs.
          - A dict mapping input names to the corresponding array/tensors, if the model has named inputs.
          - A ``tf.data`` dataset. Should return a tuple of either ``(inputs, targets)`` or
            ``(inputs, targets, sample_weights)``.
          - A generator or ``keras.utils.Sequence`` returning ``(inputs, targets)`` or
            ``(inputs, targets, sample weights)``.
          - A string that points to a file. Supported formats:

              - CSV with header (``.csv`` extension``)
              - Numpy raw or compressed files (``.npy`` or ``.npz`` extension)
              - Image files
              - An HTTP URL pointing to one of the file types listed above

        :param batch_size: Number of samples per gradient update. If unspecified, ``batch_size`` will default to 32.
            Do not specify the ``batch_size`` if your data is in the form of symbolic tensors, datasets,
            generators, or ``keras.utils.Sequence`` instances (since they generate batches).

        :param verbose: Verbosity mode, 0 or 1.

        :param steps: Total number of steps (batches of samples) before declaring the prediction round finished.
            Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, ``predict``
            will run until the input dataset is exhausted.

        :param max_queue_size: Integer. Used for generator or ``keras.utils.Sequence`` input only. Maximum size for
            the generator queue (default: 10).

        :param workers: Used for generator or ``keras.utils.Sequence`` input only. Maximum number of processes
            to spin up when using process-based threading. If unspecified, ``workers`` will default to 1. If 0, will
            execute the generator on the main thread.

        :param use_multiprocessing: Used for generator or ``keras.utils.Sequence`` input only. If ``True``,
            use process-based threading. If unspecified, ``use_multiprocessing`` will default to ``False``.
            Note that because this implementation relies on multiprocessing, you should not pass non-picklable
            arguments to the generator as they can't be passed easily to children processes.

        :return: :class:`platypush.message.response.tensorflow.TensorflowPredictResponse`. Format:

            - For regression models with no output labels specified: ``outputs`` will contain the output vector:

                .. code-block:: json

                  {
                      "outputs": [[3.1415]]
                  }

            - For regression models with output labels specified: ``outputs`` will be a list of ``{label -> value}``
              maps:

                .. code-block:: json

                  {
                      "outputs": [
                          {
                              "x": 42.0,
                              "y": 43.0
                          }
                      ]
                  }

            - 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

                  {
                      "predictions": [
                          "positive"
                      ],
                      "outputs": [
                          {
                              "positive": 0.998,
                              "negative": 0.002
                          }
                      ]
                  }

        """
:class:`platypush.message.response.tensorflow.TensorflowPredictResponse`. Format:
For regression models with no output labels specified: ``outputs`` will contain the output vector.

code-block:: json



For regression models with output labels specified: ``outputs`` will be a list of ``{label -> value}``
maps.

code-block:: json



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``  or their labels, if the model has output labels.

code-block:: json


: class : ` platypush . message . response . tensorflow . TensorflowPredictResponse ` . Format : For regression models with no output labels specified : ` ` outputs ` ` will contain the output vector . code - block :: json For regression models with output labels specified : ` ` outputs ` ` will be a list of ` ` { label - > value } ` ` maps . code - block :: json 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 ` ` or their labels if the model has output labels . code - block :: json
self
model
str
Name of the model. It can be a folder name stored under ``/models``, or an absolute path
to a model directory or file (Tensorflow directories, Protobuf models and HDF5 files are supported).
Name of the model . It can be a folder name stored under ` ` / models ` ` or an absolute path to a model directory or file ( Tensorflow directories Protobuf models and HDF5 files are supported ) .
inputs
Union[str, np.ndarray, Iterable, Dict[str, Union[Iterable, np.ndarray]]]
Input data. It can be:
A numpy array (or array-like), or a list of arrays in case the model has multiple inputs.
A TensorFlow tensor, or a list of tensors in case the model has multiple inputs.
A dict mapping input names to the corresponding array/tensors, if the model has named inputs.
A ``tf.data`` dataset. Should return a tuple of either ``(inputs, targets)`` or
``(inputs, targets, sample_weights)``.
A generator or ``keras.utils.Sequence`` returning ``(inputs, targets)`` or
``(inputs, targets, sample weights)``.
A string that points to a file. Supported formats.

CSV with header (``.csv`` extension``)
Numpy raw or compressed files (``.npy`` or ``.npz`` extension)
Image files
An HTTP URL pointing to one of the file types listed above
Input data . It can be : A numpy array ( or array - like ) or a list of arrays in case the model has multiple inputs . A TensorFlow tensor or a list of tensors in case the model has multiple inputs . A dict mapping input names to the corresponding array / tensors if the model has named inputs . A ` ` tf . data ` ` dataset . Should return a tuple of either ` ` ( inputs targets ) ` ` or ` ` ( inputs targets sample_weights ) ` ` . A generator or ` ` keras . utils . Sequence ` ` returning ` ` ( inputs targets ) ` ` or ` ` ( inputs targets sample weights ) ` ` . A string that points to a file . Supported formats . CSV with header ( ` ` . csv ` ` extension ` ` ) Numpy raw or compressed files ( ` ` . npy ` ` or ` ` . npz ` ` extension ) Image files An HTTP URL pointing to one of the file types listed above
batch_size
Optional[int]
Number of samples per gradient update. If unspecified, ``batch_size`` will default to 32.
Do not specify the ``batch_size`` if your data is in the form of symbolic tensors, datasets,
generators, or ``keras.utils.Sequence`` instances (since they generate batches).
Number of samples per gradient update . If unspecified ` ` batch_size ` ` will default to 32 . Do not specify the ` ` batch_size ` ` if your data is in the form of symbolic tensors datasets generators or ` ` keras . utils . Sequence ` ` instances ( since they generate batches ) .
verbose
int
Verbosity mode, 0 or 1.
Verbosity mode 0 or 1 .
steps
Optional[int]
Total number of steps (batches of samples) before declaring the prediction round finished.
Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, ``predict``
will run until the input dataset is exhausted.
Total number of steps ( batches of samples ) before declaring the prediction round finished . Ignored with the default value of ` ` None ` ` . If x is a ` ` tf . data ` ` dataset and ` ` steps ` ` is None ` ` predict ` ` will run until the input dataset is exhausted .
max_queue_size
int
Integer. Used for generator or ``keras.utils.Sequence`` input only. Maximum size for
the generator queue (default: 10).
Integer . Used for generator or ` ` keras . utils . Sequence ` ` input only . Maximum size for the generator queue ( default : 10 ) .
workers
int
Used for generator or ``keras.utils.Sequence`` input only. Maximum number of processes
to spin up when using process-based threading. If unspecified, ``workers`` will default to 1. If 0, will
execute the generator on the main thread.
Used for generator or ` ` keras . utils . Sequence ` ` input only . Maximum number of processes to spin up when using process - based threading . If unspecified ` ` workers ` ` will default to 1 . If 0 will execute the generator on the main thread .
use_multiprocessing
bool
Used for generator or ``keras.utils.Sequence`` input only. If ``True``,
use process-based threading. If unspecified, ``use_multiprocessing`` will default to ``False``.
Note that because this implementation relies on multiprocessing, you should not pass non-picklable
arguments to the generator as they can't be passed easily to children processes.
Used for generator or ` ` keras . utils . Sequence ` ` input only . If ` ` True ` ` use process - based threading . If unspecified ` ` use_multiprocessing ` ` will default to ` ` False ` ` . Note that because this implementation relies on multiprocessing you should not pass non - picklable arguments to the generator as they can ' t be passed easily to children processes .