Object Condensation Loss Functions and Utilities
The Object Condensation loss - developed by Jan Kieseler - is now being used by several groups in high energy physics for both track reconstruction and shower reconstruction in calorimeters.
Several implementations of this idea already exist, but often they are maintained by very few people. This repository aims to provide an easy to use implementation for both the TensorFlow and PyTorch backend.
Existing Implementations:
- cms-pepr [TensorFlow]
- mlpf [PyTorch]
- gnn-tracking [PyTorch]
Installation
python3 -m pip install -e 'object_condensation[pytorch]'
# or
python3 -m pip install -e 'object_condensation[tensorflow]'
Development setup
For the development setup, clone this repository and also add the dev and
testing extra options, e.g.,
python3 -m pip install -e '.[pytorch,dev,testing]'
Please also install pre-commit:
python3 -m pip install pre-commit
pre-commit install # in top-level directory of repository
Conventions
Implementations
Default
condensation_loss is a straightforward implementation that is easy to read and
to verify. It is used as baseline.
Tiger
condensation_loss_tiger saves memory by "masking instead of multiplying".
Consider the repulsive loss: It is an aggregation of potentials between
condensation points (CPs) and individual nodes. If these potentials are taken to
be hinge losses relu(1-dist), then they vanish for most CP-node pairs
(assuming a sufficiently well-trained model).
Compare now the following two implementation strategies (where dist is the
CP-node distance matrix):
# Simplified by assuming that all points belong to repulsive potential
# Strategy 1
v_rep = sum(relu(1 - dist))
# Strategy 2 (tiger)
rep_mask = dist < 1
v_rep = sum((1 - dist)[rep_mask])
In strategy 1, pytorch will keep all elements of dist in memory for
backpropagation (even though most of the relu-differentials will be 0). In
strategy 2 (because the mask is detached from the computational graph), the
number of elements to backpropagate with will be greatly reduced.
However, there is still one problem: What if our latent space collapses at some
point (or at the beginning of the training)? This would result in batches with a
greatly increased memory consumption, possibly crashing the run. To counter
this, an additional parameter max_n_rep is introduced. If the number of
repulsive pairs (rep_mask.sum() in the example above) exceeds max_n_rep,
then rep_mask will sample max_n_rep elements and upweight them by
n_rep/max_n_rep. To check whether this approximation is being used,
condensation_loss_tiger will return n_rep in addition to the losses.
Metadata
Release files for object-condensation 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| object_condensation-1.1.0.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| object_condensation-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.1 kB
Release files / object_condensation-1.1.0.tar.gz
| Download URL | object_condensation-1.1.0.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73840913500b0f5524ecea3ee97029d5dc54cd162fbcfde676f9500dd8d36178
|
|
BLAKE2b-256 checksum How to use checksums |
a339ed7cbde4b62345efa26a3f02b0cde0b17b9beb37675e5bc6d5d299c794fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / object_condensation-1.1.0-py3-none-any.whl
| Download URL | object_condensation-1.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9604593bcd4dd884e79efca091129785025a7097cb4d7abd7761602290eefd15
|
|
BLAKE2b-256 checksum How to use checksums |
42be789b88e14ae474196f060ca10a4916b1d728c34ea86f10cc2a8f383dc191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|