| """ |
| Minimal example: load global-dense-instances annotations + global-dense-satellite imagery, render one |
| instance's crop with its polygon overlay and decoded tags. |
| |
| pip install huggingface_hub datasets numpy pandas pillow torch matplotlib |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| import torch |
| import matplotlib.pyplot as plt |
| from matplotlib.patches import Polygon as MplPolygon |
|
|
| INSTANCES_NPZ = "./global-dense-instances/inst_metadata.npz" |
| TAG_VOCAB_PT = "./global-dense-instances/tag_vocab.pt" |
|
|
| d = np.load(INSTANCES_NPZ, mmap_mode="r", allow_pickle=False) |
| vocab = torch.load(TAG_VOCAB_PT, weights_only=False) |
| inv_vocab = {idx: pair for pair, idx in vocab.items()} |
|
|
| i = 1000 |
| z, x, y = int(d["anchor_zoom"][i]), int(d["anchor_x"][i]), int(d["anchor_y"][i]) |
| print("tile:", f"{z}_{x}_{y}") |
| print("source:", {0: "ms_only", 1: "ms+osm_merged", 2: "osm_building", 3: "osm_area"}[int(d["source"][i])]) |
| print("tags:", [inv_vocab[int(t)] for t in d["tag_ids"][int(d["tag_ids_ptr"][i]):int(d["tag_ids_ptr"][i + 1])]]) |
|
|
| |
| verts = d["verts_px"][int(d["verts_ptr"][i]):int(d["verts_ptr"][i + 1])] |
| print("polygon vertices:", verts.shape) |
|
|
| |
| |
|
|