gan

GAN metrics.

Classes

DiscriminatorLoss The Discriminator loss value.
EncoderLoss Encoder Loss value.
EncodingAccuracy Generator and Encoder accuracy performance.
GeneratorLoss Generator loss value.
InceptionScore Inception Score Metric.
class ashpy.metrics.gan.DiscriminatorLoss(name='d_loss', model_selection_operator=None, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'))[source]

Bases: ashpy.metrics.metric.Metric

The Discriminator loss value.

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

Initialize the Metric.

Parameters:
  • name (str) – Name of the metric.
  • 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.gan.GANContext) – An AshPy Context Object that carries all the information the Metric needs.
Return type:None
class ashpy.metrics.gan.EncoderLoss(name='e_loss', model_selection_operator=None, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'))[source]

Bases: ashpy.metrics.metric.Metric

Encoder Loss value.

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

Initialize the Metric.

Parameters:
  • name (str) – Name of the metric.
  • 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.gan.GANEncoderContext) – An AshPy Context Object that carries all the information the Metric needs.
Return type:None
class ashpy.metrics.gan.EncodingAccuracy(classifier, name='encoding_accuracy', model_selection_operator=None, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'))[source]

Bases: ashpy.metrics.classifier.ClassifierMetric

Generator 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, name='encoding_accuracy', model_selection_operator=None, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/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.
  • name (str) – Name of the metric.
  • 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(name='g_loss', model_selection_operator=None, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'))[source]

Bases: ashpy.metrics.metric.Metric

Generator loss value.

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

Initialize the Metric.

Parameters:
  • name (str) – Name of the metric.
  • 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, name='inception_score', model_selection_operator=<built-in function gt>, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/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.

See Improved Techniques for Training GANs [1].

[1]Improved Techniques for Training GANs https://arxiv.org/abs/1606.03498
__init__(inception, name='inception_score', model_selection_operator=<built-in function gt>, logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'))[source]

Initialize the Metric.

Parameters:
  • inception (tf.keras.Model) – Keras Inception model.
  • name (str) – Name of the metric.
  • 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=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/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.
Return type:

Model

Returns:

tf.keras.Model – The Inception Model.

inception_score(images)[source]

Compute the Inception Score.

Parameters:images (list of [numpy.ndarray]) – A list of ndarray of generated images of 299x299 of size.
Return type:Tensor
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