Skip to content

Add generic data tiling wrapper to solve padding consistency#1140

Open
ahmedemam576 wants to merge 5 commits intoterrastackai:mainfrom
ahmedemam576:feature/data-titling-wrapper
Open

Add generic data tiling wrapper to solve padding consistency#1140
ahmedemam576 wants to merge 5 commits intoterrastackai:mainfrom
ahmedemam576:feature/data-titling-wrapper

Conversation

@ahmedemam576
Copy link
Copy Markdown
Collaborator

@ahmedemam576 ahmedemam576 commented Mar 10, 2026

This PR addresses both issues #1079 and #1091

  • Implement TilingDataModuleWrapper for any LightningDataModule
  • Implement TiledDataset with on-the-fly tiling and disk caching
  • Add 16 comprehensive integration tests (all passing)
  • Support sliding/tumbling window modes with configurable overlap
  • Provide prediction stitching with smooth blending
  • Include end-to-end inference demo

- Implement TilingDataModuleWrapper for any LightningDataModule
- Implement TiledDataset with on-the-fly tiling and disk caching
- Add 16 comprehensive integration tests (all passing)
- Support sliding/tumbling window modes with configurable overlap
- Provide prediction stitching with smooth blending
- Include end-to-end inference demo
@ahmedemam576
Copy link
Copy Markdown
Collaborator Author

ahmedemam576 commented Mar 16, 2026

Updated this draft PR with example cleanup and validation.

  • Merged the standalone inference demo into examples/utils/tiling_datamodule_example.py
  • Removed redundant scripts/inference_stitching_demo.py
  • Added a self-contained runnable section: Example 8: End-to-End Inference Demo
  • Kept Example 3b illustrative and pointed to Example 8 for runnable behavior
  • Fixed GenericNonGeoSegmentationDataModule(...) example calls by adding required num_workers=0

@ahmedemam576 ahmedemam576 marked this pull request as ready for review March 16, 2026 09:48
@rosielickorish rosielickorish self-requested a review March 18, 2026 13:05
Copy link
Copy Markdown
Collaborator

@rosielickorish rosielickorish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two pytests are failing for me with these changes:

FAILED tests/test_finetune.py::test_finetune_multiple_backbones[fit-terramind_v1_base] - RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces)....
py::test_finetune_multiple_backbones_with_prediction[terramind_v1_small] - RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces)....
FAILED tests/test_finetune.


**See Also:**
- TiledDataset: Underlying dataset wrapper
- docs/tiling_datamodule_wrapper.md: Comprehensive documentation
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't exist.


print("=" * 70)
print("For more details, see:")
print(" docs/tiling_datamodule_wrapper.md")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't exist.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rosielickorish thanks for the feedback. I am gonna fix the issues

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expected a notebook to make it easy to run through an example of tiling. Would that be more useful here than this python script? Otherwise, the docstrings in the other files give a pretty good description on how to use this.

…late function

- Fix RuntimeError: 'view size is not compatible with input tensor's size and stride'
  in test_finetune_multiple_backbones tests
- Add .contiguous() after torch.nn.functional.pad() for all tensor dimensions
  (2D, 3D, 4D) in custom collate function
- Tensor padding can create non-contiguous memory layouts which fail on reshape
- Add documentation file (was untracked)
- Add Jupyter notebook tutorial demonstrating the fix and TiledDataModuleWrapper usage
- Fixes issues raised by @rosielickorish in PR review
Copy link
Copy Markdown
Collaborator

@rosielickorish rosielickorish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a few points on the notebook to clear up still. Failing tests now passing.

"id": "0130a6d9",
"metadata": {},
"source": [
"## Section 6: Summary of Fixes\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it starting with Section 6?

"- 3D tensors: [C, H, W]\n",
"- 4D tensors: [B, C, H, W]\n",
"\n",
"### Why This Fixes the Tests\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relavent?

},
"nbformat": 4,
"nbformat_minor": 5
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only example in the examples/notebooks directory. All others are in example/<some_description>, so it might be best to move this to match the other examples.

…ontent

- Moved notebook from examples/notebooks/ to examples/utils/
- Updated and improved notebook code content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants