Skip to content

Add Pytorch lightning classifier#580

Open
rwood-97 wants to merge 9 commits into
mainfrom
pytorch_lightning
Open

Add Pytorch lightning classifier#580
rwood-97 wants to merge 9 commits into
mainfrom
pytorch_lightning

Conversation

@rwood-97
Copy link
Copy Markdown
Collaborator

@rwood-97 rwood-97 commented Apr 1, 2026

Summary

Adds PyTorch lightning classifier

Checklist before assigning a reviewer (update as needed)

  • Self-review code
  • Ensure submission passes current tests
  • Add tests
  • Update relevant docs
  • Update changelog
  • Check copilot review

Reviewer checklist

Please add anything you want reviewers to specifically focus/comment on.

  • Everything looks ok?

@rwood-97 rwood-97 force-pushed the pytorch_lightning branch from 096eaca to 486e163 Compare April 1, 2026 15:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a PyTorch Lightning-based classifier container to support Trainer-driven training workflows, including multi-GPU usage, while also fixing several existing ClassifierContainer regression points and expanding tests/docs.

Changes:

  • Introduces LightningClassifierContainer with Lightning hooks for training, validation, prediction, saving/loading, metrics, and dataset loading.
  • Adds Lightning-specific tests plus regression tests for classifier input sizing, layerwise LR keys, and save/load roundtrips.
  • Adds optional lightning dependency extra, CI installation updates, documentation, and changelog entry.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mapreader/classify/lightning_classifier.py Adds the new Lightning classifier implementation.
mapreader/classify/classifier.py Fixes existing classifier regressions and formatting around model setup, summaries, checkpoints, logits, and metrics.
mapreader/__init__.py Exposes LightningClassifierContainer when optional dependencies are installed.
tests/test_classify/test_lightning_classifier.py Adds coverage for Lightning classifier initialization, training/prediction hooks, saving/loading, and errors.
tests/test_classify/test_classifier.py Adds regression coverage for existing classifier fixes.
setup.py Adds the optional lightning dependency extra.
.github/workflows/mr_ci.yml Installs the Lightning extra for main CI.
.github/workflows/mr_ci_text_spotting.yml Installs the Lightning extra for text spotting CI.
docs/source/using-mapreader/step-by-step-guide/4-classify/train.rst Documents Lightning classifier usage.
CHANGELOG.md Notes the new Lightning classifier feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setup.py
Comment thread mapreader/classify/lightning_classifier.py
Comment thread mapreader/classify/lightning_classifier.py
Comment thread mapreader/classify/lightning_classifier.py
rwood-97 and others added 3 commits May 19, 2026 12:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

model: str | nn.Module | None = None,
labels_map: dict[int, str] | None = None,
dataloaders: dict[str, DataLoader] | None = None,
input_size: int = (224, 224),
model_name: str,
weights: str | None = "DEFAULT",
last_layer_num_classes: str | int | None = "default",
) -> tuple[Any, int, bool]:
Comment on lines +1590 to +1594
try:
self.device = mydevice
self.model = self.model.to(mydevice)
except:
pass
Comment on lines +1580 to +1583
if force_device:
if not isinstance(force_device, str):
force_device = str(force_device)
os.environ["CUDA_VISIBLE_DEVICES"] = force_device
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