jonilaserson/sam-encoder-api
0
SAM Encoder API
Public microservice that runs the SAM ViT-B vision encoder and returns raw feature embeddings as a compressed numpy file.
API
POST /embed
Upload a map image, receive SAM encoder features.
Request: multipart/form-data with field image (PNG/JPEG/WebP, ≤1024px recommended)
Response: application/octet-stream — numpy .npz file with keys:
neck:float16 (256, 64, 64)— SAM neck output (last_hidden_state)early:float16 (768, 64, 64)— ViT block-6 output (BCHW)
GET /health
Returns {"status": "ok", "device": "cpu"}.
Usage
import requests, io, numpy as np
resp = requests.post(
"https://your-username-sam-encoder-api.hf.space/embed",
files={"image": open("map.png", "rb")},
)
data = np.load(io.BytesIO(resp.content))
neck = data["neck"] # (256, 64, 64) float16
early = data["early"] # (768, 64, 64) float16Model
Uses facebook/sam-vit-base (Meta AI). No fine-tuning — purely the frozen pretrained encoder. Model weights are downloaded from HuggingFace Hub at container build time.
