torch-geopooling 1.0.0rc3__cp311-cp311-macosx_11_0_arm64.whl → 1.0.1__cp311-cp311-macosx_11_0_arm64.whl

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.

Potentially problematic release.


This version of torch-geopooling might be problematic. Click here for more details.

Binary file
@@ -0,0 +1,3 @@
1
+ from typing import Final
2
+
3
+ __version__: Final[str] = "1.0.1"
@@ -271,10 +271,12 @@ class AdaptiveFunction(autograd.Function):
271
271
  weight, input = ctx.saved_tensors
272
272
  tiles, w = cls.sparse_ravel(weight)
273
273
 
274
- grad_weight_out = cls.backward_impl(grad_values, tiles, w, input, ctx.exterior, *ctx.params) # type: ignore
275
- grad_weight_out = cls.sparse_unravel(tiles, grad_weight_out, size=weight.size())
274
+ grad_weight_dense = cls.backward_impl(
275
+ grad_values, tiles, w, input, ctx.exterior, *ctx.params
276
+ ) # type: ignore
277
+ grad_weight_sparse = cls.sparse_unravel(tiles, grad_weight_dense, size=weight.size())
276
278
 
277
- return grad_weight_out.coalesce(), None, None, None, None
279
+ return grad_weight_sparse.coalesce(), None, None, None, None
278
280
 
279
281
  @classmethod
280
282
  def func(
@@ -17,6 +17,7 @@ import pytest
17
17
  import torch
18
18
 
19
19
  from torch_geopooling.functional import (
20
+ AdaptiveFunction,
20
21
  adaptive_quad_pool2d,
21
22
  adaptive_avg_quad_pool2d,
22
23
  adaptive_max_quad_pool2d,
@@ -26,6 +27,20 @@ from torch_geopooling.functional import (
26
27
  )
27
28
 
28
29
 
30
+ def test_adaptive_function_ravel() -> None:
31
+ size = (2, 2, 2, 1)
32
+ tiles = torch.tensor([[0, 0, 0], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]], dtype=torch.int64)
33
+
34
+ weight = torch.tensor([[1.0], [2.0], [3.0], [4.0], [5.0]], dtype=torch.float64)
35
+
36
+ sparse = AdaptiveFunction.sparse_unravel(tiles, weight, size=size)
37
+ torch.testing.assert_close(sparse.to_dense().to_sparse_coo(), sparse)
38
+
39
+ tiles_out, weight_out = AdaptiveFunction.sparse_ravel(sparse)
40
+ torch.testing.assert_close(tiles_out, tiles)
41
+ torch.testing.assert_close(weight_out, weight)
42
+
43
+
29
44
  @pytest.mark.parametrize(
30
45
  "function",
31
46
  [
torch_geopooling/nn.py CHANGED
@@ -91,7 +91,12 @@ class _AdaptiveQuadPool(nn.Module):
91
91
  def initialize_parameters(self) -> None:
92
92
  # The weight for adaptive operation should be sparse, since training operation
93
93
  # results in a dynamic change of the underlying quadtree.
94
- weight_size = (self.max_depth, 1 << self.max_depth, 1 << self.max_depth, self.feature_dim)
94
+ weight_size = (
95
+ self.max_depth + 1,
96
+ 1 << self.max_depth,
97
+ 1 << self.max_depth,
98
+ self.feature_dim,
99
+ )
95
100
  self.weight = nn.Parameter(torch.sparse_coo_tensor(size=weight_size, dtype=torch.float64))
96
101
 
97
102
  @property
@@ -19,6 +19,7 @@ import pytest
19
19
  import torch
20
20
  from shapely.geometry import Polygon
21
21
  from torch import nn
22
+ from torch.optim import SGD
22
23
  from torch.nn import L1Loss
23
24
 
24
25
  from torch_geopooling.nn import (
@@ -56,6 +57,43 @@ def test_adaptive_quad_pool2d_gradient(module_class: Type[nn.Module]) -> None:
56
57
  assert pool.weight.grad.sum().item() == pytest.approx(-1)
57
58
 
58
59
 
60
+ def test_adaptive_quad_pool2d_optimize() -> None:
61
+ pool = AdaptiveQuadPool2d(1, (-180, -90, 360, 180), max_depth=1)
62
+
63
+ # Input coordinates are simply centers of the level-1 quads.
64
+ x_true = torch.tensor(
65
+ [[90.0, 45.0], [90.0, -45.0], [-90.0, -45.0], [-90.0, 45.0]], dtype=torch.float64
66
+ )
67
+ y_true = torch.tensor([[10.0], [20.0], [30.0], [40.0]], dtype=torch.float64)
68
+ y_tile = [[1, 1, 1], [1, 1, 0], [1, 0, 0], [1, 0, 1]]
69
+
70
+ optim = SGD(pool.parameters(), lr=0.01)
71
+ loss_fn = nn.L1Loss()
72
+
73
+ for i in range(20000):
74
+ optim.zero_grad()
75
+
76
+ y_pred = pool(x_true)
77
+ loss = loss_fn(y_pred, y_true)
78
+ loss.backward()
79
+
80
+ optim.step()
81
+
82
+ # Ensure that model converged with a small loss.
83
+ assert pytest.approx(0.0, abs=1e-1) == loss.detach().item()
84
+
85
+ # Ensure that weights that pooling operation learned are the same as in the
86
+ # target matrix (y_true).
87
+ weight = pool.weight.to_dense()
88
+
89
+ for i, tile in enumerate(y_tile):
90
+ z, x, y = tile
91
+ expect_weight = y_true[i].item()
92
+ actual_weight = weight[z, x, y].detach().item()
93
+
94
+ assert pytest.approx(expect_weight, abs=1e-1) == actual_weight, f"tile {tile} is wrong"
95
+
96
+
59
97
  @pytest.mark.parametrize(
60
98
  "module_class",
61
99
  [
@@ -83,3 +121,38 @@ def test_quad_pool2d_gradient(module_class: Type[nn.Module]) -> None:
83
121
 
84
122
  assert pool.weight.grad is not None
85
123
  assert pool.weight.grad.sum().item() == pytest.approx(-1)
124
+
125
+
126
+ def test_quad_pool2d_optimize() -> None:
127
+ poly = Polygon([(-180, -90), (-180, 90), (180, 90), (180, -90)])
128
+ pool = QuadPool2d(1, poly, (-180, -90, 360, 180), max_depth=1)
129
+
130
+ x_true = torch.tensor(
131
+ [[90.0, 45.0], [90.0, -45.0], [-90.0, -45.0], [-90.0, 45.0]], dtype=torch.float64
132
+ )
133
+ y_true = torch.tensor([[10.0], [20.0], [30.0], [40.0]], dtype=torch.float64)
134
+ y_tile = [(1, 1, 1), (1, 1, 0), (1, 0, 0), (1, 0, 1)]
135
+
136
+ optim = SGD(pool.parameters(), lr=0.01)
137
+ loss_fn = nn.L1Loss()
138
+
139
+ for i in range(20000):
140
+ optim.zero_grad()
141
+
142
+ y_pred = pool(x_true)
143
+ loss = loss_fn(y_pred, y_true)
144
+ loss.backward()
145
+
146
+ optim.step()
147
+
148
+ # Ensure that model converged with a small loss.
149
+ assert pytest.approx(0.0, abs=1e-1) == loss.detach().item()
150
+
151
+ actual_tiles = {}
152
+ for i in range(pool.tiles.size(0)):
153
+ tile = tuple(pool.tiles[i].detach().tolist())
154
+ actual_tiles[tile] = pool.weight[i, 0].detach().item()
155
+
156
+ for tile, expect_weight in zip(y_tile, y_true[:, 0].tolist()):
157
+ actual_weight = actual_tiles[tile]
158
+ assert pytest.approx(expect_weight, abs=1e-1) == actual_weight, f"tile {tile} is wrong"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: torch-geopooling
3
- Version: 1.0.0rc3
3
+ Version: 1.0.1
4
4
  Summary: The geospatial pooling modules for neural networks in PyTorch
5
5
  Author-email: Yakau Bubnou <girokompass@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -680,7 +680,7 @@ License: GNU GENERAL PUBLIC LICENSE
680
680
 
681
681
  Project-URL: homepage, https://github.com/ybubnov/torch_geopooling
682
682
  Project-URL: source, https://github.com/ybubnov/torch_geopooling
683
- Classifier: Development Status :: 4 - Beta
683
+ Classifier: Development Status :: 5 - Production/Stable
684
684
  Classifier: Intended Audience :: Developers
685
685
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
686
686
  Classifier: Topic :: Scientific/Engineering
@@ -699,17 +699,21 @@ Classifier: Operating System :: MacOS
699
699
  Requires-Python: >=3.9
700
700
  Description-Content-Type: text/markdown
701
701
  License-File: LICENSE
702
- Requires-Dist: shapely >=2.0.0
703
- Requires-Dist: torch <2.3.0,>=2.2.0
702
+ Requires-Dist: shapely>=2.0.0
703
+ Requires-Dist: torch<2.3.0,>=2.2.0
704
704
  Provides-Extra: test
705
- Requires-Dist: pytest >=8.0.0 ; extra == 'test'
706
- Requires-Dist: numpy >=1.4.0 ; extra == 'test'
705
+ Requires-Dist: pytest>=8.0.0; extra == "test"
706
+ Requires-Dist: numpy>=1.4.0; extra == "test"
707
707
 
708
708
  # Torch Geopooling - The geospatial pooling library for PyTorch
709
709
 
710
710
  The Torch Geopooling library is an extension for PyTorch library that provide extra layers for
711
711
  building geospatial neural networks.
712
712
 
713
+ Here is an example of how you can use modules from Torch Geopooling library to train neural
714
+ networks predicting geospatial features:
715
+ ![example](docs/index.png)
716
+
713
717
  ## Installation
714
718
 
715
719
  The library is distributed as PyPI package, to install that package, execute the following
@@ -0,0 +1,17 @@
1
+ torch_geopooling/_C.cpython-311-darwin.so,sha256=EDFwAndoKc5inME-p5rlD64GPJu4-6Fnn52KcEcqpeI,534584
2
+ torch_geopooling/__init__.py,sha256=g3zAIxXO6CdrT0zoTlfM3K86LeTWJcgIsqPTqYmhBMQ,60
3
+ torch_geopooling/functional.py,sha256=MuJfPW_RC4slgzWBO2ngQIBTzlZXeW7DBqV3ooIOSw4,12060
4
+ torch_geopooling/functional_test.py,sha256=Sfv6bSe4DIB-y1xYVwavZoyIdu0bwARGdr8woOx7F7U,2997
5
+ torch_geopooling/nn.py,sha256=_NnGB45dWTZy4MQokFfmJL3as-EPVU3liwOuAmWbv1Y,14219
6
+ torch_geopooling/nn_test.py,sha256=zKoyK1f9SUJGhR8pt4wvocmVICoA6nPWPeUMvKKbwY8,4786
7
+ torch_geopooling/return_types.py,sha256=QhIKf_qxpppzuZzUrT-VacfbvZ6zKmSRu-WZOqL8wuE,898
8
+ torch_geopooling/tiling.py,sha256=f1g0Gf__5zIOafZzDkwO62t9OqMDMBEYVtM2HXB5X0Y,2553
9
+ torch_geopooling/transforms.py,sha256=NHPBgx1L4-1745xNO_PvLuvbMH6DWi2rs1ViuRyBQAY,3635
10
+ torch_geopooling/transforms_test.py,sha256=Cqp4VVObBVrc8HQ7uxkpe1EsQ5NxXrCI77BiUqngLXw,1196
11
+ torch_geopooling/__bind__/python_module.cc,sha256=5K04tRT62XTVsZhY2EE4r4bBTz4mA4IwEkw5adPzo58,576
12
+ torch_geopooling-1.0.1.dist-info/LICENSE,sha256=jLc4eyvG8hqxH4AdKAjK2DwXoP68qjHiGfq8eP5ubBI,35069
13
+ torch_geopooling-1.0.1.dist-info/METADATA,sha256=CgOBHIw38QEgF4TIAVvnVYWz-RlPgW_60AbdJkK_J-E,44364
14
+ torch_geopooling-1.0.1.dist-info/WHEEL,sha256=LFVzND6nAdWMS-norKkn42oL86bk-j1PiLvh1xzptX0,110
15
+ torch_geopooling-1.0.1.dist-info/dependency_links.txt,sha256=JqLDcYHtEaQB51V72n3gAJvRd36bpoPk9qgTbot-Lx4,37
16
+ torch_geopooling-1.0.1.dist-info/top_level.txt,sha256=3geTL2nsLvybdtr1psWIE6h63B1LuyIIyWWv0rDafTk,17
17
+ torch_geopooling-1.0.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: bdist_wheel (0.44.0)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp311-cp311-macosx_11_0_arm64
5
5
 
@@ -1,17 +0,0 @@
1
- torch_geopooling/_C.cpython-311-darwin.so,sha256=DA6hfL7S9IkTInk0UjUy-adV93SBOzNzgIRdxUkcItk,518504
2
- torch_geopooling/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- torch_geopooling/functional.py,sha256=rZrh30K4IlxG3lGQ1_C8wrL7MKS9yIT-NSEkcM21A_k,12028
4
- torch_geopooling/functional_test.py,sha256=WZ7GePj1f8jp8cxNrnrDoHXnJeEeBUNVnFySPgEDl2I,2406
5
- torch_geopooling/nn.py,sha256=A_pozkqIfjhmOL7BDvTV2bJBv7nXD3Wi8nAlbl_rSEs,14156
6
- torch_geopooling/nn_test.py,sha256=4Aj3CcI8KG0parOyruAHZCCnC51CvSacTZ0AxTs16Gc,2359
7
- torch_geopooling/return_types.py,sha256=QhIKf_qxpppzuZzUrT-VacfbvZ6zKmSRu-WZOqL8wuE,898
8
- torch_geopooling/tiling.py,sha256=f1g0Gf__5zIOafZzDkwO62t9OqMDMBEYVtM2HXB5X0Y,2553
9
- torch_geopooling/transforms.py,sha256=NHPBgx1L4-1745xNO_PvLuvbMH6DWi2rs1ViuRyBQAY,3635
10
- torch_geopooling/transforms_test.py,sha256=Cqp4VVObBVrc8HQ7uxkpe1EsQ5NxXrCI77BiUqngLXw,1196
11
- torch_geopooling/__bind__/python_module.cc,sha256=5K04tRT62XTVsZhY2EE4r4bBTz4mA4IwEkw5adPzo58,576
12
- torch_geopooling-1.0.0rc3.dist-info/LICENSE,sha256=jLc4eyvG8hqxH4AdKAjK2DwXoP68qjHiGfq8eP5ubBI,35069
13
- torch_geopooling-1.0.0rc3.dist-info/METADATA,sha256=e81OTHBrYbB3X4ZdjIKovz-ch5tEywdIMf4_oNNq8co,44199
14
- torch_geopooling-1.0.0rc3.dist-info/WHEEL,sha256=sieEctgmsyAnWfDYOiunmkigyyjGmYuUaApm_YItwoI,110
15
- torch_geopooling-1.0.0rc3.dist-info/dependency_links.txt,sha256=JqLDcYHtEaQB51V72n3gAJvRd36bpoPk9qgTbot-Lx4,37
16
- torch_geopooling-1.0.0rc3.dist-info/top_level.txt,sha256=3geTL2nsLvybdtr1psWIE6h63B1LuyIIyWWv0rDafTk,17
17
- torch_geopooling-1.0.0rc3.dist-info/RECORD,,