Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
79caedc
add pytorch template
tjarkmiener Mar 27, 2025
feae15e
First commit with new structure to support MultiDLFrameworks
Mar 28, 2025
ed53c87
some bug fixed and refactored some part
Mar 31, 2025
0f88ecc
refactored to avoid dependencies with tensorflow and pytorch. Added t…
Mar 31, 2025
899317b
fixed a missing var when using pytorch and removed commented code.
Apr 4, 2025
5a53710
Added DataLoader in Factory format
Apr 24, 2025
dc2b18c
Fix unit test??
Apr 24, 2025
ef870c9
fixed some bugs and fixed framework parameter
Apr 24, 2025
d339494
Added nets, load checkpoints in pytorch
Apr 25, 2025
e8615f5
fixed unit test
Apr 28, 2025
6caef05
formated code (round 1) and fixed a function that does not exist in p…
Apr 28, 2025
d59bcb6
fixed the training command binary
May 6, 2025
49205a9
Fixed flags in training and fixed a bug in validation index
May 14, 2025
5b81fb0
Fixed __main__ and minor changes
May 22, 2025
7926e8c
refactored keras files and fixed minor issues...
May 23, 2025
0b77156
added first sketch of prediction
May 26, 2025
52466bc
fixed _predict_with_model
May 26, 2025
fc8fae7
updated pytorch_loader
May 27, 2025
548ddf5
skeleton for training in pytorch
May 27, 2025
78f1e1b
fixed cuda memory problem in pytorch
May 28, 2025
6ff757b
fixed parameter log saving and added missing files
May 28, 2025
0da2621
added some comments
Jun 3, 2025
578db9e
fixed some bugs in training and dataloader
Jun 3, 2025
3d91d13
fixing training direction
Jun 4, 2025
7b09b86
cleaning up pytorch training module.
Jun 6, 2025
37f10be
added the fix for CI
Jun 6, 2025
8177bd5
removed unused code
Jun 6, 2025
6e6ce9c
fixed minor bugs
Jun 6, 2025
6ffbf9f
removed unused call
Jun 6, 2025
91f7c75
fixed some bugs in task type. Still there is a bug to fix
Jun 9, 2025
9baeec0
fixed the bug in Type training (blocking)
Jun 10, 2025
19eac76
Added Augmentation and removed unused code.
Jun 10, 2025
27ab9ec
Added Diffusion model and adapted the type loss
Jun 15, 2025
30a7285
Fixed Diffusion Regression code and plot bug fix
Jun 24, 2025
00c1170
clean up and added DBB in diffusion model
Jun 25, 2025
674a922
fixed some minor bugs
Jun 30, 2025
575daae
rem,oved commented code and added gpu memory trick
Jul 2, 2025
2208a23
modification in training and added another network for testing
Jul 15, 2025
2ec8dac
fixed bug in pytorch loader
Jul 21, 2025
a08265d
Adds new models
cpozogonzalez Jul 24, 2025
f34ae12
Update the git ignore
cpozogonzalez Jul 24, 2025
2fef763
Change the pyproyect file, to the new structure of folders
cpozogonzalez May 26, 2025
cecc3dd
Add the Subarray Descriptions and refactoring the predict task using …
cpozogonzalez May 28, 2025
abb7241
Separete the model and update the references
cpozogonzalez May 28, 2025
4e5f853
Add some changes in the predictions tasks
cpozogonzalez May 30, 2025
55067fe
Fix the problems related with the predict model and add the loading bar
cpozogonzalez Jun 12, 2025
a61be79
Add the MC dl2 predictions
cpozogonzalez Jul 2, 2025
fd37df1
Minor changes and optimization
cpozogonzalez Jul 4, 2025
1e2cd85
Support the last dl1-data-handler version
cpozogonzalez Jul 7, 2025
b2662ee
Fix the pytorch loader and add some changes in the Pylithing validation
cpozogonzalez Jul 29, 2025
ae66a8f
Refactoring CTLearnPL
cpozogonzalez Sep 1, 2025
5bb253c
Update the predictions tools and the ThinResNet model DBB
cpozogonzalez Sep 1, 2025
e7f2558
Add the warning message about the imbalance classes.
cpozogonzalez Sep 2, 2025
afee303
Add the class weight informations
cpozogonzalez Sep 15, 2025
b3593ae
Remove the weight calculation from the energy and cameradirrection tasks
cpozogonzalez Sep 15, 2025
8381454
Add the warnings for class weights
cpozogonzalez Sep 16, 2025
c4830f2
Add the weight only if the task is type, inside the CTLearnPL.py
cpozogonzalez Sep 16, 2025
b215a7b
Update the pytorch dataloader unit test
cpozogonzalez Sep 16, 2025
a160b16
Fix the problems with preditions
cpozogonzalez Sep 23, 2025
e7486d7
Update the feuture vectors storage
cpozogonzalez Sep 30, 2025
a854081
Remove the comment in the imports
cpozogonzalez Oct 2, 2025
bfc6c20
Apply some changes to solve the problems after rebase
cpozogonzalez Oct 21, 2025
8ae0a01
Update the test CI, to be more conservative with the space, and updat…
cpozogonzalez Oct 21, 2025
0d15985
Separete, the env_files in to differents (pytorch and tensorflow) and…
cpozogonzalez Oct 21, 2025
1e83841
Update the name in the env_file and change the CI
cpozogonzalez Oct 21, 2025
dc80ad4
Fix the predict problems after the rebase
cpozogonzalez Oct 31, 2025
2e42a18
Optimaze batch size
cpozogonzalez Oct 31, 2025
12990ad
Update the enviroments files/*.env
cpozogonzalez Nov 12, 2025
4c7c6fd
Add some comments in all the functions and class and the multiGPU tra…
cpozogonzalez Jan 7, 2026
332f234
Add the log scaling
cpozogonzalez Jan 19, 2026
f78199f
Unify the keras and pytorch pipelines with the CTApipe Traitlets
cpozogonzalez Jul 8, 2026
6f73f3f
Update the unit test and fix the onnx train problems
cpozogonzalez Jul 8, 2026
9abade2
Update the env files
cpozogonzalez Jul 8, 2026
25935fe
Change the name of the envioroments
cpozogonzalez Jul 8, 2026
6009bd3
Solve the problem in the FLoat loading
cpozogonzalez Jul 9, 2026
997e256
Add the numbers of workers etc options for the dataloader.
cpozogonzalez Jul 20, 2026
45ea6bc
Add a warning in the pytroch onxx train
cpozogonzalez Jul 20, 2026
982fc71
Add the Pytorch Keras Resnet Model
cpozogonzalez Jul 21, 2026
d5cd9a3
Update the enviroment files
cpozogonzalez Jul 21, 2026
790143e
Change the energy criterion by default to mean
cpozogonzalez Jul 21, 2026
e951976
Solve some bug after the rebase
cpozogonzalez Jul 21, 2026
a61a306
Update the CI to include test
cpozogonzalez Jul 22, 2026
5a238b8
Fix the CI
cpozogonzalez Jul 22, 2026
92dae04
Solving flake 8 problems
cpozogonzalez Jul 22, 2026
03efde1
Fix test
cpozogonzalez Jul 22, 2026
5470007
install tf and torch in same env and run CI with the same job
tjarkmiener Jul 23, 2026
c7d1b2e
run latest and lowest supported versions of tensorflow and torch
tjarkmiener Jul 23, 2026
bfe0961
run Ci with schedule at 2:00 UTC
tjarkmiener Jul 23, 2026
78c0d59
fix minimal torch version to >=2.2.X
tjarkmiener Jul 23, 2026
34cbfbb
Add the opncv in the pyproject
cpozogonzalez Jul 23, 2026
a36ac31
Fix the test
cpozogonzalez Jul 23, 2026
a09087b
make abstract level of singleCNN and ResNet to inherit the different …
tjarkmiener Jul 21, 2026
77ef080
fix some model set up for keras/pytorch
tjarkmiener Jul 21, 2026
9fbf5de
fix pytorch models
tjarkmiener Jul 21, 2026
b5ded08
remove unused imports
tjarkmiener Jul 21, 2026
822e39b
added tests for models in keras and pytorch
tjarkmiener Jul 22, 2026
44071df
update pytorch model
tjarkmiener Jul 22, 2026
18f8f35
fix keras ResNet model
tjarkmiener Jul 22, 2026
62a217f
fix tests for keras and pytorch models
tjarkmiener Jul 22, 2026
3d5fdfa
change activation function in test models
tjarkmiener Jul 22, 2026
38db4b2
add random seed
tjarkmiener Jul 22, 2026
502d28c
fix models and polish tests (WIP)
tjarkmiener Jul 23, 2026
312c88a
fix models and CI for ResNet models
tjarkmiener Jul 24, 2026
73a4ab3
fix bug where reduction ratio and input channel lead to filter number…
tjarkmiener Jul 24, 2026
2175726
test also attention layers in ResNet
tjarkmiener Jul 24, 2026
6d67e24
fix __all__ for pytorch models
tjarkmiener Jul 24, 2026
a6f0dba
only use cpu torch pypi for CI and organize cache in CI
tjarkmiener Jul 24, 2026
89b0023
fix torch vision
tjarkmiener Jul 24, 2026
7a300a9
fix some stuff
tjarkmiener Jul 24, 2026
3b672fd
added isolated attention layer tests
tjarkmiener Jul 24, 2026
78de216
Merge pull request #277 from ctlearn-project/fix_pytorch_rebase
tjarkmiener Jul 27, 2026
269d6b1
Change the loader and the base tain model to normlize the images by d…
cpozogonzalez Jul 27, 2026
9976052
Merge branch 'pytorch_support' of github.com:ctlearn-project/ctlearn …
cpozogonzalez Jul 27, 2026
72bd37b
Update the test on the CI
cpozogonzalez Jul 27, 2026
aa5585e
Fix the CI; Try to change the model import, remove the model_collecti…
cpozogonzalez Jul 27, 2026
50c861b
Fix the test_model file
cpozogonzalez Jul 27, 2026
1b9ae42
Remove the log from the ctlearn and leaved in the dl1-data-handeler a…
cpozogonzalez Jul 28, 2026
9d17794
Update all the files for the data to provida only one images as imput…
cpozogonzalez Jul 28, 2026
a8bf6a7
Fix the test
cpozogonzalez Jul 28, 2026
231efa9
Change the architectur for the dirrection
cpozogonzalez Jul 29, 2026
ce2e070
Fix the test
cpozogonzalez Jul 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203, W503
25 changes: 19 additions & 6 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: CI

on:
push:
branches:
- "**"
tags:
- "**"
branches: ["**"]
tags: ["**"]
pull_request:
workflow_dispatch:
schedule:
- cron: "0 2 * * *" # Daily at 02:00 UTC

jobs:
build:
Expand All @@ -17,14 +17,22 @@ jobs:
python-version: ['3.12', '3.13', '3.14']
dl1dh-version: ['latest', 'nightly']
tensorflow-version: ['latest', '2.16.*']
torch-version: ['latest', '2.2.*']
exclude:
- python-version: '3.13'
tensorflow-version: '2.16.*'
- python-version: '3.14'
tensorflow-version: '2.16.*'
- python-version: '3.13'
torch-version: '2.2.*'
- python-version: '3.14'
torch-version: '2.2.*'
max-parallel: 6
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.dl1dh-version == 'nightly' || matrix.python-version == '3.14' }}
env:
PIP_NO_CACHE_DIR: "1"
PIP_EXTRA_INDEX_URL: "https://download.pytorch.org/whl/cpu"
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -61,6 +69,11 @@ jobs:
else
pip install "tensorflow==${{ matrix.tensorflow-version }}"
fi
if [ "${{ matrix.torch-version }}" = "latest" ]; then
pip install --upgrade torch torchvision
else
pip install "torch==${{ matrix.torch-version }}" torchvision
fi

- name: Add MKL_THREADING_LAYER variable
run: echo "MKL_THREADING_LAYER=GNU" >> $GITHUB_ENV
Expand All @@ -76,8 +89,8 @@ jobs:
run: |
source $HOME/miniconda/etc/profile.d/conda.sh
conda activate ctlearn
pip install -e .

pip install -e .[tests]
- name: Run pytest
run: |
source $HOME/miniconda/etc/profile.d/conda.sh
Expand Down
25 changes: 23 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ctlearn/_version.py

output_dir2/
*.swp
*.swo
*.gemini
Expand All @@ -12,13 +12,34 @@ ctlearn/_version.py
*.png
*.csv
*~
*.log
.vscode/
launcher_workspace/
*.h5

output_dir2/
output_dir/
.vscode/
# Compiled Python files
__pycache__/
*.py[cod]
.DS_Store
*.egg-info/
dist

.pytest_cache/*.log
# Sphinx documentation
docs/build/
build/
# Default pytorch output
run/
test/
*.se2
*.jar
*.puml
mc_tjark/
calibration/
test_local_cristian/

test/prepare_file.py
test_local_cristian/
*.txt
21 changes: 19 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
FROM python:3.12 AS builder

# Install git (needed for setuptools_scm during build) and build tool

RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir build

# Copy source code needed for the build
WORKDIR /repo
COPY ./pyproject.toml MANIFEST.in ./
COPY ./ctlearn ./ctlearn/
# If .git is truly needed for versioning by setuptools_scm, copy it. Otherwise, omit.
COPY ./.git ./.git/
RUN pip install --no-cache-dir build

# Copy source code needed for the build
WORKDIR /repo
COPY ./pyproject.toml MANIFEST.in ./
Expand All @@ -18,14 +27,22 @@ COPY ./.git ./.git/
RUN python -m build --wheel

# Stage 2: Create the final runtime image BASED ON NVIDIA's TF image
# TODO what version to use ? after 24.?? TF 2.14 is not found in the container
FROM nvcr.io/nvidia/tensorflow:24.01-tf2-py3

# Copy only the built wheel from the builder stage's dist directory
# Build the wheel

# Stage 2: Create the final runtime image BASED ON NVIDIA's TF image

FROM nvcr.io/nvidia/tensorflow:25.02-tf2-py3
# Copy only the built wheel from the builder stage's dist directory
COPY --from=builder /repo/dist /tmp/dist

# Install the ctlearn wheel using pip from the NVIDIA base image
# Install the ctlearn wheel using pip from the NVIDIA base image
RUN python -m pip install --no-cache-dir /tmp/dist/* \
&& rm -r /tmp/dist

RUN addgroup --system ctlearn && adduser --system --group ctlearn
USER ctlearn

USER ctlearn
43 changes: 43 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ The lastest version fo this package can be installed as a pip package:

See the documentation for further information like `installation instructions for the IT-cluster <https://ctlearn.readthedocs.io/en/latest/installation.html#install-a-released-version>`_, `installation instructions for developers <https://ctlearn.readthedocs.io/en/latest/installation.html#installing-with-pip-setuptools-from-source-for-development>`_, `package usage <https://ctlearn.readthedocs.io/en/stable/usage.html>`_, and `dependencies <https://ctlearn.readthedocs.io/en/stable/installation.html#dependencies>`_ among other topics.

Running CTLearn Training and Prediction
---------------------------------------

CTLearn provides a unified command line interface (CLI) using `ctapipe`'s ``Tool`` and ``Component`` systems, supporting both the **Keras** and **PyTorch** deep learning frameworks.

Launching training
~~~~~~~~~~~~~~~~~~

You can launch a training run using the unified tool ``ctlearn-train``. To run with a specific framework, set the ``--framework`` option (choices: ``keras``, ``pytorch``):

.. code-block:: bash

# Launch training with PyTorch
ctlearn-train --framework=pytorch --output ./my_output_dir --signal /path/to/signal/h5/ --pattern-signal "*.dl1.h5" --reco energy --n_epochs=10 --batch_size=32

# Launch training with Keras
ctlearn-train --framework=keras --output ./my_output_dir --signal /path/to/signal/h5/ --pattern-signal "*.dl1.h5" --reco energy --n_epochs=10 --batch_size=32

Common Training Command Options:
* ``--framework``: Deep learning framework to use (``keras`` or ``pytorch``).
* ``-o``, ``--output``: Directory to save experiment checkpoints, parameters, and logs.
* ``--signal``: Directory containing signal HDF5 data files.
* ``--pattern-signal``: File name pattern for signal files (e.g. ``*.dl1.h5``).
* ``--reco``: Tasks to train (e.g. ``type``, ``energy``, ``cameradirection``, ``skydirection``). Multiple tasks can be provided.
* ``--n_epochs``: Number of epochs to train.
* ``--batch_size``: Batch size for training.
* ``--save_onnx=True``: Export the trained model to ONNX format.
* ``--load_onnx_model=PATH``: Load an existing ONNX model to train/fine-tune.
* ``--overwrite``: Overwrite the output directory if it already exists.

Launching prediction
~~~~~~~~~~~~~~~~~~~~

Similarly, predictions on test/observation data can be executed using the unified prediction tools (for monoscopic or stereoscopic mode):

.. code-block:: bash

# Monoscopic prediction with PyTorch
ctlearn-predict-mono-model --framework=pytorch --output ./pred_results --signal /path/to/test/h5/ --pattern-signal "*.dl1.h5" --energy_checkpoint /path/to/checkpoint.pth

# Monoscopic prediction with Keras
ctlearn-predict-mono-model --framework=keras --output ./pred_results --signal /path/to/test/h5/ --pattern-signal "*.dl1.h5" --energy_checkpoint /path/to/keras_model/

Citing this software
--------------------

Expand Down
11 changes: 11 additions & 0 deletions condaenv.vowayxih.requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
numba
tensorflow>=2.14,<2.15
dl1_data_handler>=0.14.1,<0.15
pydot
pytorch_lightning
deepspeed
onnx
onnxsim
torch==2.5.0
torchvision==0.20.0
torchaudio==2.5.0
Loading
Loading