gan

GAN metrics.

Classes

DiscriminatorLoss

The Discriminator loss value.

EncoderLoss

Encoder Loss value.

EncodingAccuracy

Generetor and Encoder accuracy performance.

GeneratorLoss

Generator loss value.

InceptionScore

Inception Score Metric.

class ashpy.metrics.gan.DiscriminatorLoss(model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Bases: ashpy.metrics.metric.Metric

The Discriminator loss value.

__init__(model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Initialize the Metric.

Parameters
  • model_selection_operator (typing.Callable) –

    The operation that will be used when model_selection is triggered to compare the metrics, used by the update_state. Any typing.Callable behaving like an operator is accepted.

    Note

    Model selection is done ONLY if an operator is specified here.

  • logdir (str) – Path to the log dir, defaults to a log folder in the current directory.

Return type

None

update_state(context)[source]

Update the internal state of the metric, using the information from the context object.

Parameters

context (ashpy.contexts.GANContext) – An AshPy Context Object that carries all the information the Metric needs.

Return type

None

class ashpy.metrics.gan.EncoderLoss(model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Bases: ashpy.metrics.metric.Metric

Encoder Loss value.

__init__(model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Initialize the Metric.

Parameters
  • model_selection_operator (typing.Callable) –

    The operation that will be used when model_selection is triggered to compare the metrics, used by the update_state. Any typing.Callable behaving like an operator is accepted.

    Note

    Model selection is done ONLY if an operator is specified here.

  • logdir (str) – Path to the log dir, defaults to a log folder in the current directory.

Return type

None

update_state(context)[source]

Update the internal state of the metric, using the information from the context object.

Parameters

context (ashpy.contexts.GANEncoderContext) – An AshPy Context Object that carries all the information the Metric needs.

Return type

None

class ashpy.metrics.gan.EncodingAccuracy(classifier, model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Bases: ashpy.metrics.classifier.ClassifierMetric

Generetor and Encoder accuracy performance.

Measure the Generator and Encoder performance together, by classifying: G(E(x)), y using a pre-trained classified (on the dataset of x).

__init__(classifier, model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Measure the Generator and Encoder performance together.

This is done by classifying: G(E(x)), y using a pre-trained classified (on the dataset of x).

Parameters
  • classifier (tf.keras.Model) – Keras Model to use as a Classifier to measure the accuracy. Generally assumed to be the Inception Model.

  • model_selection_operator (typing.Callable) –

    The operation that will be used when model_selection is triggered to compare the metrics, used by the update_state. Any typing.Callable behaving like an operator is accepted.

    Note

    Model selection is done ONLY if an operator is specified here.

  • logdir (str) – Path to the log dir, defaults to a log folder in the current directory.

Return type

None

update_state(context)[source]

Update the internal state of the metric, using the information from the context object.

Parameters

context (ashpy.contexts.GANEncoderContext) – An AshPy Context Object that carries all the information the Metric needs.

Return type

None

class ashpy.metrics.gan.GeneratorLoss(model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Bases: ashpy.metrics.metric.Metric

Generator loss value.

__init__(model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Initialize the Metric.

Parameters
  • model_selection_operator (typing.Callable) –

    The operation that will be used when model_selection is triggered to compare the metrics, used by the update_state. Any typing.Callable behaving like an operator is accepted.

    Note

    Model selection is done ONLY if an operator is specified here.

  • logdir (str) – Path to the log dir, defaults to a log folder in the current directory.

update_state(context)[source]

Update the internal state of the metric, using the information from the context object.

Parameters

context (ashpy.contexts.GANContext) – An AshPy Context Object that carries all the information the Metric needs.

Return type

None

class ashpy.metrics.gan.InceptionScore(inception, model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Bases: ashpy.metrics.metric.Metric

Inception Score Metric.

This class is an implementation of the Inception Score technique for evaluating a GAN.

Todo

Add reference to the paper.

__init__(inception, model_selection_operator=None, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Initialize the Metric.

Parameters
  • inception (tf.keras.Model) – Keras Inception model.

  • model_selection_operator (typing.Callable) –

    The operation that will be used when model_selection is triggered to compare the metrics, used by the update_state. Any typing.Callable behaving like an operator is accepted.

    Note

    Model selection is done ONLY if an operator is specified here.

  • logdir (str) – Path to the log dir, defaults to a log folder in the current directory.

static get_or_train_inception(dataset, name, num_classes, epochs, fine_tuning=False, loss_fn=<tensorflow.python.keras.losses.SparseCategoricalCrossentropy object>, optimizer=<tensorflow.python.keras.optimizer_v2.adam.Adam object>, logdir='/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/latest/docs/source/log')[source]

Restore or train (and save) the Inception model.

Parameters
  • dataset (tf.data.Dataset) – Dataset to re-train Inception Model on.

  • name (str) – Name of this new Inception Model, used for saving it.

  • num_classes (int) – Number of classes to use for classification.

  • epochs (int) – Epochs to train the Inception model for.

  • fine_tuning (bool) – Controls wether the model will be fine-tuned or used as is.

  • loss_fn (tf.keras.losses.Loss) – Keras Loss for the model.

  • optimizer (tf.keras.optimizers.Optimizer) – Keras optimizer for the model.

  • logdir (str) – Path to the log dir, defaults to a log folder in the current directory.

Returns

tf.keras.Model – The Inception Model.

inception_score(images, splits=10)[source]

Compute the Inception Score.

Parameters
  • images (list of [numpy.ndarray]) – A list of ndarray of generated images of 299x299 of size.

  • splits (int) – The number of splits to be used during the inception score calculation.

Return type

Tuple[np.ndarray, np.ndarray]

Returns

tuple of (numpy.ndarray, numpy.ndarray) – Mean and STD.

update_state(context)[source]

Update the internal state of the metric, using the information from the context object.

Parameters

context (ashpy.contexts.ClassifierContext) – An AshPy Context holding all the information the Metric needs.

Return type

None