File size: 4,425 Bytes
fe69e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
download_dataset.py — fetch the public datasets that make up the CropGuard corpus.

What it does:
  * Lists every source dataset with its licence and link.
  * Attempts the Kaggle-hosted downloads automatically IF the Kaggle CLI is
    configured (pip install kaggle, and ~/.kaggle/kaggle.json in place).
  * Prints the Mendeley / GitHub links for the sets that must be downloaded by
    hand (Mendeley serves a JS redirect, so scripted download is unreliable).

It does NOT organise images into class folders — run prepare_dataset.py for that.

Usage:
    python download_dataset.py            # show the plan + try Kaggle downloads
    python download_dataset.py --list     # just print the registry, download nothing
    python download_dataset.py --out ./raw_downloads
"""
import argparse, os, shutil, subprocess, sys, textwrap

# (name, kind, identifier, licence note)
REGISTRY = [
    ("CCMT (Cashew/Cassava/Maize/Tomato — collected in Ghana) [PRIMARY]",
     "mendeley", "https://data.mendeley.com/datasets/bwh3zbpkpv/1",
     "Mendeley, typically CC BY 4.0 — verify on page"),
    ("PlantVillage (tomato, pepper, maize cross-checks)",
     "kaggle-dataset", "abdallahalidev/plantvillage-dataset",
     "Free for research — verify the mirror"),
    ("Cassava Leaf Disease (Makerere) — source for cassava_cbsd",
     "kaggle-competition", "cassava-leaf-disease-classification",
     "Kaggle competition rules (research/educational)"),
    ("MangoLeafBD (mango)",
     "mendeley", "https://data.mendeley.com/datasets/hxsnvwty3r/1",
     "CC BY 4.0 — verify"),
    ("Rice Leaf Disease Image Samples (Sethy)",
     "mendeley", "https://data.mendeley.com/datasets/fwcj7stb8r/1",
     "CC BY 4.0 — verify"),
    ("Groundnut Leaf Dataset (Sasmal)",
     "mendeley", "https://data.mendeley.com/datasets/x6x5jkk873/2",
     "CC BY 4.0 — verify"),
    ("Cocoa Diseases YOLOv4 (black pod) — Kaggle",
     "kaggle-dataset", "serranosebas/enfermedades-cacao-yolov4",
     "Verify on page"),
    ("KaraAgroAI Cocoa (CSSVD/healthy/anthracnose)",
     "manual", "arXiv:2405.04535 — see the paper for the dataset repository link",
     "Research/educational — verify"),
    ("BananaLSD (plantain/banana — sigatoka, healthy)",
     "manual", "Data in Brief S2352340923006959 (Kaggle mirrors exist; search 'BananaLSD')",
     "CC BY 4.0 — verify"),
]

NOTE_LOCAL = textwrap.dedent("""
    Crops that need LOCALLY COLLECTED images (weak/no public dataset):
      cowpea (all classes), yam (all), okra (all), garden egg (all),
      plantain_bbtv, plantain_panama, cocoa_capsid, pepper_anthracnose.
    Photograph these in the field — extension officers / research stations can help.
""")


def kaggle_available():
    return shutil.which("kaggle") is not None


def try_kaggle(kind, ident, out):
    if not kaggle_available():
        print("    ! Kaggle CLI not found — skipping (pip install kaggle, add ~/.kaggle/kaggle.json)")
        return
    os.makedirs(out, exist_ok=True)
    if kind == "kaggle-competition":
        cmd = ["kaggle", "competitions", "download", "-c", ident, "-p", out]
    else:
        cmd = ["kaggle", "datasets", "download", "-d", ident, "-p", out]
    print("    >", " ".join(cmd))
    try:
        subprocess.run(cmd, check=True)
        print("    ✓ downloaded (unzip it inside the raw folder)")
    except subprocess.CalledProcessError as e:
        print(f"    ! Kaggle download failed ({e}). For competitions you must accept the rules on the website first.")


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--out", default="./raw_downloads")
    ap.add_argument("--list", action="store_true", help="print the registry only")
    args = ap.parse_args()

    print("=" * 72)
    print("CropGuard GH — dataset sources")
    print("=" * 72)
    for i, (name, kind, ident, lic) in enumerate(REGISTRY, 1):
        print(f"\n[{i}] {name}")
        print(f"    kind:    {kind}")
        print(f"    source:  {ident}")
        print(f"    licence: {lic}")
        if args.list:
            continue
        if kind.startswith("kaggle"):
            try_kaggle(kind, ident, args.out)
        else:
            print("    → download by hand from the link above into:", args.out)

    print(NOTE_LOCAL)
    print("Next: unzip everything into the raw folder, then run prepare_dataset.py")


if __name__ == "__main__":
    main()