universal_attention/summaries.py
def plot_summaries(
    images: np.ndarray,
    labels: np.ndarray,
    model: tf.keras.Model,
    ds_info: tfds.core.DatasetInfo,
    step: int,
) -> None:
    """
    Plot classification performance and attention on a set of images.

    Parameters
    ----------
    images: np.ndarray
        Images to use.
    labels: np.ndarray
        True integer labels for the images.
    model: np.ndarray
        A Model: images -> AttendingClassifierOutput.
    ds_info: tfds.core.DatasetInfo
        Info object for the dataset associated with these images.
    step: int
        X-axis for the summaries.
    """
    if not FLAGS.num_debug_images:
        return

    logits, attention_maps = model.predict_on_batch(
        images[: FLAGS.num_debug_images]
    )
    probs = tf.nn.softmax(logits, axis=-1)

    tf.summary.image(
        "Input images",
        _make_examples_summary(
            images=images,
            label_fn=ds_info.features["label"].int2str,
            true_labels=labels,
            pred_probs=probs.numpy(),
        ),
        step=step,
        max_outputs=FLAGS.num_debug_images,
    )

    for name, attention in attention_maps.items():
        tf.summary.histogram(
            f"Attention distribution ({name})", attention, step=step
        )

        tf.summary.image(
            f"Attention maps ({name})",
            _make_attention_summary(
                images,
                label_fn=ds_info.features["label"].int2str,
                true_labels=labels,
                pred_probs=probs.numpy(),
                attention=attention.numpy(),
            ),
            step=step,
            max_outputs=FLAGS.num_debug_images,
        )

    Plot classification performance and attention on a set of images.

    Parameters
    ----------
    images: np.ndarray
        Images to use.
    labels: np.ndarray
        True integer labels for the images.
    model: np.ndarray
        A Model: images -> AttendingClassifierOutput.
    ds_info: tfds.core.DatasetInfo
        Info object for the dataset associated with these images.
    step: int
        X-axis for the summaries.
    
Plot classification performance and attention on a set of images.
Parameters


Plot classification performance and attention on a set of images . Parameters
def plot_summaries(
    images: np.ndarray,
    labels: np.ndarray,
    model: tf.keras.Model,
    ds_info: tfds.core.DatasetInfo,
    step: int,
) -> None:
    if not FLAGS.num_debug_images:
        return
    logits, attention_maps = model.predict_on_batch(
        images[: FLAGS.num_debug_images]
    )
    probs = tf.nn.softmax(logits, axis=-1)
    tf.summary.image(
        "Input images",
        _make_examples_summary(
            images=images,
            label_fn=ds_info.features["label"].int2str,
            true_labels=labels,
            pred_probs=probs.numpy(),
        ),
        step=step,
        max_outputs=FLAGS.num_debug_images,
    )
    for name, attention in attention_maps.items():
        tf.summary.histogram(
            f"Attention distribution ({name})", attention, step=step
        )
        tf.summary.image(
            f"Attention maps ({name})",
            _make_attention_summary(
                images,
                label_fn=ds_info.features["label"].int2str,
                true_labels=labels,
                pred_probs=probs.numpy(),
                attention=attention.numpy(),
            ),
            step=step,
            max_outputs=FLAGS.num_debug_images,
        )
def plot_summaries ( images : np . ndarray , labels : np . ndarray , model : tf . keras . Model , ds_info : tfds . core . DatasetInfo , step : int , ) -> None : if not FLAGS . num_debug_images : return logits , attention_maps = model . predict_on_batch ( images [ : FLAGS . num_debug_images ] ) probs = tf . nn . softmax ( logits , axis = - 1 ) tf . summary . image ( "Input images" , _make_examples_summary ( images = images , label_fn = ds_info . features [ "label" ] . int2str , true_labels = labels , pred_probs = probs . numpy ( ) , ) , step = step , max_outputs = FLAGS . num_debug_images , ) for name , attention in attention_maps . items ( ) : tf . summary . histogram ( f"Attention distribution ({name})" , attention , step = step ) tf . summary . image ( f"Attention maps ({name})" , _make_attention_summary ( images , label_fn = ds_info . features [ "label" ] . int2str , true_labels = labels , pred_probs = probs . numpy ( ) , attention = attention . numpy ( ) , ) , step = step , max_outputs = FLAGS . num_debug_images , )
Plot classification performance and attention on a set of images.
Plot classification performance and attention on a set of images .
"""
    Plot classification performance and attention on a set of images.

    Parameters
    ----------
    images: np.ndarray
        Images to use.
    labels: np.ndarray
        True integer labels for the images.
    model: np.ndarray
        A Model: images -> AttendingClassifierOutput.
    ds_info: tfds.core.DatasetInfo
        Info object for the dataset associated with these images.
    step: int
        X-axis for the summaries.
    """
images
np.ndarray
labels
np.ndarray
model
tf.keras.Model
ds_info
tfds.core.DatasetInfo
step
int