TrainCTLearnPyTorchModel#

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

Bases: TrainCTLearnModel

Tool to train a ~ctlearn.core.model.CTLearnModel PyTorch-based model on R1/DL1a data.

The tool trains a CTLearn PyTorch-based model on the input data (R1 calibrated waveforms or DL1a images) and saves the trained model in the output directory. The input data is loaded from the input directories for signal and background events using the ~dl1_data_handler.reader.DLDataReader and ~dl1_data_handler.loader.DLDataLoader. The tool supports the following reconstruction tasks: - Classification of the primary particle type (gamma/proton) - Regression of the primary particle energy - Regression of the primary particle arrival direction based on the offsets in camera coordinates - Regression of the primary particle arrival direction based on the offsets in sky coordinates

Attributes Summary

description

examples

name

num_workers

Number of worker processes to use for data loading (0 means data will be loaded in the main process).

persistent_workers

Set whether to keep data loader worker processes alive between epochs.

Methods Summary

setup_framework()

Initialize the backend-specific parameters (e.g., PyTorch or Keras devices and distributed strategies).

start()

Execute the core logic of the tool.

Attributes Documentation

description = '\n    Tool to train a ``~ctlearn.core.model.CTLearnModel`` PyTorch-based model on R1/DL1a data.\n\n    The tool trains a CTLearn PyTorch-based model on the input data (R1 calibrated waveforms or DL1a images) and\n    saves the trained model in the output directory. The input data is loaded from the input directories\n    for signal and background events using the ``~dl1_data_handler.reader.DLDataReader`` and\n    ``~dl1_data_handler.loader.DLDataLoader``. The tool supports the following reconstruction tasks:\n    - Classification of the primary particle type (gamma/proton)\n    - Regression of the primary particle energy\n    - Regression of the primary particle arrival direction based on the offsets in camera coordinates\n    - Regression of the primary particle arrival direction based on the offsets in sky coordinates\n    '#
examples = '\n    To train a PyTorch-based CTLearn model for the classification of the primary particle type:\n    > ctlearn-train-pytorch-model         --signal /path/to/your/gammas_dl1_dir/         --pattern-signal "gamma_*_run1.dl1.h5"         --pattern-signal "gamma_*_run10.dl1.h5"         --background /path/to/your/protons_dl1_dir/         --pattern-background "proton_*_run1.dl1.h5"         --pattern-background "proton_*_run10.dl1.h5"         --output /path/to/your/type/         --reco type \n    To train a PyTorch-based CTLearn model for the regression of the primary particle energy:\n    > ctlearn-train-pytorch-model         --signal /path/to/your/gammas_dl1_dir/         --pattern-signal "gamma_*_run1.dl1.h5"         --pattern-signal "gamma_*_run10.dl1.h5"         --output /path/to/your/energy/         --reco energy \n    To train a PyTorch-based CTLearn model for the regression of the primary particle\n    arrival direction based on the offsets in camera coordinates:\n    > ctlearn-train-pytorch-model         --signal /path/to/your/gammas_dl1_dir/         --pattern-signal "gamma_*_run1.dl1.h5"         --pattern-signal "gamma_*_run10.dl1.h5"         --output /path/to/your/direction/         --reco cameradirection \n    To train a PyTorch-based CTLearn model for the regression of the primary particle\n    arrival direction based on the offsets in sky coordinates:\n    > ctlearn-train-pytorch-model         --signal /path/to/your/gammas_dl1_dir/         --pattern-signal "gamma_*_run1.dl1.h5"         --pattern-signal "gamma_*_run10.dl1.h5"         --output /path/to/your/direction/         --reco skydirection     '#
name = 'ctlearn-train-pytorch-model'#
num_workers#

Number of worker processes to use for data loading (0 means data will be loaded in the main process).

persistent_workers#

Set whether to keep data loader worker processes alive between epochs.

Methods Documentation

setup_framework()[source]#

Initialize the backend-specific parameters (e.g., PyTorch or Keras devices and distributed strategies).

This method ensures that the hardware accelerators (like GPUs) are properly allocated and configures things like precision mixed-training and multi-processing workers.

start()[source]#

Execute the core logic of the tool.

Depending on the tool, this method either orchestrates the training and validation loops across epochs, or it iterates through the input dataset to generate and save model predictions to the output file.