| |
| """ |
| 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 |
|
|
| |
| 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() |
|
|