nip.parameters.agents.ImageClassificationAgentParameters#

class nip.parameters.agents.ImageClassificationAgentParameters(agent_lr_factor: ~nip.parameters.agents.LrFactors | dict | None = None, body_lr_factor: ~nip.parameters.agents.LrFactors | dict | None = None, update_schedule: ~nip.parameters.update_schedule.AgentUpdateSchedule = ConstantUpdateSchedule(), use_manual_architecture: bool = False, normalize_message_history: bool = False, load_checkpoint_and_parameters: bool = False, checkpoint_entity: str = <factory>, checkpoint_project: str = <factory>, checkpoint_run_id: str | None = None, checkpoint_version: str = 'latest', use_orthogonal_initialisation: bool = True, orthogonal_initialisation_gain: float = 1.0, activation_function: ~typing.Literal['relu', 'tanh', 'sigmoid'] = 'tanh', building_block_type: ~typing.Literal['conv2d', 'residual_basic'] = 'conv2d', num_blocks_per_group: int = 2, kernel_size: int = 3, stride: int = 1, pretrained_embeddings_model: str | None = None, pretrained_embedding_channels: int = 64, d_latent_pixel_selector: int = 16, num_latent_pixel_selector_layers: int = 2, d_decider: int = 16, num_decider_layers: int = 2, include_round_in_decider: bool = True, d_linear_message_selector: int = 16, num_linear_message_selector_layers: int = 2, d_value: int = 16, num_value_layers: int = 2, include_round_in_value: bool = True)[source]#

Additional parameters for agents in the image classification experiment.

An image classification network is composed of several groups of building blocks, such as convolutional layers. Each group contains several building blocks.

Parameters:
  • activation_function (ActivationType) – The activation function to use.

  • building_block_type (ImageBuildingBlockType) – The type of building block to use in the agents’s CNN (e.g. convolutional layer).

  • num_blocks_per_group (int) – The number of building blocks in each group in the agents’s CNN.

  • kernel_size (int) – The kernel size of the building blocks in the agents’s CNN.

  • stride (int) – The stride of the building blocks in the agents’s CNN.

  • pretrained_embeddings_model (str or None) – If not None, specifies a pretrained model to load. This is usually either of the form “{hf_user}/{model_name}_{dataset}”, where hf_user is a HuggingFace Hub username, or “{model_name}”, which resolves to “{HF_PRETRAINED_MODELS_USER}/{model_name}_{hyper_params.dataset}”, where HF_PRETRAINED_MODELS_USER is defined in the constants module. The last-layer embeddings will be included in the model architecture.

  • pretrained_embedding_channels (int) – The number of channels used to represent the pretrained embeddings. The pretrained embeddings are resized to this number of channels by using a 1x1 convolution.

  • d_latent_pixel_selector (int) – The dimension of the hidden layer in the agents’s MLP which selects a latent pixel to send as a message.

  • num_latent_pixel_selector_layers (int) – The number of layers in the agents’s latent pixel selector MLP.

  • d_decider (int) – The dimension of the hidden layer in the agents’s MLP which decides whether continue exchanging messages or to guess.

  • num_decider_layers (int) – The number of layers in the agents’s decider MLP.

  • include_round_in_decider (bool) – Whether to include the round number in the agents’s decider MLP.

  • d_linear_message_selector (int) – The dimension of the hidden layer in the agents’s MLP which selects a linear message, if we’re using the linear message space.

  • num_linear_message_selector_layers (int) – The number of layers in the agents’s linear message selector MLP.

  • d_value (int) – The dimension of the hidden layer in the agents’s MLP which estimates the value function.

  • num_value_layers (int) – The number of layers in the agents’s value MLP.

  • include_round_in_value (bool) – Whether to include the round number in the agents’s value MLP.

Methods Summary

__eq__(other)

Return self==value.

__init__([agent_lr_factor, body_lr_factor, ...])

__post_init__()

__repr__()

Return repr(self).

_get_param_class_from_dict(param_dict)

Try to get the parameter class from a dictionary of serialised parameters.

construct_test_params()

Construct test parameters for the agent.

from_dict(params_dict[, ignore_extra_keys])

Create a parameters object from a dictionary.

get(address)

Get a value from the parameters object using a dot-separated address.

load_from_wandb_config(wandb_config)

Load the parameters from a W&B config dictionary.

to_dict()

Convert the parameters object to a dictionary.

Attributes

LOAD_PRESERVED_PARAMETERS

activation_function

agent_lr_factor

body_lr_factor

building_block_type

checkpoint_run_id

checkpoint_version

d_decider

d_latent_pixel_selector

d_linear_message_selector

d_value

include_round_in_decider

include_round_in_value

is_random

kernel_size

load_checkpoint_and_parameters

normalize_message_history

num_blocks_per_group

num_decider_layers

num_latent_pixel_selector_layers

num_linear_message_selector_layers

num_value_layers

orthogonal_initialisation_gain

pretrained_embedding_channels

pretrained_embeddings_model

stride

update_schedule

use_manual_architecture

use_orthogonal_initialisation

checkpoint_entity

checkpoint_project

Methods

__eq__(other)#

Return self==value.

__init__(agent_lr_factor: ~nip.parameters.agents.LrFactors | dict | None = None, body_lr_factor: ~nip.parameters.agents.LrFactors | dict | None = None, update_schedule: ~nip.parameters.update_schedule.AgentUpdateSchedule = ConstantUpdateSchedule(), use_manual_architecture: bool = False, normalize_message_history: bool = False, load_checkpoint_and_parameters: bool = False, checkpoint_entity: str = <factory>, checkpoint_project: str = <factory>, checkpoint_run_id: str | None = None, checkpoint_version: str = 'latest', use_orthogonal_initialisation: bool = True, orthogonal_initialisation_gain: float = 1.0, activation_function: ~typing.Literal['relu', 'tanh', 'sigmoid'] = 'tanh', building_block_type: ~typing.Literal['conv2d', 'residual_basic'] = 'conv2d', num_blocks_per_group: int = 2, kernel_size: int = 3, stride: int = 1, pretrained_embeddings_model: str | None = None, pretrained_embedding_channels: int = 64, d_latent_pixel_selector: int = 16, num_latent_pixel_selector_layers: int = 2, d_decider: int = 16, num_decider_layers: int = 2, include_round_in_decider: bool = True, d_linear_message_selector: int = 16, num_linear_message_selector_layers: int = 2, d_value: int = 16, num_value_layers: int = 2, include_round_in_value: bool = True) None#
__post_init__()[source]#
__repr__()#

Return repr(self).

classmethod _get_param_class_from_dict(param_dict: dict) type[ParameterValue] | None[source]#

Try to get the parameter class from a dictionary of serialised parameters.

Parameters:

param_dict (dict) – A dictionary of parameters, which may have come from a to_dict method. This dictionary may contain a _type key, which is used to determine the class of the parameter.

Returns:

param_class (type[ParameterValue] | None) – The class of the parameter, if it can be determined.

Raises:

ValueError – If the class specified in the dictionary is not a valid parameter class.

classmethod construct_test_params() ImageClassificationAgentParameters[source]#

Construct test parameters for the agent.

We use a simple architecture with one convolutional layer.

Returns:

test_params (ImageClassificationAgentParameters) – The test parameters.

classmethod from_dict(params_dict: dict, ignore_extra_keys: bool = False) AgentsParameters[source]#

Create a parameters object from a dictionary.

Parameters:
  • params_dict (dict) – A dictionary of the parameters.

  • ignore_extra_keys (bool, default=False) – If True, ignore keys in the dictionary that do not correspond to fields in the parameters object.

Returns:

hyper_params (AgentsParameters) – The parameters object.

get(address: str) Any[source]#

Get a value from the parameters object using a dot-separated address.

Parameters:

address (str) – The path to the value in the parameters object, separated by dots.

Returns:

value (Any) – The value at the address.

Raises:

KeyError – If the address does not exist.

load_from_wandb_config(wandb_config: dict)[source]#

Load the parameters from a W&B config dictionary.

Parameters:

wandb_config (dict) – The W&B config dictionary for this agent (e.g. wandb_run.config["agents"][agent_name]).

to_dict() dict[source]#

Convert the parameters object to a dictionary.

Adds the is_random parameter to the dictionary. This is not a field of the parameters object, but we want to include it in the dictionary for logging.

Returns:

params_dict (dict) – A dictionary of the parameters.