universal_attention/train.py
def train_subtask(
    classifier: tf.keras.Model,
    task: data.DatasetAndInfo,
    num_batches: int,
    plot_summaries: bool = False,
    meta_step: Optional[int] = None,
) -> None:
    """
    Use an encoder to create and train a new classifier on a meta-training
    dataset. Modifies the encoder's weights in place.

    Parameters
    ----------
    classifier: tf.keras.Model (tf.Tensor -> models.AttendingClassifierOutput)
        A classifier for this dataset. Assumed to be compiled.
    task: data.DatasetAndInfo
        A dataset yielding training batches for this subtask, and its info.
    num_batches
        How many batches to train for.
    learning_rate
        Learning rate to use for this subtask.
    plot_summaries (default: False)
        Whether to plot summaries for the first batch of this subtask.
    meta_step (default: None)
        Which step of meta-optimization we're on.
        Must be provided if plot_summaries is True.
    """
    # Show plots for the first batch of a subtask at certain steps
    if plot_summaries:
        first_batch = True
        if meta_step is None:
            raise ValueError(
                "If plot_summaries is True, meta_step must be provided."
            )

    dataset, info = task
    for images, labels in dataset["train"].take(num_batches):
        if plot_summaries and first_batch:
            summaries.plot_summaries(
                images, labels, classifier, info, meta_step  # type: ignore
            )
            first_batch = False

        classifier.train_on_batch(images, labels)

    Use an encoder to create and train a new classifier on a meta-training
    dataset. Modifies the encoder's weights in place.

    Parameters
    ----------
    classifier: tf.keras.Model (tf.Tensor -> models.AttendingClassifierOutput)
        A classifier for this dataset. Assumed to be compiled.
    task: data.DatasetAndInfo
        A dataset yielding training batches for this subtask, and its info.
    num_batches
        How many batches to train for.
    learning_rate
        Learning rate to use for this subtask.
    plot_summaries (default: False)
        Whether to plot summaries for the first batch of this subtask.
    meta_step (default: None)
        Which step of meta-optimization we're on.
        Must be provided if plot_summaries is True.
    
Use an encoder to create and train a new classifier on a meta-training
dataset. Modifies the encoder's weights in place.

Parameters


Use an encoder to create and train a new classifier on a meta - training dataset . Modifies the encoder ' s weights in place . Parameters
def train_subtask(
    classifier: tf.keras.Model,
    task: data.DatasetAndInfo,
    num_batches: int,
    plot_summaries: bool = False,
    meta_step: Optional[int] = None,
) -> None:
    if plot_summaries:
        first_batch = True
        if meta_step is None:
            raise ValueError(
                "If plot_summaries is True, meta_step must be provided."
            )
    dataset, info = task
    for images, labels in dataset["train"].take(num_batches):
        if plot_summaries and first_batch:
            summaries.plot_summaries(
                images, labels, classifier, info, meta_step  
            )
            first_batch = False
        classifier.train_on_batch(images, labels)
def train_subtask ( classifier : tf . keras . Model , task : data . DatasetAndInfo , num_batches : int , plot_summaries : bool = False , meta_step : Optional [ int ] = None , ) -> None : if plot_summaries : first_batch = True if meta_step is None : raise ValueError ( "If plot_summaries is True, meta_step must be provided." ) dataset , info = task for images , labels in dataset [ "train" ] . take ( num_batches ) : if plot_summaries and first_batch : summaries . plot_summaries ( images , labels , classifier , info , meta_step ) first_batch = False classifier . train_on_batch ( images , labels )
Use an encoder to create and train a new classifier on a meta-training
dataset.
Use an encoder to create and train a new classifier on a meta - training dataset .
"""
    Use an encoder to create and train a new classifier on a meta-training
    dataset. Modifies the encoder's weights in place.

    Parameters
    ----------
    classifier: tf.keras.Model (tf.Tensor -> models.AttendingClassifierOutput)
        A classifier for this dataset. Assumed to be compiled.
    task: data.DatasetAndInfo
        A dataset yielding training batches for this subtask, and its info.
    num_batches
        How many batches to train for.
    learning_rate
        Learning rate to use for this subtask.
    plot_summaries (default: False)
        Whether to plot summaries for the first batch of this subtask.
    meta_step (default: None)
        Which step of meta-optimization we're on.
        Must be provided if plot_summaries is True.
    """ # Show plots for the first batch of a subtask at certain steps # type: ignore
classifier
tf.keras.Model
task
data.DatasetAndInfo
num_batches
int
plot_summaries
bool
meta_step
Optional[int]