InceptionScore

Inheritance Diagram

Inheritance diagram of ashpy.metrics.gan.InceptionScore

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

Methods

__init__(inception[, name, …]) Initialize the Metric.
get_or_train_inception(dataset, name, …[, …]) Restore or train (and save) the Inception model.
inception_score(images) Compute the Inception Score.
update_state(context) Update the internal state of the metric, using the information from the context object.

Attributes

best_folder Retrieve the folder used to save the best model when doing model selection.
best_model_sel_file Retrieve the path to JSON file containing the measured performance of the best model.
logdir Retrieve the log directory.
metric Retrieve the tf.keras.metrics.Metric object.
model_selection_operator Retrieve the operator used for model selection.
name Retrieve the metric name.
sanitized_name all / are _.
__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