pytorch-hexagdly 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytorch_hexagdly-0.1.0/.github/workflows/publish.yml +45 -0
- pytorch_hexagdly-0.1.0/.github/workflows/test.yml +43 -0
- pytorch_hexagdly-0.1.0/.gitignore +10 -0
- pytorch_hexagdly-0.1.0/CHANGELOG.md +24 -0
- pytorch_hexagdly-0.1.0/LICENSE +22 -0
- pytorch_hexagdly-0.1.0/MANIFEST.in +1 -0
- pytorch_hexagdly-0.1.0/NOTICE.md +45 -0
- pytorch_hexagdly-0.1.0/PKG-INFO +238 -0
- pytorch_hexagdly-0.1.0/README.md +183 -0
- pytorch_hexagdly-0.1.0/conftest.py +6 -0
- pytorch_hexagdly-0.1.0/figures/explicit_next_neighbour_conv.png +0 -0
- pytorch_hexagdly-0.1.0/figures/kernel_size+stride.png +0 -0
- pytorch_hexagdly-0.1.0/figures/violating_symmetry.png +0 -0
- pytorch_hexagdly-0.1.0/notebooks/addressing_utils.py +88 -0
- pytorch_hexagdly-0.1.0/notebooks/example_utils.py +524 -0
- pytorch_hexagdly-0.1.0/notebooks/hexagdly_2d_example.ipynb +2539 -0
- pytorch_hexagdly-0.1.0/notebooks/hexagdly_cnn_example.ipynb +4355 -0
- pytorch_hexagdly-0.1.0/notebooks/hexagdly_custom_kernels_example.ipynb +1745 -0
- pytorch_hexagdly-0.1.0/notebooks/hexagdly_hex_vs_square.ipynb +3893 -0
- pytorch_hexagdly-0.1.0/notebooks/hexagdly_tools.py +143 -0
- pytorch_hexagdly-0.1.0/notebooks/how_to_apply_adressing_scheme.ipynb +3306 -0
- pytorch_hexagdly-0.1.0/pyproject.toml +65 -0
- pytorch_hexagdly-0.1.0/src/pytorch_hexagdly/__init__.py +1041 -0
- pytorch_hexagdly-0.1.0/tests/test_Conv2d.py +367 -0
- pytorch_hexagdly-0.1.0/tests/test_Conv2d_Custom.py +348 -0
- pytorch_hexagdly-0.1.0/tests/test_Conv2d_CustomKernel.py +377 -0
- pytorch_hexagdly-0.1.0/tests/test_Conv3d.py +516 -0
- pytorch_hexagdly-0.1.0/tests/test_Conv3d_CustomKernel.py +523 -0
- pytorch_hexagdly-0.1.0/tests/test_MaxPool2d.py +199 -0
- pytorch_hexagdly-0.1.0/tests/test_MaxPool3d.py +425 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Triggered by pushing a tag like v0.1.0. Uses PyPI Trusted Publishing (OIDC):
|
|
4
|
+
# no API token is stored anywhere -- PyPI verifies this workflow's identity
|
|
5
|
+
# directly. See https://docs.pypi.org/trusted-publishers/ to register it
|
|
6
|
+
# (one-time setup on pypi.org, no code change needed here).
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags:
|
|
11
|
+
- "v*"
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.11"
|
|
21
|
+
- name: Build sdist and wheel
|
|
22
|
+
run: |
|
|
23
|
+
pip install build
|
|
24
|
+
python -m build
|
|
25
|
+
- name: Check distribution metadata
|
|
26
|
+
run: |
|
|
27
|
+
pip install twine
|
|
28
|
+
twine check dist/*
|
|
29
|
+
- uses: actions/upload-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: dist
|
|
32
|
+
path: dist/
|
|
33
|
+
|
|
34
|
+
publish:
|
|
35
|
+
needs: build
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment: pypi
|
|
38
|
+
permissions:
|
|
39
|
+
id-token: write # required for Trusted Publishing
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/download-artifact@v4
|
|
42
|
+
with:
|
|
43
|
+
name: dist
|
|
44
|
+
path: dist/
|
|
45
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
|
|
23
|
+
- name: Install pytorch-hexagdly + dev deps
|
|
24
|
+
run: |
|
|
25
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
26
|
+
pip install -e ".[dev]"
|
|
27
|
+
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: pytest tests/ -v
|
|
30
|
+
|
|
31
|
+
lint:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
- uses: actions/setup-python@v5
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.11"
|
|
38
|
+
- name: Install ruff
|
|
39
|
+
run: pip install ruff
|
|
40
|
+
- name: Ruff check
|
|
41
|
+
run: ruff check src/ tests/
|
|
42
|
+
- name: Ruff format check
|
|
43
|
+
run: ruff format --check src/ tests/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
5
|
+
|
|
6
|
+
## [0.1.0] - 2026-07-02
|
|
7
|
+
|
|
8
|
+
Initial release of `pytorch-hexagdly`, a fork of
|
|
9
|
+
[HexagDLy](https://github.com/ai4iacts/hexagdly).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `share_neighbors` parameter on `Conv2d` and `Conv3d`: ties hexagonal kernel
|
|
14
|
+
weights by ring (ring 0 = center, ring *r* = the 6*r* cells at hex-distance
|
|
15
|
+
*r*) instead of giving every cell an independent weight, like TDSCAN.
|
|
16
|
+
- `depth_padding` parameter on `Conv3d`: `"same"` zero-pads the depth/time
|
|
17
|
+
axis so the temporal kernel is centred and output depth equals input depth,
|
|
18
|
+
instead of upstream's `"valid"`-only behaviour.
|
|
19
|
+
- `ring_maps_2d(n)`: utility function returning the per-sub-kernel ring-index
|
|
20
|
+
maps for kernel size `n`, derived empirically via impulse responses.
|
|
21
|
+
- PyPI packaging: `pyproject.toml` with hatchling backend, proper package
|
|
22
|
+
layout under `src/pytorch_hexagdly/`, `__version__`, and `__all__`.
|
|
23
|
+
- GitHub Actions CI: test workflow (Python 3.10/3.11/3.12) and publish workflow
|
|
24
|
+
(tag-triggered, PyPI Trusted Publishing / OIDC).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 ai4iacts (HexagDLy authors: Tim Lukas Holch, Constantin Steppa)
|
|
4
|
+
Copyright (c) 2026 Tanguy Dietrich, HEPIA, SST-1M Collaboration (pytorch-hexagdly fork)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prune tests
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Notice
|
|
2
|
+
|
|
3
|
+
`pytorch-hexagdly` is a fork of
|
|
4
|
+
[HexagDLy](https://github.com/ai4iacts/hexagdly) by Tim Lukas Holch and
|
|
5
|
+
Constantin Steppa (ai4iacts), originally developed for hexagonal convolution
|
|
6
|
+
and pooling on PyTorch in the context of Imaging Atmospheric Cherenkov
|
|
7
|
+
Telescope analysis with H.E.S.S.
|
|
8
|
+
|
|
9
|
+
This package extends the original `HexBase` sub-kernel decomposition with two
|
|
10
|
+
new features that have no equivalent in upstream HexagDLy:
|
|
11
|
+
|
|
12
|
+
- `share_neighbors`: ties the weights of a hexagonal kernel by ring (ring 0 =
|
|
13
|
+
center, ring *r* = the 6*r* cells at hex-distance *r*), instead of giving
|
|
14
|
+
every cell its own weight.
|
|
15
|
+
- `depth_padding` (`Conv3d` only): `"same"` zero-pads the depth/time axis so
|
|
16
|
+
the temporal kernel is centred and output depth equals input depth, instead of
|
|
17
|
+
HexagDLy's `"valid"`-only behaviour.
|
|
18
|
+
|
|
19
|
+
This work was developed as part of the SST-1M Collaboration / HEPIA TDSCAN
|
|
20
|
+
triggering project.
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
Both the original HexagDLy code and this fork are distributed under the MIT
|
|
25
|
+
license; see [LICENSE](LICENSE). The original copyright notice
|
|
26
|
+
(Copyright (c) 2018 ai4iacts) is preserved alongside the copyright notice for
|
|
27
|
+
this fork, as required by the MIT license.
|
|
28
|
+
|
|
29
|
+
## Citing
|
|
30
|
+
|
|
31
|
+
If you use this package, please cite the original HexagDLy paper:
|
|
32
|
+
|
|
33
|
+
```bibtex
|
|
34
|
+
@article{hexagdly_paper,
|
|
35
|
+
title = "HexagDLy—Processing hexagonally sampled data with CNNs in PyTorch",
|
|
36
|
+
author = "Constantin Steppa and Tim L. Holch",
|
|
37
|
+
journal = "SoftwareX",
|
|
38
|
+
volume = "9",
|
|
39
|
+
pages = "193 - 198",
|
|
40
|
+
year = "2019",
|
|
41
|
+
issn = "2352-7110",
|
|
42
|
+
doi = "https://doi.org/10.1016/j.softx.2019.02.010",
|
|
43
|
+
url = "https://www.sciencedirect.com/science/article/pii/S2352711018302723",
|
|
44
|
+
}
|
|
45
|
+
```
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytorch-hexagdly
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Hexagonal convolution and pooling layers for PyTorch — an extended HexagDLy fork
|
|
5
|
+
Project-URL: Homepage, https://github.com/YugnatD/pytorch-hexagdly
|
|
6
|
+
Project-URL: Source, https://github.com/YugnatD/pytorch-hexagdly
|
|
7
|
+
Project-URL: Issues, https://github.com/YugnatD/pytorch-hexagdly/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/YugnatD/pytorch-hexagdly/blob/master/CHANGELOG.md
|
|
9
|
+
Project-URL: Original (HexagDLy), https://github.com/ai4iacts/hexagdly
|
|
10
|
+
Author: Tanguy Dietrich
|
|
11
|
+
License: MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2018 ai4iacts (HexagDLy authors: Tim Lukas Holch, Constantin Steppa)
|
|
14
|
+
Copyright (c) 2026 Tanguy Dietrich, HEPIA, SST-1M Collaboration (pytorch-hexagdly fork)
|
|
15
|
+
|
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
in the Software without restriction, including without limitation the rights
|
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
SOFTWARE.
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
License-File: NOTICE.md
|
|
35
|
+
Keywords: astroparticle-physics,cherenkov,cnn,convolution,deep-learning,equivariant,geometric-deep-learning,hexagdly,hexagonal,hexagonal-convolution,hexagonal-grid,iact,neural-networks,pytorch,torch
|
|
36
|
+
Classifier: Development Status :: 4 - Beta
|
|
37
|
+
Classifier: Intended Audience :: Developers
|
|
38
|
+
Classifier: Intended Audience :: Science/Research
|
|
39
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
40
|
+
Classifier: Operating System :: OS Independent
|
|
41
|
+
Classifier: Programming Language :: Python :: 3
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
45
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
46
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
47
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
48
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
49
|
+
Requires-Python: >=3.9
|
|
50
|
+
Requires-Dist: numpy
|
|
51
|
+
Requires-Dist: torch
|
|
52
|
+
Provides-Extra: dev
|
|
53
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
54
|
+
Description-Content-Type: text/markdown
|
|
55
|
+
|
|
56
|
+
# pytorch-hexagdly — Hexagonal Convolutions for PyTorch
|
|
57
|
+
|
|
58
|
+
`pytorch-hexagdly` is a fork of [HexagDLy](https://github.com/ai4iacts/hexagdly)
|
|
59
|
+
that extends the original hexagonal convolution and pooling layers for PyTorch with
|
|
60
|
+
two new features: **ring-shared weights** (`share_neighbors`) and **depth-axis same-padding**
|
|
61
|
+
(`depth_padding="same"` on `Conv3d`).
|
|
62
|
+
|
|
63
|
+
- [Getting Started](#getting-started)
|
|
64
|
+
- [New Features](#new-features)
|
|
65
|
+
- [Preparing the Data](#preparing-the-data)
|
|
66
|
+
- [How to use pytorch-hexagdly](#how-to-use-pytorch-hexagdly)
|
|
67
|
+
- [General Concept](#general-concept)
|
|
68
|
+
- [Disclaimer](#disclaimer)
|
|
69
|
+
- [Citing HexagDLy](#citation)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## Getting Started
|
|
73
|
+
|
|
74
|
+
### Pip Installation
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
pip install pytorch-hexagdly
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import pytorch_hexagdly
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
To get the dependencies needed to run the provided [unit tests](tests) and
|
|
85
|
+
[notebooks](notebooks), add the `dev` option:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
pip install pytorch-hexagdly[dev]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Manual Installation
|
|
92
|
+
|
|
93
|
+
Requires a working installation of [PyTorch](https://github.com/pytorch/pytorch).
|
|
94
|
+
Clone the repository and install in editable mode:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
git clone https://github.com/YugnatD/pytorch-hexagdly
|
|
98
|
+
cd pytorch-hexagdly
|
|
99
|
+
pip install -e .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## New Features
|
|
104
|
+
|
|
105
|
+
### `share_neighbors` — ring-shared kernel weights
|
|
106
|
+
|
|
107
|
+
Available on `Conv2d` and `Conv3d`. When set to `True`, all cells at the same
|
|
108
|
+
hexagonal ring distance share a single weight, reducing the number of learnable
|
|
109
|
+
parameters. Ring 0 is the center pixel; ring *r* covers the 6*r* cells at
|
|
110
|
+
hex-distance *r*. This mirrors the TDSCAN triggering approach.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
import torch
|
|
114
|
+
import pytorch_hexagdly
|
|
115
|
+
|
|
116
|
+
conv = pytorch_hexagdly.Conv2d(1, 8, kernel_size=2, stride=1, share_neighbors=True)
|
|
117
|
+
x = torch.randn(1, 1, 21, 21)
|
|
118
|
+
print(conv(x).shape)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `depth_padding="same"` — temporal same-padding for `Conv3d`
|
|
122
|
+
|
|
123
|
+
When `depth_padding="same"`, the depth/time axis is zero-padded symmetrically so
|
|
124
|
+
the output depth equals the input depth. The default is `"valid"` (upstream behaviour).
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
conv3d = pytorch_hexagdly.Conv3d(1, 4, kernel_size=(3, 1), stride=1,
|
|
128
|
+
depth_padding="same")
|
|
129
|
+
x = torch.randn(1, 1, 10, 21, 21)
|
|
130
|
+
print(conv3d(x).shape) # depth dimension preserved
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## How to use pytorch-hexagdly
|
|
135
|
+
|
|
136
|
+
As `pytorch-hexagdly` is based on PyTorch, it is of advantage to be familiar with
|
|
137
|
+
PyTorch's functionalities and concepts. Before applying it, ensure that the input
|
|
138
|
+
data has the correct hexagonal layout. An [example notebook](notebooks/how_to_apply_adressing_scheme.ipynb)
|
|
139
|
+
illustrates the steps to get data into the correct format.
|
|
140
|
+
|
|
141
|
+
Basic example:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
import torch
|
|
145
|
+
import pytorch_hexagdly
|
|
146
|
+
|
|
147
|
+
kernel_size, stride = 1, 4
|
|
148
|
+
in_channels, out_channels = 1, 3
|
|
149
|
+
|
|
150
|
+
hexconv = pytorch_hexagdly.Conv2d(in_channels, out_channels, kernel_size, stride)
|
|
151
|
+
input = torch.rand(1, 1, 21, 21)
|
|
152
|
+
output = hexconv(input)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
HexagDLy uses an addressing scheme to map hexagonal grid data to a square tensor.
|
|
156
|
+
The layout from top to bottom (along tensor index 2) must be of zig-zag-edge shape
|
|
157
|
+
and from left to right (along tensor index 3) of armchair-edge shape.
|
|
158
|
+
|
|
159
|
+
Additional examples for basic use-cases are shown in the [notebooks](notebooks) folder.
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
## General Concept
|
|
163
|
+
|
|
164
|
+
As common deep learning frameworks process data on square grids, hexagonally sampled
|
|
165
|
+
data must be mapped to a square tensor. This conversion is non-trivial due to the
|
|
166
|
+
different symmetries of square (4-fold) vs hexagonal (6-fold) grids.
|
|
167
|
+
|
|
168
|
+
HexagDLy solves this by splitting each convolution kernel into sub-kernels that
|
|
169
|
+
together cover the true neighbours of a data point in the hexagonal grid. A full
|
|
170
|
+
hexagonal convolution with size 1 (next-neighbour kernel) decomposes into three
|
|
171
|
+
sub-convolutions with two different sub-kernels applied to three differently padded
|
|
172
|
+
versions of the input.
|
|
173
|
+
|
|
174
|
+

|
|
175
|
+
|
|
176
|
+
**Please note**: Operations are only performed where the center point of a kernel is
|
|
177
|
+
located within the input tensor. This could result in output columns of different
|
|
178
|
+
length; in such cases the output will be sliced according to the shortest column.
|
|
179
|
+
|
|
180
|
+

|
|
181
|
+
|
|
182
|
+

|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
## Disclaimer
|
|
186
|
+
|
|
187
|
+
`pytorch-hexagdly` is built as an easy-to-use prototyping tool to design convolutional
|
|
188
|
+
neural networks for hexagonally sampled data. The implemented methods aim for
|
|
189
|
+
flexibility rather than performance. Once a model is optimized, hard-coding kernel
|
|
190
|
+
size, stride and input dimensions will make the implementation faster.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
## Authors
|
|
194
|
+
|
|
195
|
+
**Fork (`pytorch-hexagdly`)**
|
|
196
|
+
* **Tanguy Dietrich** — HEPIA / SST-1M Collaboration
|
|
197
|
+
|
|
198
|
+
**Original HexagDLy**
|
|
199
|
+
* **Tim Lukas Holch**
|
|
200
|
+
* **Constantin Steppa**
|
|
201
|
+
|
|
202
|
+
See [NOTICE.md](NOTICE.md) for full attribution.
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT license — see [LICENSE](LICENSE).
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## Citation
|
|
211
|
+
|
|
212
|
+
If this work has helped your research, please cite the original HexagDLy paper:
|
|
213
|
+
|
|
214
|
+
```bibtex
|
|
215
|
+
@article{hexagdly_paper,
|
|
216
|
+
title = "HexagDLy—Processing hexagonally sampled data with CNNs in PyTorch",
|
|
217
|
+
author = "Constantin Steppa and Tim L. Holch",
|
|
218
|
+
journal = "SoftwareX",
|
|
219
|
+
volume = "9",
|
|
220
|
+
pages = "193 - 198",
|
|
221
|
+
year = "2019",
|
|
222
|
+
issn = "2352-7110",
|
|
223
|
+
doi = "https://doi.org/10.1016/j.softx.2019.02.010",
|
|
224
|
+
url = "https://www.sciencedirect.com/science/article/pii/S2352711018302723",
|
|
225
|
+
keywords = "Convolutional neural networks, Hexagonal grid, PyTorch, Astroparticle physics",
|
|
226
|
+
abstract = "HexagDLy is a Python-library extending the PyTorch deep learning framework with convolution and pooling operations on hexagonal grids. It aims to ease the access to convolutional neural networks for applications that rely on hexagonally sampled data as, for example, commonly found in ground-based astroparticle physics experiments."
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
HexagDLy was developed as part of a research study in ground-based gamma-ray astronomy
|
|
231
|
+
published in [Astroparticle Physics](https://doi.org/10.1016/j.astropartphys.2018.10.003).
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## Acknowledgments
|
|
235
|
+
|
|
236
|
+
The original HexagDLy project evolved by exploring new analysis techniques for Imaging
|
|
237
|
+
Atmospheric Cherenkov Telescopes with H.E.S.S. The fork was developed in the context of
|
|
238
|
+
the SST-1M Collaboration / HEPIA TDSCAN triggering project.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# pytorch-hexagdly — Hexagonal Convolutions for PyTorch
|
|
2
|
+
|
|
3
|
+
`pytorch-hexagdly` is a fork of [HexagDLy](https://github.com/ai4iacts/hexagdly)
|
|
4
|
+
that extends the original hexagonal convolution and pooling layers for PyTorch with
|
|
5
|
+
two new features: **ring-shared weights** (`share_neighbors`) and **depth-axis same-padding**
|
|
6
|
+
(`depth_padding="same"` on `Conv3d`).
|
|
7
|
+
|
|
8
|
+
- [Getting Started](#getting-started)
|
|
9
|
+
- [New Features](#new-features)
|
|
10
|
+
- [Preparing the Data](#preparing-the-data)
|
|
11
|
+
- [How to use pytorch-hexagdly](#how-to-use-pytorch-hexagdly)
|
|
12
|
+
- [General Concept](#general-concept)
|
|
13
|
+
- [Disclaimer](#disclaimer)
|
|
14
|
+
- [Citing HexagDLy](#citation)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
### Pip Installation
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
pip install pytorch-hexagdly
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import pytorch_hexagdly
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To get the dependencies needed to run the provided [unit tests](tests) and
|
|
30
|
+
[notebooks](notebooks), add the `dev` option:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install pytorch-hexagdly[dev]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Manual Installation
|
|
37
|
+
|
|
38
|
+
Requires a working installation of [PyTorch](https://github.com/pytorch/pytorch).
|
|
39
|
+
Clone the repository and install in editable mode:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
git clone https://github.com/YugnatD/pytorch-hexagdly
|
|
43
|
+
cd pytorch-hexagdly
|
|
44
|
+
pip install -e .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## New Features
|
|
49
|
+
|
|
50
|
+
### `share_neighbors` — ring-shared kernel weights
|
|
51
|
+
|
|
52
|
+
Available on `Conv2d` and `Conv3d`. When set to `True`, all cells at the same
|
|
53
|
+
hexagonal ring distance share a single weight, reducing the number of learnable
|
|
54
|
+
parameters. Ring 0 is the center pixel; ring *r* covers the 6*r* cells at
|
|
55
|
+
hex-distance *r*. This mirrors the TDSCAN triggering approach.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import torch
|
|
59
|
+
import pytorch_hexagdly
|
|
60
|
+
|
|
61
|
+
conv = pytorch_hexagdly.Conv2d(1, 8, kernel_size=2, stride=1, share_neighbors=True)
|
|
62
|
+
x = torch.randn(1, 1, 21, 21)
|
|
63
|
+
print(conv(x).shape)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `depth_padding="same"` — temporal same-padding for `Conv3d`
|
|
67
|
+
|
|
68
|
+
When `depth_padding="same"`, the depth/time axis is zero-padded symmetrically so
|
|
69
|
+
the output depth equals the input depth. The default is `"valid"` (upstream behaviour).
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
conv3d = pytorch_hexagdly.Conv3d(1, 4, kernel_size=(3, 1), stride=1,
|
|
73
|
+
depth_padding="same")
|
|
74
|
+
x = torch.randn(1, 1, 10, 21, 21)
|
|
75
|
+
print(conv3d(x).shape) # depth dimension preserved
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## How to use pytorch-hexagdly
|
|
80
|
+
|
|
81
|
+
As `pytorch-hexagdly` is based on PyTorch, it is of advantage to be familiar with
|
|
82
|
+
PyTorch's functionalities and concepts. Before applying it, ensure that the input
|
|
83
|
+
data has the correct hexagonal layout. An [example notebook](notebooks/how_to_apply_adressing_scheme.ipynb)
|
|
84
|
+
illustrates the steps to get data into the correct format.
|
|
85
|
+
|
|
86
|
+
Basic example:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import torch
|
|
90
|
+
import pytorch_hexagdly
|
|
91
|
+
|
|
92
|
+
kernel_size, stride = 1, 4
|
|
93
|
+
in_channels, out_channels = 1, 3
|
|
94
|
+
|
|
95
|
+
hexconv = pytorch_hexagdly.Conv2d(in_channels, out_channels, kernel_size, stride)
|
|
96
|
+
input = torch.rand(1, 1, 21, 21)
|
|
97
|
+
output = hexconv(input)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
HexagDLy uses an addressing scheme to map hexagonal grid data to a square tensor.
|
|
101
|
+
The layout from top to bottom (along tensor index 2) must be of zig-zag-edge shape
|
|
102
|
+
and from left to right (along tensor index 3) of armchair-edge shape.
|
|
103
|
+
|
|
104
|
+
Additional examples for basic use-cases are shown in the [notebooks](notebooks) folder.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
## General Concept
|
|
108
|
+
|
|
109
|
+
As common deep learning frameworks process data on square grids, hexagonally sampled
|
|
110
|
+
data must be mapped to a square tensor. This conversion is non-trivial due to the
|
|
111
|
+
different symmetries of square (4-fold) vs hexagonal (6-fold) grids.
|
|
112
|
+
|
|
113
|
+
HexagDLy solves this by splitting each convolution kernel into sub-kernels that
|
|
114
|
+
together cover the true neighbours of a data point in the hexagonal grid. A full
|
|
115
|
+
hexagonal convolution with size 1 (next-neighbour kernel) decomposes into three
|
|
116
|
+
sub-convolutions with two different sub-kernels applied to three differently padded
|
|
117
|
+
versions of the input.
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
**Please note**: Operations are only performed where the center point of a kernel is
|
|
122
|
+
located within the input tensor. This could result in output columns of different
|
|
123
|
+
length; in such cases the output will be sliced according to the shortest column.
|
|
124
|
+
|
|
125
|
+

|
|
126
|
+
|
|
127
|
+

|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## Disclaimer
|
|
131
|
+
|
|
132
|
+
`pytorch-hexagdly` is built as an easy-to-use prototyping tool to design convolutional
|
|
133
|
+
neural networks for hexagonally sampled data. The implemented methods aim for
|
|
134
|
+
flexibility rather than performance. Once a model is optimized, hard-coding kernel
|
|
135
|
+
size, stride and input dimensions will make the implementation faster.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Authors
|
|
139
|
+
|
|
140
|
+
**Fork (`pytorch-hexagdly`)**
|
|
141
|
+
* **Tanguy Dietrich** — HEPIA / SST-1M Collaboration
|
|
142
|
+
|
|
143
|
+
**Original HexagDLy**
|
|
144
|
+
* **Tim Lukas Holch**
|
|
145
|
+
* **Constantin Steppa**
|
|
146
|
+
|
|
147
|
+
See [NOTICE.md](NOTICE.md) for full attribution.
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT license — see [LICENSE](LICENSE).
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
## Citation
|
|
156
|
+
|
|
157
|
+
If this work has helped your research, please cite the original HexagDLy paper:
|
|
158
|
+
|
|
159
|
+
```bibtex
|
|
160
|
+
@article{hexagdly_paper,
|
|
161
|
+
title = "HexagDLy—Processing hexagonally sampled data with CNNs in PyTorch",
|
|
162
|
+
author = "Constantin Steppa and Tim L. Holch",
|
|
163
|
+
journal = "SoftwareX",
|
|
164
|
+
volume = "9",
|
|
165
|
+
pages = "193 - 198",
|
|
166
|
+
year = "2019",
|
|
167
|
+
issn = "2352-7110",
|
|
168
|
+
doi = "https://doi.org/10.1016/j.softx.2019.02.010",
|
|
169
|
+
url = "https://www.sciencedirect.com/science/article/pii/S2352711018302723",
|
|
170
|
+
keywords = "Convolutional neural networks, Hexagonal grid, PyTorch, Astroparticle physics",
|
|
171
|
+
abstract = "HexagDLy is a Python-library extending the PyTorch deep learning framework with convolution and pooling operations on hexagonal grids. It aims to ease the access to convolutional neural networks for applications that rely on hexagonally sampled data as, for example, commonly found in ground-based astroparticle physics experiments."
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
HexagDLy was developed as part of a research study in ground-based gamma-ray astronomy
|
|
176
|
+
published in [Astroparticle Physics](https://doi.org/10.1016/j.astropartphys.2018.10.003).
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
## Acknowledgments
|
|
180
|
+
|
|
181
|
+
The original HexagDLy project evolved by exploring new analysis techniques for Imaging
|
|
182
|
+
Atmospheric Cherenkov Telescopes with H.E.S.S. The fork was developed in the context of
|
|
183
|
+
the SST-1M Collaboration / HEPIA TDSCAN triggering project.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|