Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auto-tiling and fix weighting after merging #7

Merged
merged 23 commits into from
Dec 14, 2021
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5351226
add auto-tiling and fix weighting after merging
renerichter Sep 27, 2021
fdc38c8
add minimal overlap
renerichter Sep 29, 2021
6db742e
Merge remote-tracking branch 'origin/master' into renerichter-rl
the-lay Nov 8, 2021
c10c04c
Code linting
the-lay Nov 9, 2021
a14beea
Added ndarray types; Throw an exception in case of non-matching data.…
the-lay Nov 18, 2021
ab58cd3
Removing flattop window since it has negative values
the-lay Nov 18, 2021
46e948b
Code linting
the-lay Nov 19, 2021
a6e56e4
Added dtype keyword to Merger that specifies dtype of data buffer
the-lay Dec 10, 2021
4474666
Added apply_padding method; overlap now can be given as a numpy array
the-lay Dec 10, 2021
3640e2d
Small documentation fixes
the-lay Dec 10, 2021
ae79a80
Saving Merger data_visits is now optional
the-lay Dec 10, 2021
ebac20a
Fixed data visits check
the-lay Dec 10, 2021
51cc98c
Added an uncovered edge case test
the-lay Dec 11, 2021
5eee24b
Added test for Merger with disabled save_visits
the-lay Dec 11, 2021
aa86420
Refactored normalization by weights in merging
the-lay Dec 11, 2021
69ab5c9
Fixed explicit padding for odd data shapes
the-lay Dec 11, 2021
d0a559e
Hiding division by zero warning when normalizing by weight
the-lay Dec 11, 2021
f0b1f9b
Code linting
the-lay Dec 11, 2021
bd1cd9e
Updated documentation
the-lay Dec 11, 2021
f032b09
Fixing trying to submit coveralls on pull requests
the-lay Dec 11, 2021
054b5d7
Teaser image generated script now actually tiles and merges the image :)
the-lay Dec 11, 2021
a02c0c6
Merger buffer dtypes are now hardcoded, optional casting to specified…
the-lay Dec 11, 2021
c230be4
Refactored extra padding system and updated examples
the-lay Dec 12, 2021
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
Prev Previous commit
Next Next commit
Added dtype keyword to Merger that specifies dtype of data buffer
  • Loading branch information
the-lay committed Dec 10, 2021
commit a6e56e4cfc6ca8c99a4a3f4fddc0d91547105717
16 changes: 12 additions & 4 deletions tiler/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
tiler: Tiler,
window: Union[None, str, np.ndarray] = None,
logits: int = 0,
dtype: np.dtype = np.float64,
atol: float = 1e-10,
):
"""Merger precomputes everything for merging together tiles created by given Tiler.
Expand All @@ -73,6 +74,9 @@ def __init__(
Default is None which creates a boxcar window (constant 1s).

logits (int): Specify whether to add logits dimensions in front of the data array. Default is `0`.

dtype (np.dtype): Specify dtype of buffer that holds added tiles. Default is `np.float64`.

"""

self.tiler = tiler
Expand All @@ -86,6 +90,7 @@ def __init__(
self.logits = int(logits)

# Generate data and normalization arrays
self.dtype = dtype
self.data = self.data_visits = self.weights_sum = None
self.reset()

Expand Down Expand Up @@ -187,15 +192,15 @@ def reset(self) -> None:

# Image holds sum of all processed tiles multiplied by the window
if self.logits:
self.data = np.zeros((self.logits, *padded_data_shape))
self.data = np.zeros((self.logits, *padded_data_shape), dtype=self.dtype)
else:
self.data = np.zeros(padded_data_shape)
self.data = np.zeros(padded_data_shape, dtype=self.dtype)

# Normalization array holds the number of times each element was visited
self.data_visits = np.zeros(padded_data_shape, dtype=np.uint32)

# Total data window (weight) coefficients
self.weights_sum = np.zeros(padded_data_shape)
self.weights_sum = np.zeros(padded_data_shape, dtype=np.float64)

def add(self, tile_id: int, data: np.ndarray) -> None:
"""Adds `tile_id`-th tile into Merger.
Expand Down Expand Up @@ -233,6 +238,10 @@ def add(self, tile_id: int, data: np.ndarray) -> None:
f"must be less or equal than tile shape ({expected_tile_shape})."
)

# Check for dtype mismatch
if self.dtype != data.dtype:
raise ValueError(f"Passed data dtype ({data.dtype}) must match Merger initialized dtype ({self.dtype}).")

# Select coordinates for data
shape_diff = expected_tile_shape - data_shape
a, b = self.tiler.get_tile_bbox_position(tile_id, with_channel_dim=True)
Expand All @@ -243,7 +252,6 @@ def add(self, tile_id: int, data: np.ndarray) -> None:
for diff in shape_diff
]

# TODO check for self.data and data dtypes mismatch?
if self.logits > 0:
self.data[tuple([slice(None, None, None)] + sl)] += (
data * self.window[tuple(win_sl[1:])]
Expand Down