Developer docs / AI Fabric tutorials
Satellite images → embedding vectors
- GPU
- Batch / map
- Image DSL
Take it for a spin
The whole program in one file, ready to run.
import bladekit
app = bladekit.app("satellite-embeddings")
# fabric/torch already ships torch + torchvision + CUDA, so do NOT reinstall them
# (a pip torch upgrade breaks torchvision's compiled ops). Just use the base.
image = bladekit.Image.from_catalog("fabric/torch")
@app.function(gpu="RTX-A4500", image=image, timeout=600)
def embed_batch(seed: int) -> dict:
"""Embed a small batch of synthetic 'satellite' images and return shapes."""
import torch
from torchvision import models
# Pretrained ResNet-50 encoder with the classification head removed:
# the 2048-d penultimate features are a solid generic image embedding.
weights = models.ResNet50_Weights.DEFAULT
encoder = models.resnet50(weights=weights)
encoder.fc = torch.nn.Identity()
encoder.eval().to("cuda")
# Synthesise a batch of 8 RGB "tiles" (224x224) in-code (no files, no URLs).
# Real satellite tiles would be loaded the same way once decoded to tensors.
g = torch.Generator().manual_seed(seed)
batch = torch.rand(8, 3, 224, 224, generator=g)
# Normalise with ImageNet stats, exactly as torchvision's transforms would.
mean = torch.tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1)
std = torch.tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1)
batch = ((batch - mean) / std).to("cuda")
with torch.no_grad():
vecs = encoder(batch).cpu()
return {
"seed": seed,
"n_images": int(vecs.shape[0]),
"embedding_dim": int(vecs.shape[1]),
"preview": vecs[0, :6].tolist(),
}
@app.local_entrypoint()
def main():
# Fan several batches out across the fleet, one GPU container per seed.
results = list(embed_batch.map(range(4), return_exceptions=True))
for r in results:
if isinstance(r, Exception):
print(f"batch failed: {r}")
else:
print(f"seed={r['seed']}: {r['n_images']} images -> "
f"{r['embedding_dim']}-d vectors, preview={r['preview']}")Run it
- Run
blade run satellite_embeddings.py. - Each seed runs in its own GPU container via
.map(), so they all embed in parallel and return in input order. - The ResNet-50 encoder (head removed) turns each 224×224 tile into a 2048-d vector. Swap
torch.rand(...)for your decoded satellite tiles to embed real imagery. - To persist the vectors, write them to a
bladekit.Volume(or push to your vector DB) from inside the function instead of returning a preview.
Concepts used: GPU, Run