skills/cv/rle-mask-encoding/SKILL.md
Encodes binary segmentation masks into compressed RLE format for efficient storage and submission.
npx skillsauth add wenmin-wu/ds-skills cv-rle-mask-encodingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Run-Length Encoding (RLE) compresses binary segmentation masks by storing consecutive runs of 0s and 1s as (start, length) pairs. Combined with zlib compression and base64 encoding, this produces compact ASCII strings suitable for competition submissions and efficient storage.
import numpy as np
from pycocotools import _mask as mask_util
import zlib
import base64
def mask_to_rle(binary_mask):
"""Convert binary mask to COCO-format RLE."""
fortran_mask = np.asfortranarray(binary_mask.astype(np.uint8))
rle = mask_util.encode(fortran_mask)
return rle
def rle_to_compressed_string(rle):
"""Compress RLE to base64 string for submission."""
compressed = zlib.compress(rle["counts"])
return base64.b64encode(compressed).decode("ascii")
def rle_to_mask(rle, shape):
"""Decode RLE back to binary mask."""
return mask_util.decode(rle).astype(bool)
pycocotools._mask.encodemask_util.decode when needednp.asfortranarray is essentialmask_util.encode for speeddata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF