File size: 1,371 Bytes
1e91598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
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])]])

# Polygon vertices (already in the 256x256 anchor-tile pixel frame)
verts = d["verts_px"][int(d["verts_ptr"][i]):int(d["verts_ptr"][i + 1])]
print("polygon vertices:", verts.shape)

# To overlay on imagery: load the matching tile from dcher95/global-dense-satellite via its
# "location" column == f"{z}_{x}_{y}", then plot `verts` on the 256x256 image.