Download scripts/make_notebook.py from XZhi/ViViD-5k: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/datasets/XZhi/ViViD-5k/resolve/main/scripts/make_notebook.py
- Command line
-
hf download hf://datasets/XZhi/ViViD-5k/scripts/make_notebook.py
-
curl -L -o make_notebook.py https://huggingface.co/datasets/XZhi/ViViD-5k/resolve/main/scripts/make_notebook.py
2.67 kB
| """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) | |