hyrax.models.hyrax_cnn#

Attributes#

Classes#

HyraxCNN

This CNN is designed to work with datasets that are prepared with Hyrax's HSC Data Set class.

Module Contents#

logger[source]#
class HyraxCNN(config, data_sample=None)[source]#

Bases: torch.nn.Module

This CNN is designed to work with datasets that are prepared with Hyrax’s HSC Data Set class.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

config[source]#
conv1[source]#
pool[source]#
conv2[source]#
fc1[source]#
fc2[source]#
fc3[source]#
conv2d_output_size(input_size, kernel_size, padding=0, stride=1, dilation=1) int[source]#
pool2d_output_size(input_size, kernel_size, stride, padding=0, dilation=1) int[source]#
forward(x)[source]#
train_batch(batch)[source]#

This function contains the logic for a single training step that will process a single batch of data. i.e. the contents of the inner loop of a ML training process.

Parameters:

batch (tuple) – A tuple containing the inputs and labels for the current batch.

Returns:

Current loss value – Dictionary containing the loss value for the current batch.

Return type:

dict

validate_batch(batch)[source]#

This function contains the logic for a single validation step that will process a single batch of data. i.e. the contents of the inner loop of a ML validation process. In this case it is identical to test_batch.

Parameters:

batch (tuple) – A tuple containing the inputs and labels for the current batch.

Returns:

Current loss value – Dictionary containing the loss value for the current batch.

Return type:

dict

test_batch(batch)[source]#

This function contains the logic for a single testing step that will process a single batch of data. i.e. the contents of the inner loop of a ML testing process. In this case, it is identical to validate_batch.

Parameters:

batch (tuple) – A tuple containing the inputs and labels for the current batch.

Returns:

Current loss value – Dictionary containing the loss value for the current batch.

Return type:

dict

infer_batch(batch)[source]#

This function contains the logic for a single inference step that will process a single batch of data. i.e. the contents of the inner loop of a ML inference process.

Parameters:

batch (tuple) – A tuple containing the inputs and labels for the current batch.

Returns:

Model outputs – Tensor containing the model outputs for the current batch.

Return type:

Tensor

static prepare_inputs(data_dict) tuple[source]#

Extract image and label arrays from the batch dictionary.

This static method is the interface between the data pipeline and the model. Override it on the model class to reshape or select fields from the collated batch to match the inputs your model expects.

Hyrax will convert the returned arrays to PyTorch tensors and move them to the appropriate device automatically.

Parameters:

data_dict (dict) – The collated batch dictionary produced by the data pipeline. Expected to contain a "data" key with "image" and optionally "label" fields.

Returns:

inputs – A tuple of (image, label) as float32 and int64 arrays respectively.

Return type:

tuple of numpy.ndarray