Xieih commited on
Commit
ac3b25c
·
verified ·
1 Parent(s): ed23ed1

tree7: 2,143 images (7 urban tree species) as parquet with embedded images

Browse files

train 1714 / valid 215 / test 214, stratified 80/10/10 (seed 20261124); images embedded as Image() feature, labels as ClassLabel.

README.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: mixed-cc-by-nc-cc-by-cc0
4
+ tags:
5
+ - image-classification
6
+ - computer-vision
7
+ - plants
8
+ - trees
9
+ - inaturalist
10
+ - wikimedia-commons
11
+ size_categories:
12
+ - 1K<n<10K
13
+ task_categories:
14
+ - image-classification
15
+ language:
16
+ - zh
17
+ - en
18
+ ---
19
+
20
+ # tree7 — seven urban tree species
21
+
22
+ 2,143 labelled photos of seven ornamental / street-tree species, packaged as parquet with the
23
+ images embedded, so `load_dataset()` streams them without a 500 MB download.
24
+
25
+ | label | class_name | 中文 | scientific name | train | valid | test |
26
+ |---|---|---|---|---|---|---|
27
+ | 0 | `Ficus_microcarpa` | 榕樹 | *Ficus microcarpa* | 246 | 31 | 31 |
28
+ | 1 | `Terminalia_catappa` | 大葉欖仁 | *Terminalia catappa* | 246 | 31 | 30 |
29
+ | 2 | `Araucaria_columnaris` | 柱狀南洋杉 | *Araucaria columnaris* | 246 | 31 | 31 |
30
+ | 3 | `Dypsis_lutescens` | 散尾葵 | *Dypsis lutescens* | 242 | 30 | 31 |
31
+ | 4 | `Strelitzia_reginae` | 鶴望蘭 | *Strelitzia reginae* | 242 | 30 | 30 |
32
+ | 5 | `Drynaria_roosii` | 槲蕨 | *Drynaria roosii* | 247 | 31 | 31 |
33
+ | 6 | `Acalypha_wilkesiana` | 紅桑 | *Acalypha wilkesiana* | 245 | 31 | 30 |
34
+
35
+ Images are JPEG, long side ≤1024 px, quality 88. Short side p5 = 576 px.
36
+
37
+ ## Load it
38
+
39
+ ```python
40
+ from datasets import load_dataset
41
+
42
+ ds = load_dataset("xieyihong04-creator/tree7") # train / valid / test
43
+ ds["train"][0]["image"] # PIL.Image, decoded on access
44
+ ds["train"][0]["label"], ds["train"][0]["class_name"]
45
+ names = ds["train"].features["label"].names # 0..6 -> class_name
46
+ ```
47
+
48
+ PyTorch example:
49
+
50
+ ```python
51
+ import torch
52
+ from transformers import AutoImageProcessor
53
+ from torch.utils.data import DataLoader
54
+ from datasets import load_dataset
55
+
56
+ proc = AutoImageProcessor.from_pretrained("microsoft/resnet-50")
57
+ ds = load_dataset("xieyihong04-creator/tree7", split="train")
58
+
59
+ def collate(batch):
60
+ px = proc(images=[b["image"] for b in batch], return_tensors="pt")
61
+ px["labels"] = torch.tensor([b["label"] for b in batch])
62
+ return px
63
+ ```
64
+
65
+ ## Provenance and label quality
66
+
67
+ - **iNaturalist — 2,016 images (94.3%).** Only observations at `quality_grade=research` are used,
68
+ i.e. the identification has been agreed by at least two community taxonomists. `page_url` links
69
+ to the observation so every label is auditable.
70
+ - **Wikimedia Commons — 127 images (5.9%).** Taken from the species category pages. Titles matching
71
+ book scans (BHL/CHS), maps, diagrams, posters, or naming a *different* genus are rejected
72
+ automatically; the remainder were reviewed against a contact sheet.
73
+ - **De-duplication.** 64-bit dHash, Hamming distance ≤6, applied within and across classes.
74
+ Cross-class near-duplicates: 0 — no photo is filed under two species.
75
+ - **GBIF was deliberately skipped**: its media are mostly herbarium scans and literature thumbnails.
76
+
77
+ Pipeline source: `xieyihong04-creator/tree7-dataset` (GitHub) — `collect.py` builds the candidate
78
+ index, `build.py` downloads/resizes/dedupes, `repair_manifest.py` audits.
79
+
80
+ `dataset_info` is intentionally left out of the card front matter: the parquet files carry the
81
+ Hugging Face feature signature, so the Hub (and `load_dataset`) reads `image` as `Image()` and
82
+ `label` as `ClassLabel` directly from them.
83
+
84
+ ## Fields
85
+
86
+ `sample_id`, `image`, `label`, `class_name`, `zh_name`, `sci_name`, `source`, `license`,
87
+ `commercial_ok`, `attribution`, `page_url`, `observed_on`, `latitude`, `longitude`, `width`,
88
+ `height`, `grade`, `faves`.
89
+
90
+ Use `license` / `attribution` / `commercial_ok` for compliance, `grade` / `faves` for weighting,
91
+ `latitude` / `longitude` / `observed_on` for geographically or seasonally disjoint validation.
92
+ 129 rows have no coordinates (obscured iNaturalist observations and Commons files).
93
+
94
+ ## License
95
+
96
+ **The images are not released under this repo's license.** Each keeps the license its uploader
97
+ chose: CC BY-NC 1,879 · CC0 81 · CC BY 60 · CC BY-SA 4.0/3.0 64 · other 39.
98
+
99
+ - 1,879 images are **non-commercial** — do not use this dataset as-is in a commercial product.
100
+ - CC BY / BY-SA require attribution; the exact string to credit is in `attribution`.
101
+ - For a commercial-only subset, filter `commercial_ok == "yes"` (246 images).
102
+
103
+ The parquet packaging and this dataset card are MIT; the pipeline code is MIT.
104
+
105
+ ## Known limitations
106
+
107
+ 1. **Mixed framing.** Whole-tree, canopy, leaf and fruit close-ups are all kept (the stated target
108
+ is a general classifier). Roughly 40% of the banyan images are leaf close-ups — filter them if
109
+ you want a habit-only model.
110
+ 2. **Urban bias.** Parks, street trees and campuses dominate; wild forest habitat, distant small
111
+ subjects, night and rain/fog conditions are under-covered.
112
+ 3. **Geographic skew.** Tropical and Southern-Hemisphere observations (East Africa, South America,
113
+ Pacific islands) are over-represented relative to Taiwan. A `place_id`-restricted second pull
114
+ would fix this.
115
+ 4. **Resolution ceiling.** iNaturalist `large` files cap at 1024 px on the long side.
116
+ 5. **Strelitzia pool is the smallest** (769 research-grade observations), so that class is closest
117
+ to saturation if you scale up.
118
+
119
+ ## Citation
120
+
121
+ ```bibtex
122
+ @misc{tree7,
123
+ title = {tree7: an image dataset of seven urban tree species},
124
+ author = {xieyihong04-creator},
125
+ year = {2026},
126
+ note = {Images derived from iNaturalist (CC BY-NC / CC BY / CC0) and Wikimedia Commons},
127
+ url = {https://huggingface.co/datasets/xieyihong04-creator/tree7}
128
+ }
129
+ ```
build_parquet.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Pack the tree7 images into a Hugging Face parquet dataset (train/valid/test).
3
+
4
+ Images are embedded as {bytes, path} structs so the HF AutoReader maps them to
5
+ the Image feature automatically — the repo previews and streams without anyone
6
+ having to download 500 MB first.
7
+ """
8
+ import csv, json, os, random
9
+ import pyarrow as pa
10
+ import pyarrow.parquet as pq
11
+ from datasets import Dataset, Features, ClassLabel, Image as HFImage, Value
12
+
13
+ SRC = "/data/tree_dataset"
14
+ OUT = "/data/tree7_hf"
15
+ ROWS = [json.loads(l) for l in open(os.path.join(SRC, "manifest.jsonl"), encoding="utf-8")]
16
+ CLASSES = json.load(open(os.path.join(SRC, "classes.json"), encoding="utf-8"))["classes"]
17
+ SEED, SPLIT = 20261124, (0.8, 0.1, 0.1)
18
+ MAX_MB = 110
19
+
20
+ random.seed(SEED)
21
+ buckets = {"train": [], "valid": [], "test": []}
22
+ for lab in CLASSES:
23
+ grp = sorted([r for r in ROWS if r["label"] == lab], key=lambda r: r["file"])
24
+ random.shuffle(grp)
25
+ n = len(grp)
26
+ a = int(round(n * SPLIT[0]))
27
+ b = a + int(round(n * SPLIT[1]))
28
+ buckets["train"] += grp[:a]
29
+ buckets["valid"] += grp[a:b]
30
+ buckets["test"] += grp[b:]
31
+ print(f"{lab:22s} train={a} valid={b-a} test={n-b}")
32
+
33
+
34
+ def to_col(r):
35
+ with open(os.path.join(SRC, "images", r["file"]), "rb") as f:
36
+ blob = f.read()
37
+ lat, lng = (r.get("latlng") or ",").split(",")[:2]
38
+ return {
39
+ "sample_id": f"{r['label']}-{r['image_id']}",
40
+ "image": {"bytes": blob, "path": os.path.basename(r["file"])},
41
+ "label": CLASSES.index(r["label"]),
42
+ "class_name": r["label"],
43
+ "zh_name": r["zh_name"],
44
+ "sci_name": r["sci_name"],
45
+ "source": r["source"],
46
+ "license": r["license"],
47
+ "commercial_ok": r["commercial_ok"],
48
+ "attribution": r["attribution"],
49
+ "page_url": r["page_url"],
50
+ "observed_on": (r.get("observed_on") or "")[:10],
51
+ "latitude": float(lat) if lat else None,
52
+ "longitude": float(lng.split()[0]) if lng else None,
53
+ "width": r["w"],
54
+ "height": r["h"],
55
+ "grade": r.get("grade"),
56
+ "faves": r.get("faves"),
57
+ }
58
+
59
+
60
+ SCHEMA = pa.schema([
61
+ ("sample_id", pa.string()),
62
+ ("image", pa.struct([("bytes", pa.binary()), ("path", pa.string())])),
63
+ ("label", pa.int32()),
64
+ ("class_name", pa.string()),
65
+ ("zh_name", pa.string()),
66
+ ("sci_name", pa.string()),
67
+ ("source", pa.string()),
68
+ ("license", pa.string()),
69
+ ("commercial_ok", pa.string()),
70
+ ("attribution", pa.string()),
71
+ ("page_url", pa.string()),
72
+ ("observed_on", pa.string()),
73
+ ("latitude", pa.float64()),
74
+ ("longitude", pa.float64()),
75
+ ("width", pa.int32()),
76
+ ("height", pa.int32()),
77
+ ("grade", pa.string()),
78
+ ("faves", pa.int32()),
79
+ ])
80
+
81
+ FEATS = Features({
82
+ "sample_id": Value("string"),
83
+ "image": HFImage(),
84
+ "label": ClassLabel(names=CLASSES),
85
+ "class_name": Value("string"),
86
+ "zh_name": Value("string"),
87
+ "sci_name": Value("string"),
88
+ "source": Value("string"),
89
+ "license": Value("string"),
90
+ "commercial_ok": Value("string"),
91
+ "attribution": Value("string"),
92
+ "page_url": Value("string"),
93
+ "observed_on": Value("string"),
94
+ "latitude": Value("float64"),
95
+ "longitude": Value("float64"),
96
+ "width": Value("int32"),
97
+ "height": Value("int32"),
98
+ "grade": Value("string"),
99
+ "faves": Value("int32"),
100
+ })
101
+
102
+ os.makedirs(os.path.join(OUT, "data"), exist_ok=True)
103
+ sizes, no_geo = {}, 0
104
+ for split, rows in buckets.items():
105
+ cols, shard, shards, mb = [], 0, [], 0.0
106
+ for i, r in enumerate(rows):
107
+ c = to_col(r)
108
+ no_geo += c["latitude"] is None
109
+ cols.append(c)
110
+ mb += r["bytes"] / 1e6
111
+ if mb >= MAX_MB or i == len(rows) - 1:
112
+ shards.append(cols)
113
+ cols, mb = [], 0.0
114
+ total = len(shards)
115
+ for k, sh in enumerate(shards):
116
+ tb = pa.Table.from_pylist(sh, schema=SCHEMA)
117
+ name = f"data/{split}-{k:05d}-of-{total:05d}.parquet"
118
+ Dataset(tb).cast(FEATS).to_parquet(os.path.join(OUT, name))
119
+ print(f" {name} rows={len(sh)} "
120
+ f"{os.path.getsize(os.path.join(OUT, name))/1e6:.1f} MB")
121
+ sizes[split] = sum(len(s) for s in shards)
122
+
123
+ with open(os.path.join(OUT, "splits.json"), "w", encoding="utf-8") as f:
124
+ json.dump({"seed": SEED, "ratios": SPLIT, "counts": sizes,
125
+ "classes": CLASSES,
126
+ "files": {s: sorted(os.listdir(os.path.join(OUT, "data")))
127
+ for s in ["train", "valid", "test"]}}, f, indent=2)
128
+ print("counts:", sizes, "total", sum(sizes.values()), "| rows without coordinates:", no_geo)
data/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a27f02724d3227e9c46184e10e7b5e50a41eac164f2b299f1fb6559275da872
3
+ size 51615570
data/train-00000-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71bb0d74404c102da77851e89537db02bee0d9924ead45a98325ed1d25ec3bad
3
+ size 110196703
data/train-00001-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a718864e82218b4bd6c61d0d741de611d43d19d29ca70a6cb8e6c4e5f26b7ed
3
+ size 110204424
data/train-00002-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc94ce930ebb8e3bb7128d78d5ca993622523304800c50e3f4ff45638f83cf0a
3
+ size 110184984
data/train-00003-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecf3677e5815d8564c5862284f1e5a32da3375f96a0d10ca5e11648a0eb03284
3
+ size 75175980
data/valid-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac2e6f5bded99bdd71860378e36feda2cecd0629ccdac9fbbc7a4605a15d3f67
3
+ size 53818786
splits.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "seed": 20261124,
3
+ "ratios": [
4
+ 0.8,
5
+ 0.1,
6
+ 0.1
7
+ ],
8
+ "counts": {
9
+ "train": 1714,
10
+ "valid": 215,
11
+ "test": 214
12
+ },
13
+ "classes": [
14
+ "Ficus_microcarpa",
15
+ "Terminalia_catappa",
16
+ "Araucaria_columnaris",
17
+ "Dypsis_lutescens",
18
+ "Strelitzia_reginae",
19
+ "Drynaria_roosii",
20
+ "Acalypha_wilkesiana"
21
+ ],
22
+ "files": {
23
+ "train": [
24
+ "test-00000-of-00001.parquet",
25
+ "train-00000-of-00004.parquet",
26
+ "train-00001-of-00004.parquet",
27
+ "train-00002-of-00004.parquet",
28
+ "train-00003-of-00004.parquet",
29
+ "valid-00000-of-00001.parquet"
30
+ ],
31
+ "valid": [
32
+ "test-00000-of-00001.parquet",
33
+ "train-00000-of-00004.parquet",
34
+ "train-00001-of-00004.parquet",
35
+ "train-00002-of-00004.parquet",
36
+ "train-00003-of-00004.parquet",
37
+ "valid-00000-of-00001.parquet"
38
+ ],
39
+ "test": [
40
+ "test-00000-of-00001.parquet",
41
+ "train-00000-of-00004.parquet",
42
+ "train-00001-of-00004.parquet",
43
+ "train-00002-of-00004.parquet",
44
+ "train-00003-of-00004.parquet",
45
+ "valid-00000-of-00001.parquet"
46
+ ]
47
+ }
48
+ }