TrainCTLearnModel#

class ctlearn.tools.TrainCTLearnModel(*args: t.Any, **kwargs: t.Any)[source]#

Bases: Tool

Base tool to train a ~ctlearn.core.model.CTLearnModel on R1/DL1a data.

The tool holds configurations and set up functions.

Attributes Summary

aliases

batch_size

Size of the batch to train the neural network.

classes

dl1dh_reader_type

early_stopping

Early stopping parameters for the Keras callback or the PyTorch scheduler.

file_pattern_background

List of specific file pattern for matching files in input_dir_background

file_pattern_signal

List of specific file pattern for matching files in input_dir_signal

input_dir_background

Input directory for background events

input_dir_signal

Input directory for signal events

lr_reducing

Learning rate reducing parameters for the Keras callback or the PyTorch scheduler.

model_type

Model type to be used in the Keras or PyTorch framework.

n_epochs

Number of epochs to train the neural network.

optimizer

Optimizer to use for training.

output_dir

Output directory for the trained reconstructor.

random_seed

Random seed for shuffling the data before the training/validation split and after the end of an epoch.

reco_tasks

List of reconstruction tasks to perform.

save_best_validation_only

Set whether to save the best validation checkpoint only.

sort_by_intensity

Set whether to sort the telescope images by intensity in the data loader.

stack_telescope_images

Set whether to stack the telescope images in the data loader.

validation_split

Fraction of the data to use for validation

Methods Summary

finish()

Perform final cleanup and save metadata after the core logic completes.

setup()

Initialize the tool configuration, validate parameters, and setup data handlers.

setup_framework()

This is an abstract method for the setup of the framework-specific training tool.

write_provenance()

Write the provenance log and a second one in the output directory.

Attributes Documentation

aliases = {'background': 'TrainCTLearnModel.input_dir_background', 'batch-size': 'TrainCTLearnModel.batch_size', 'n-epochs': 'TrainCTLearnModel.n_epochs', 'pattern-background': 'TrainCTLearnModel.file_pattern_background', 'pattern-signal': 'TrainCTLearnModel.file_pattern_signal', 'random-seed': 'TrainCTLearnModel.random_seed', 'reco': 'TrainCTLearnModel.reco_tasks', 'save-best-val': 'TrainCTLearnModel.save_best_validation_only', 'signal': 'TrainCTLearnModel.input_dir_signal', ('o', 'output'): 'TrainCTLearnModel.output_dir'}#
batch_size#

Size of the batch to train the neural network.

classes = [<class 'ctlearn.core.model.CTLearnModel'>, <class 'dl1_data_handler.reader.DLDataReader'>, <class 'dl1_data_handler.reader.DLImageReader'>, <class 'dl1_data_handler.reader.DLWaveformReader'>, <class 'dl1_data_handler.reader.DLFeatureVectorReader'>]#
dl1dh_reader_type#

. Possible values: []

early_stopping#

Early stopping parameters for the Keras callback or the PyTorch scheduler. E.g. {‘monitor’: ‘val_loss’, ‘patience’: 4, ‘verbose’: 1, ‘restore_best_weights’: True}.

file_pattern_background#

List of specific file pattern for matching files in input_dir_background

file_pattern_signal#

List of specific file pattern for matching files in input_dir_signal

input_dir_background#

Input directory for background events

input_dir_signal#

Input directory for signal events

lr_reducing#

Learning rate reducing parameters for the Keras callback or the PyTorch scheduler. E.g. {‘factor’: 0.5, ‘patience’: 5, ‘min_delta’: 0.01, ‘min_lr’: 0.000001}.

model_type#

Model type to be used in the Keras or PyTorch framework. The framework is determined by the inherited tools being used.

n_epochs#

Number of epochs to train the neural network.

optimizer#

Optimizer to use for training. E.g. {‘name’: ‘Adam’, ‘base_learning_rate’: 0.0001, ‘adam_epsilon’: 1.0e-8}.

output_dir#

Output directory for the trained reconstructor.

random_seed#

Random seed for shuffling the data before the training/validation split and after the end of an epoch.

reco_tasks#

List of reconstruction tasks to perform. ‘type’: classification of the primary particle type; ‘energy’: regression of the primary particle energy; ‘cameradirection’: reconstruction of the primary particle arrival direction in camera coordinates; ‘skydirection’: reconstruction of the primary particle arrival direction in sky coordinates.

save_best_validation_only#

Set whether to save the best validation checkpoint only.

sort_by_intensity#

Set whether to sort the telescope images by intensity in the data loader. Requires DLDataReader mode to be stereo.

stack_telescope_images#

Set whether to stack the telescope images in the data loader. Requires DLDataReader mode to be stereo.

validation_split#

Fraction of the data to use for validation

Methods Documentation

finish()[source]#

Perform final cleanup and save metadata after the core logic completes.

This method writes provenance data (such as configuration and execution context) to the output file, finalizes tables, and ensures all file handlers are safely closed.

setup()[source]#

Initialize the tool configuration, validate parameters, and setup data handlers.

This method is the first part of the tool execution lifecycle. It validates input arguments, sets up the configuration dictionary, configures the output file, and prepares the DataReader to ensure everything is ready before the core processing begins.

abstractmethod setup_framework()[source]#

This is an abstract method for the setup of the framework-specific training tool.

write_provenance()[source]#

Write the provenance log and a second one in the output directory.