Download scripts/load_dataset_example.py from MVRL/dense500-retrieval-instances: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/MVRL/dense500-retrieval-instances/resolve/main/scripts/load_dataset_example.py
- Command line
-
hf download hf://datasets/MVRL/dense500-retrieval-instances/scripts/load_dataset_example.py
-
curl -L -o load_dataset_example.py https://huggingface.co/datasets/MVRL/dense500-retrieval-instances/resolve/main/scripts/load_dataset_example.py
1.37 kB
| """ | |
| 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. | |