File size: 2,670 Bytes
320b346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Generate notebooks/demo.ipynb programmatically."""
from pathlib import Path

import nbformat as nbf

ROOT = Path(__file__).resolve().parents[1]
nb = nbf.v4.new_notebook()
cells = []

cells.append(nbf.v4.new_markdown_cell(
    "# ViViD-5k demo — load, visualize, count berries\n"
    "Dataset: [XZhi/ViViD-5k](https://huggingface.co/datasets/XZhi/ViViD-5k) · "
    "Paper: [arXiv:2605.24353](https://arxiv.org/abs/2605.24353) · "
    "Code: [GrapeSAM](https://github.com/tong-xz/GrapeSAM)"))

cells.append(nbf.v4.new_code_cell(
    "%pip install -q huggingface_hub datasets pillow matplotlib numpy"))

cells.append(nbf.v4.new_markdown_cell("## Download one sample (image + berry keypoints)"))
cells.append(nbf.v4.new_code_cell(
    'from huggingface_hub import hf_hub_download\n'
    'import numpy as np\n'
    'from PIL import Image\n\n'
    'repo = "XZhi/ViViD-5k"\n'
    'img = Image.open(hf_hub_download(repo, "data/imgs/0.png", repo_type="dataset"))\n'
    'pts = np.load(hf_hub_download(repo, "data/anns/points/0.npy", repo_type="dataset"))\n'
    'print(f"image {img.size}, {len(pts)} annotated berries")'))

cells.append(nbf.v4.new_markdown_cell("## Overlay the berry keypoints"))
cells.append(nbf.v4.new_code_cell(
    'import matplotlib.pyplot as plt\n\n'
    'fig, ax = plt.subplots(figsize=(6, 10))\n'
    'ax.imshow(img)\n'
    'ax.scatter(pts[:, 0], pts[:, 1], s=6, color="#FDE047", edgecolors="#B45309", linewidths=0.3)\n'
    'ax.set_title(f"{len(pts)} berries")\n'
    'ax.axis("off")\n'
    'plt.show()'))

cells.append(nbf.v4.new_markdown_cell("## Browse the dataset (streaming, no full download)"))
cells.append(nbf.v4.new_code_cell(
    'from datasets import load_dataset\n\n'
    'ds = load_dataset(repo, split="train", streaming=True)\n'
    'ex = next(iter(ds))\n'
    'display(ex["image"])\n'
    'print("berries:", ex["berry_count"], "clusters:", ex["cluster_count"])'))

cells.append(nbf.v4.new_markdown_cell(
    "## Per-image metadata\nEvery image has computed stats in `data/metadata.csv`."))
cells.append(nbf.v4.new_code_cell(
    'import pandas as pd\n\n'
    'meta = pd.read_csv(hf_hub_download(repo, "data/metadata.csv", repo_type="dataset"))\n'
    'meta.berry_count.hist(bins=50)\n'
    'meta.describe()'))

cells.append(nbf.v4.new_markdown_cell(
    "## Next: count berries with a model\n"
    "[GrapeSAM](https://github.com/tong-xz/GrapeSAM) trains and evaluates cluster "
    "segmentation + berry counting models on ViViD-5k — full masks and COCO "
    "annotations are in `data/anns/`."))

nb["cells"] = cells
out = ROOT / "notebooks" / "demo.ipynb"
out.parent.mkdir(exist_ok=True)
nbf.write(nb, out)
print("wrote", out)