Refactor: Convert CrossScore to pip-installable package#5
Open
ziruiw-dev wants to merge 5 commits intomainfrom
Open
Refactor: Convert CrossScore to pip-installable package#5ziruiw-dev wants to merge 5 commits intomainfrom
ziruiw-dev wants to merge 5 commits intomainfrom
Conversation
Restructure the project into a proper Python package so users can install with `pip install crossscore` instead of manually configuring a conda env. Key changes: - Move model/, dataloading/, utils/ into crossscore/ package with proper __init__.py files and absolute imports (no more sys.path.append hacks) - Add pyproject.toml with flexible dependency ranges (torch>=2.0.0, not pinned) so users install PyTorch+CUDA separately per their system - Add crossscore.score() high-level API for simple inference - Add `crossscore` CLI entry point - Add auto-download of model checkpoint from HuggingFace Hub - Update task/ entry points to import from crossscore package - Update README with pip install instructions and quick start guide https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB
- Make wandb import lazy in core.py and batch_visualiser.py so inference works without wandb installed (it's only needed for training) - Fix CPU mode: use "auto" devices, "32-true" precision, handle non-list device configs in DDP logic - Add --cpu flag to CLI https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB
The pip package now only supports inference (scoring), not training. This dramatically reduces dependencies and complexity. Key changes: - Rewrite crossscore/task/core.py to pure PyTorch (no LightningModule) - CrossScoreNet is a plain torch.nn.Module - load_model() handles Lightning checkpoint format - Rewrite crossscore/api.py to use direct torch inference loop - No Lightning Trainer, just DataLoader + model.forward() - Returns both score_maps (tensors) and scores (per-image means) - Writes colorized score map PNGs to disk - Remove training-only files from package: - metric_logger, batch_visualiser, batch_writer, score_summariser - evaluation metrics, data_manager, summarise_score_gt - Remove heavy deps: lightning, wandb, scipy, scikit-image, pandas, hydra-core - Move CrossScoreLightningModule to task/core.py (repo-only, not in pip package) for training workflow - Add --cpu and --device flags to CLI https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB
The checkpoint is already hosted via Git LFS in the GitHub repo, so download directly from there using stdlib urllib (no extra deps). Remove huggingface-hub from direct dependencies. URL: https://github.com/ActiveVisionLab/CrossScore/raw/main/ckpt/CrossScore-v1.0.0.ckpt https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB
HuggingFace has no bandwidth limits for public models, unlike GitHub LFS (1 GB/month free). huggingface_hub is already a transitive dep of transformers so this adds no new dependencies. Upload checkpoint with: huggingface-cli upload ActiveVisionLab/CrossScore ckpt/CrossScore-v1.0.0.ckpt CrossScore-v1.0.0.ckpt https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB
af29259 to
01a4099
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors CrossScore from a standalone research codebase into a proper pip-installable Python package with a public API, enabling easy distribution and usage.
Key Changes
Package Structure
crossscore/package directory with proper__init__.pyand submodule organizationtask/core.pytocrossscore/task/core.pywith backwards-compatible re-exportsdataloading/,model/,utils/,task/__init__.pyfiles to all subpackages for proper Python package structurePublic API
crossscore/api.pywith high-levelscore()function for easy image quality assessmentcrossscore/__init__.pyexposing main API functions (score(),get_checkpoint_path())crossscore/cli.pyfor command-line interface supportcrossscore/_download.pyfor automatic checkpoint downloading from HuggingFace HubConfiguration & Distribution
pyproject.tomlwith proper package metadata, dependencies, and build configurationcrossscore/config/directory with YAML configs for model and datacrossscore/config/default_predict.yamlfor inference configurationcrossscore/config/model/model.yamlandcrossscore/config/data/SimpleReference.yamlImport Path Updates
crossscore.package prefix (e.g.,from crossscore.utils.io.images import ...)sys.path.append()hacks from training/testing scriptsBackwards Compatibility
task/core.pynow re-exports fromcrossscore.task.corefor backwards compatibilitytask/train.py,task/test.py,task/predict.py) updated to work with new structureDocumentation
README.mdwith pip installation instructionsImplementation Details
score()API automatically downloads the model checkpoint on first use (cached in~/.cache/crossscore/)https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB