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.1

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.1
File Size Uploaded Provenance
codelor_color-2.2.1.tar.gz 16.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 27.3 kB

Release files / codelor_color-2.2.1.tar.gz

Download URL codelor_color-2.2.1.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bcc1d6794a0ce1feee14705cf594ac16450da3dc1b1f0bd2f0b69db50cf08365
BLAKE2b-256 checksum
How to use checksums
1151a6cc432efede89d75498c44f17a3a988e9547fb0a7182e9fbe2f0483a146
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.1-py3-none-any.whl

Download URL codelor_color-2.2.1-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
370b1bc6d3b6afe0922020e72b619015c90b96d8ef00572e099de36f502b9bd4
BLAKE2b-256 checksum
How to use checksums
7c6535d3df55f8c47f049508ee0674845afc7cec03c8b1fb748472df37b8a7ab
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.1

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