platypush/plugins/tensorflow/__init__.py
def evaluate(self,
                 model: str,
                 inputs: Union[str, np.ndarray, Iterable, Dict[str, Union[Iterable, np.ndarray]]],
                 outputs: Optional[Union[str, np.ndarray, Iterable]] = None,
                 batch_size: Optional[int] = None,
                 verbose: int = 1,
                 sample_weight: Optional[Union[np.ndarray, Iterable]] = None,
                 steps: Optional[int] = None,
                 max_queue_size: int = 10,
                 workers: int = 1,
                 use_multiprocessing: bool = False) -> Union[Dict[str, float], List[float]]:
        """
        Returns the loss value and metrics values for the model in test model.

        :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
              - Directories with images. If ``inputs`` points to a directory of images then the following
                conventions are followed:

                - The folder must contain exactly as many subfolders as the output units of your model. If
                  the model has ``output_labels`` then those subfolders should be named as the output labels.
                  Each subfolder will contain training examples that match the associated label (e.g.
                  ``positive`` will contain all the positive images and ``negative`` all the negative images).
                - ``outputs`` doesn't have to be specified.


        :param outputs: Target data. Like the input data `x`, it can be a numpy array (or array-like) or TensorFlow tensor(s).
            It should be consistent with `x` (you cannot have Numpy inputs and tensor targets, or inversely).
            If `x` is a dataset, generator, or `keras.utils.Sequence` instance, `y` should not be specified
            (since targets will be obtained from `x`).

        :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 = silent, 1 = progress bar, 2 = one line per epoch.
            Note that the progress bar is not particularly useful when
            logged to a file, so verbose=2 is recommended when not running
            interactively (eg, in a production environment).

        :param sample_weight: Optional iterable/numpy array of weights for the training samples, used for weighting
            the loss function (during training only). You can either pass a flat (1D) numpy array/iterable with the
            same length as the input samples (1:1 mapping between weights and samples), or in the case of temporal data,
            you can pass a 2D array with shape ``(samples, sequence_length)``, to apply a different weight to every
            time step of every sample. In this case you should make sure to specify ``sample_weight_mode="temporal"``
            in ``compile()``. This argument is not supported when ``x`` is a dataset, generator, or
            ``keras.utils.Sequence`` instance, instead provide the sample_weights as the third element of ``x``.

        :param steps: Total number of steps (batches of samples) before declaring the evaluation round finished.
            Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, 'evaluate'
            will run until the dataset is exhausted. This argument is not supported with array inputs.

        :param max_queue_size: Used for generator or ``keras.utils.Sequence`` input only. Maximum size for the generator
            queue. If unspecified, ``max_queue_size`` will default to 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: ``{test_metric: metric_value}`` dictionary if the ``metrics_names`` of the model are specified,
            otherwise a list with the result test metrics (loss is usually the first value).
        """

        name = model
        model = self._load_model(model)
        inputs, outputs = self._get_dataset(inputs, outputs, model)

        ret = model.evaluate(
            x=inputs,
            y=outputs,
            batch_size=batch_size,
            verbose=verbose,
            sample_weight=sample_weight,
            steps=steps,
            callbacks=self._generate_callbacks(name),
            max_queue_size=max_queue_size,
            workers=workers,
            use_multiprocessing=use_multiprocessing
        )

        ret = ret if isinstance(ret, list) else [ret]
        if not model.metrics_names:
            return ret

        return {model.metrics_names[i]: value for i, value in enumerate(ret)}

        Returns the loss value and metrics values for the model in test model.

        :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
              - Directories with images. If ``inputs`` points to a directory of images then the following
                conventions are followed:

                - The folder must contain exactly as many subfolders as the output units of your model. If
                  the model has ``output_labels`` then those subfolders should be named as the output labels.
                  Each subfolder will contain training examples that match the associated label (e.g.
                  ``positive`` will contain all the positive images and ``negative`` all the negative images).
                - ``outputs`` doesn't have to be specified.


        :param outputs: Target data. Like the input data `x`, it can be a numpy array (or array-like) or TensorFlow tensor(s).
            It should be consistent with `x` (you cannot have Numpy inputs and tensor targets, or inversely).
            If `x` is a dataset, generator, or `keras.utils.Sequence` instance, `y` should not be specified
            (since targets will be obtained from `x`).

        :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 = silent, 1 = progress bar, 2 = one line per epoch.
            Note that the progress bar is not particularly useful when
            logged to a file, so verbose=2 is recommended when not running
            interactively (eg, in a production environment).

        :param sample_weight: Optional iterable/numpy array of weights for the training samples, used for weighting
            the loss function (during training only). You can either pass a flat (1D) numpy array/iterable with the
            same length as the input samples (1:1 mapping between weights and samples), or in the case of temporal data,
            you can pass a 2D array with shape ``(samples, sequence_length)``, to apply a different weight to every
            time step of every sample. In this case you should make sure to specify ``sample_weight_mode="temporal"``
            in ``compile()``. This argument is not supported when ``x`` is a dataset, generator, or
            ``keras.utils.Sequence`` instance, instead provide the sample_weights as the third element of ``x``.

        :param steps: Total number of steps (batches of samples) before declaring the evaluation round finished.
            Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, 'evaluate'
            will run until the dataset is exhausted. This argument is not supported with array inputs.

        :param max_queue_size: Used for generator or ``keras.utils.Sequence`` input only. Maximum size for the generator
            queue. If unspecified, ``max_queue_size`` will default to 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: ``{test_metric: metric_value}`` dictionary if the ``metrics_names`` of the model are specified,
            otherwise a list with the result test metrics (loss is usually the first value).
        
Returns the loss value and metrics values for the model in test model.
Returns the loss value and metrics values for the model in test model .
def evaluate(self,
                 model: str,
                 inputs: Union[str, np.ndarray, Iterable, Dict[str, Union[Iterable, np.ndarray]]],
                 outputs: Optional[Union[str, np.ndarray, Iterable]] = None,
                 batch_size: Optional[int] = None,
                 verbose: int = 1,
                 sample_weight: Optional[Union[np.ndarray, Iterable]] = None,
                 steps: Optional[int] = None,
                 max_queue_size: int = 10,
                 workers: int = 1,
                 use_multiprocessing: bool = False) -> Union[Dict[str, float], List[float]]:
        name = model
        model = self._load_model(model)
        inputs, outputs = self._get_dataset(inputs, outputs, model)
        ret = model.evaluate(
            x=inputs,
            y=outputs,
            batch_size=batch_size,
            verbose=verbose,
            sample_weight=sample_weight,
            steps=steps,
            callbacks=self._generate_callbacks(name),
            max_queue_size=max_queue_size,
            workers=workers,
            use_multiprocessing=use_multiprocessing
        )
        ret = ret if isinstance(ret, list) else [ret]
        if not model.metrics_names:
            return ret
        return {model.metrics_names[i]: value for i, value in enumerate(ret)}
def evaluate ( self , model : str , inputs : Union [ str , np . ndarray , Iterable , Dict [ str , Union [ Iterable , np . ndarray ] ] ] , outputs : Optional [ Union [ str , np . ndarray , Iterable ] ] = None , batch_size : Optional [ int ] = None , verbose : int = 1 , sample_weight : Optional [ Union [ np . ndarray , Iterable ] ] = None , steps : Optional [ int ] = None , max_queue_size : int = 10 , workers : int = 1 , use_multiprocessing : bool = False ) -> Union [ Dict [ str , float ] , List [ float ] ] : name = model model = self . _load_model ( model ) inputs , outputs = self . _get_dataset ( inputs , outputs , model ) ret = model . evaluate ( x = inputs , y = outputs , batch_size = batch_size , verbose = verbose , sample_weight = sample_weight , steps = steps , callbacks = self . _generate_callbacks ( name ) , max_queue_size = max_queue_size , workers = workers , use_multiprocessing = use_multiprocessing ) ret = ret if isinstance ( ret , list ) else [ ret ] if not model . metrics_names : return ret return { model . metrics_names [ i ] : value for i , value in enumerate ( ret ) }
Returns the loss value and metrics values for the model in test model.
Returns the loss value and metrics values for the model in test model .
"""
        Returns the loss value and metrics values for the model in test model.

        :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
              - Directories with images. If ``inputs`` points to a directory of images then the following
                conventions are followed:

                - The folder must contain exactly as many subfolders as the output units of your model. If
                  the model has ``output_labels`` then those subfolders should be named as the output labels.
                  Each subfolder will contain training examples that match the associated label (e.g.
                  ``positive`` will contain all the positive images and ``negative`` all the negative images).
                - ``outputs`` doesn't have to be specified.


        :param outputs: Target data. Like the input data `x`, it can be a numpy array (or array-like) or TensorFlow tensor(s).
            It should be consistent with `x` (you cannot have Numpy inputs and tensor targets, or inversely).
            If `x` is a dataset, generator, or `keras.utils.Sequence` instance, `y` should not be specified
            (since targets will be obtained from `x`).

        :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 = silent, 1 = progress bar, 2 = one line per epoch.
            Note that the progress bar is not particularly useful when
            logged to a file, so verbose=2 is recommended when not running
            interactively (eg, in a production environment).

        :param sample_weight: Optional iterable/numpy array of weights for the training samples, used for weighting
            the loss function (during training only). You can either pass a flat (1D) numpy array/iterable with the
            same length as the input samples (1:1 mapping between weights and samples), or in the case of temporal data,
            you can pass a 2D array with shape ``(samples, sequence_length)``, to apply a different weight to every
            time step of every sample. In this case you should make sure to specify ``sample_weight_mode="temporal"``
            in ``compile()``. This argument is not supported when ``x`` is a dataset, generator, or
            ``keras.utils.Sequence`` instance, instead provide the sample_weights as the third element of ``x``.

        :param steps: Total number of steps (batches of samples) before declaring the evaluation round finished.
            Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, 'evaluate'
            will run until the dataset is exhausted. This argument is not supported with array inputs.

        :param max_queue_size: Used for generator or ``keras.utils.Sequence`` input only. Maximum size for the generator
            queue. If unspecified, ``max_queue_size`` will default to 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: ``{test_metric: metric_value}`` dictionary if the ``metrics_names`` of the model are specified,
            otherwise a list with the result test metrics (loss is usually the first value).
        """
``{test_metric: metric_value}`` dictionary if the ``metrics_names`` of the model are specified,
otherwise a list with the result test metrics (loss is usually the first value).
` ` { test_metric : metric_value } ` ` dictionary if the ` ` metrics_names ` ` of the model are specified otherwise a list with the result test metrics ( loss is usually the first value ) .
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
Directories with images. If ``inputs`` points to a directory of images then the following
conventions are followed.

The folder must contain exactly as many subfolders as the output units of your model. If
the model has ``output_labels`` then those subfolders should be named as the output labels.
Each subfolder will contain training examples that match the associated label .
``outputs`` doesn't have to be specified.
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 Directories with images . If ` ` inputs ` ` points to a directory of images then the following conventions are followed . The folder must contain exactly as many subfolders as the output units of your model . If the model has ` ` output_labels ` ` then those subfolders should be named as the output labels . Each subfolder will contain training examples that match the associated label . ` ` outputs ` ` doesn ' t have to be specified .
outputs
Optional[Union[str, np.ndarray, Iterable]]
Target data. Like the input data `x`, it can be a numpy array (or array-like) or TensorFlow tensor(s).
It should be consistent with `x` (you cannot have Numpy inputs and tensor targets, or inversely).
If `x` is a dataset, generator, or `keras.utils.Sequence` instance, `y` should not be specified
(since targets will be obtained from `x`).
Target data . Like the input data ` x ` it can be a numpy array ( or array - like ) or TensorFlow tensor ( s ) . It should be consistent with ` x ` ( you cannot have Numpy inputs and tensor targets or inversely ) . If ` x ` is a dataset generator or ` keras . utils . Sequence ` instance ` y ` should not be specified ( since targets will be obtained from ` x ` ) .
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 = silent, 1 = progress bar, 2 = one line per epoch.
Note that the progress bar is not particularly useful when
logged to a file, so verbose=2 is recommended when not running
interactively .
Verbosity mode . 0 = silent 1 = progress bar 2 = one line per epoch . Note that the progress bar is not particularly useful when logged to a file so verbose = 2 is recommended when not running interactively .
sample_weight
Optional[Union[np.ndarray, Iterable]]
Optional iterable/numpy array of weights for the training samples, used for weighting
the loss function (during training only). You can either pass a flat (1D) numpy array/iterable with the
same length as the input samples (1:1 mapping between weights and samples), or in the case of temporal data,
you can pass a 2D array with shape ``(samples, sequence_length)``, to apply a different weight to every
time step of every sample. In this case you should make sure to specify ``sample_weight_mode="temporal"``
in ``compile()``. This argument is not supported when ``x`` is a dataset, generator, or
``keras.utils.Sequence`` instance, instead provide the sample_weights as the third element of ``x``.
Optional iterable / numpy array of weights for the training samples used for weighting the loss function ( during training only ) . You can either pass a flat ( 1D ) numpy array / iterable with the same length as the input samples ( 1 : 1 mapping between weights and samples ) or in the case of temporal data you can pass a 2D array with shape ` ` ( samples sequence_length ) ` ` to apply a different weight to every time step of every sample . In this case you should make sure to specify ` ` sample_weight_mode = " temporal " ` ` in ` ` compile () ` ` . This argument is not supported when ` ` x ` ` is a dataset generator or ` ` keras . utils . Sequence ` ` instance instead provide the sample_weights as the third element of ` ` x ` ` .
steps
Optional[int]
Total number of steps (batches of samples) before declaring the evaluation round finished.
Ignored with the default value of ``None``. If x is a ``tf.data`` dataset and ``steps`` is None, 'evaluate'
will run until the dataset is exhausted. This argument is not supported with array inputs.
Total number of steps ( batches of samples ) before declaring the evaluation round finished . Ignored with the default value of ` ` None ` ` . If x is a ` ` tf . data ` ` dataset and ` ` steps ` ` is None ' evaluate ' will run until the dataset is exhausted . This argument is not supported with array inputs .
max_queue_size
int
Used for generator or ``keras.utils.Sequence`` input only. Maximum size for the generator
queue. If unspecified, ``max_queue_size`` will default to 10.
Used for generator or ` ` keras . utils . Sequence ` ` input only . Maximum size for the generator queue . If unspecified ` ` max_queue_size ` ` will default to 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 .