Skip to main content

dspic

Status: vibe-coded experiment. This project is exploratory and not production-quality. If it reaches 1.0, it means the code and API have been fully reviewed by qualified humans.

DSPIC is a DSPy-inspired library for foundation vision models. It uses typed signatures, adapters, and normalized request/response objects for vision models instead of language models.

Created by Maxime Rivest and Aurelie Guisnet.

Quick start

import dspic

sam = dspic.SAM21VM(endpoint="http://192.168.2.24:8078/v1/vision")
dspic.configure(vm=sam)

segment = dspic.Predict("image: Image, point: Point -> mask: Masks")

pred = segment(
    image="image.png",
    point=(48, 48),
)

mask = pred.mask

For remote servers, use image data, URLs, or paths the server can access.

Core ideas

  • VM: a vision model client, analogous to a DSPy LM.
  • Predict: a DSPy-style module for typed vision signatures.
  • ImageAdapter: routes signatures to one or more specialized VMs.
  • demos: visual prompting examples, analogous to DSPy demos.

Signatures

String signatures:

segment = dspic.Predict("image: Image, point: Point -> mask: Masks")

Class signatures:

class Segment(dspic.Signature):
    image: dspic.Image = dspic.InputField()
    point: dspic.Point = dspic.InputField()
    mask: dspic.Masks = dspic.OutputField()

segment = dspic.Predict(Segment)

Simple input types

image = "image.png"
point = (48, 48)
box = (10, 20, 100, 120)

These become normalized VM inputs:

  • Image -> ImageInput
  • Point -> PointPrompt
  • Box -> BoxPrompt
  • Mask -> MaskPrompt

Common outputs:

  • Masks
  • Boxes
  • Points
  • Tracks
  • Keypoints
  • RawText

Multiple VMs

Vision models are specialized, so one program can use several VMs:

program = dspic.Predict("image: Image, query: Text -> boxes: Boxes, mask: Masks")

pred = program(
    image="image.png",
    query="cat",
    vm=[detector_vm, segmenter_vm],
)

Visual prompting demos

segment = dspic.Predict(
    "image: Image, point: Point -> mask: Masks",
    vm=sam,
    demos=[{"image": "first-frame.png", "point": (100, 120)}],
)

pred = segment(image="current-frame.png", point=(130, 140))

SAM 2.1 integration test

If a SAM 2.1 server is running at the default endpoint, this test runs end to end:

uv run pytest tests/test_sam21_predict_integration.py

Default endpoint:

http://192.168.2.24:8078/v1/vision

Override it with:

export DSPIC_SAM21_ENDPOINT=http://your-server:8078/v1/vision
uv run pytest tests/test_sam21_predict_integration.py

Development

uv sync --dev
uv run pytest
uv run ruff check .

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dspic-0.1.0.tar.gz (84.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dspic-0.1.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file dspic-0.1.0.tar.gz.

File metadata

  • Download URL: dspic-0.1.0.tar.gz
  • Upload date:
  • Size: 84.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for dspic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 da81a99cbd12d41ed5b9fc5fd3c1b23ccdda92fa77422ec96aecd29c0534d41a
MD5 5ba2e55260f1f7e09ae734536b4b571f
BLAKE2b-256 f93cc6f41df2f3d74b76f7a81e270ffe923066343bd6d33f7f8bbe9ac9519486

See more details on using hashes here.

File details

Details for the file dspic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dspic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for dspic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b5df21cfd9fe107d68a1b8e9634b9b222abc7803858e929eb0dd0b4abe9a797
MD5 61db3f19f09310fccc5d2162dc93ff13
BLAKE2b-256 81040c062d4d670f5fd4a3a8bae3ddd18866b82ba3dc0562007624fd41fac754

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page