Skip to content

Refactor: Convert CrossScore to pip-installable package#5

Open
ziruiw-dev wants to merge 5 commits intomainfrom
claude/pip-installable-package-Zg7eR
Open

Refactor: Convert CrossScore to pip-installable package#5
ziruiw-dev wants to merge 5 commits intomainfrom
claude/pip-installable-package-Zg7eR

Conversation

@ziruiw-dev
Copy link
Collaborator

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

  • Created crossscore/ package directory with proper __init__.py and submodule organization
  • Moved core model code from task/core.py to crossscore/task/core.py with backwards-compatible re-exports
  • Organized code into logical subpackages: dataloading/, model/, utils/, task/
  • Added __init__.py files to all subpackages for proper Python package structure

Public API

  • Added crossscore/api.py with high-level score() function for easy image quality assessment
  • Added crossscore/__init__.py exposing main API functions (score(), get_checkpoint_path())
  • Added crossscore/cli.py for command-line interface support
  • Added crossscore/_download.py for automatic checkpoint downloading from HuggingFace Hub

Configuration & Distribution

  • Added pyproject.toml with proper package metadata, dependencies, and build configuration
  • Created crossscore/config/ directory with YAML configs for model and data
  • Added crossscore/config/default_predict.yaml for inference configuration
  • Added crossscore/config/model/model.yaml and crossscore/config/data/SimpleReference.yaml

Import Path Updates

  • Updated all internal imports to use crossscore. package prefix (e.g., from crossscore.utils.io.images import ...)
  • Removed sys.path.append() hacks from training/testing scripts
  • Cleaned up relative imports in renamed files

Backwards Compatibility

  • Original task/core.py now re-exports from crossscore.task.core for backwards compatibility
  • Existing training/testing scripts (task/train.py, task/test.py, task/predict.py) updated to work with new structure

Documentation

  • Updated README.md with pip installation instructions
  • Added quick start examples for both Python API and CLI usage
  • Documented PyTorch installation requirements and CUDA version handling

Implementation Details

  • The score() API automatically downloads the model checkpoint on first use (cached in ~/.cache/crossscore/)
  • Configuration is built dynamically from YAML files with CLI/API parameter overrides
  • Supports both GPU and CPU inference with configurable device selection
  • Maintains full compatibility with existing training pipeline while enabling easy inference distribution

https://claude.ai/code/session_0114iFoswRfTkMai4JTrgMrB

claude added 5 commits March 21, 2026 20:20
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
@ziruiw-dev ziruiw-dev force-pushed the claude/pip-installable-package-Zg7eR branch from af29259 to 01a4099 Compare March 21, 2026 20:20
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