Skip to main content

Codelor Color Architecture 🌿🧠

This repository contains the pure PyTorch architecture for Codelor Color, a lightweight Transformer designed for Chroma Key (green screen) segmentation.

Important note: The model weights (.safetensors), training scripts, and inference tools are available on the Hugging Face repository: plimb/codelor-color-1.2

Version 2.2.0 keeps the exact same weights as 2.1.0 (same parameter names and shapes), it only hardens the surrounding API. See CHANGELOG.md.

📦 Installation

pip install codelor-color

To download checkpoints directly from the Hugging Face Hub:

pip install "codelor-color[hf]"

Development install (tests, linter, type checker):

pip install -e ".[dev,hf]"

🚀 Usage

Load a pretrained checkpoint (local directory or Hub repo id):

from codelor_color import load_from_pretrained, predict_mask, remove_green

model = load_from_pretrained("plimb/codelor-color-1.2", device="cpu")

import torch
img = torch.rand(3, 160, 160)          # (3, H, W) float in [0, 1]

mask, prob = predict_mask(model, img)  # (H, W) bool mask + (H, W) float probability
rgba = remove_green(img, model)        # (4, H, W) RGBA tensor

Batches are supported: pass (B, 3, H, W) and you get (B, H, W) masks / (B, 4, H, W) RGBA tensors back.

Instantiate the architecture directly and load your own weights:

import torch
from codelor_color import CodelorColor

# Initialize the architecture
model = CodelorColor(dim=128, depth=8, heads=8, tied_after=4)

# Load your weights
# state_dict = load_file("model.safetensors")
# model.load_state_dict(state_dict)

model.eval()

# Forward pass
img = torch.rand(1, 3, 160, 160)
ref = torch.tensor([[0.20, 0.85, 0.30]]) # Target color (Green)

with torch.no_grad():
    prob_mask = torch.sigmoid(model(img, ref))

The default reference color is available as codelor_color.DEFAULT_REF_RGB.

🏗️ Architecture Details

  • ConvNeXt-style Stem: Anti-aliased downsampling for crisp edges.
  • Transformer Blocks: 8 blocks with 2D RoPE, QK-Norm, and weight sharing (tied_after).
  • Color Cross-Attention: Injects the target RGB color at each block.
  • Gated Decoder: FPN-like decoder with deep supervision and a Sobel edge head.

Notes:

  • The learned positional embedding table holds max_tokens tokens (default 1024). Larger inputs still run, but raise a RuntimeWarning because the positional embeddings are skipped beyond that capacity.
  • predict_mask and remove_green switch the model to eval mode and run under torch.inference_mode().

🧪 Development

pip install -e ".[dev,hf]"
pytest                # tests
ruff check codelor_color tests
mypy codelor_color

CI runs the same checks on every push and pull request.

📜 License

MIT License.

Metadata

Release files for codelor-color 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codelor-color 2.2.0
File Size Uploaded Provenance
codelor_color-2.2.0.tar.gz 15.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for codelor-color 2.2.0
File Interpreter ABI Platform
codelor_color-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / codelor_color-2.2.0.tar.gz

Download URL codelor_color-2.2.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8ecad8881a04791c338c69621c6507215291eaa9f5d61430862f0f4727a366ce
BLAKE2b-256 checksum
How to use checksums
1f702f479f6cd294f5374a79b7aa0c85ddf1c92492dce6083b5014cbe755af73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / codelor_color-2.2.0-py3-none-any.whl

Download URL codelor_color-2.2.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c4537cd76c5ee6f1d82a3432bd7610dfbb9504548173be529863f23406aba46
BLAKE2b-256 checksum
How to use checksums
4fd6fef645e76adf57381e13d24ba1914c3e94797805ae1e0389af523c37078a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for codelor-color 2.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page