File size: 4,104 Bytes
693bf28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
"""Structure and format the 8,190-image dataset into standard Hugging Face Dataset format for CLI push.

Outputs to `huggingface_dataset/`:
  huggingface_dataset/
  β”œβ”€β”€ README.md               # Dataset Card with YAML frontmatter metadata
  β”œβ”€β”€ data.yaml               # YOLO dataset configuration
  β”œβ”€β”€ train/                  # 5,733 images and .txt label pairs
  β”‚   β”œβ”€β”€ images/
  β”‚   └── labels/
  β”œβ”€β”€ val/                    # 1,228 images and .txt label pairs
  β”‚   β”œβ”€β”€ images/
  β”‚   └── labels/
  └── test/                   # 1,229 images and .txt label pairs
      β”œβ”€β”€ images/
      └── labels/
"""
from __future__ import annotations

import json
import shutil
from pathlib import Path

ROOT_DIR = Path(__file__).resolve().parent
SPLITS_DIR = ROOT_DIR / "splits"
HF_DATASET_DIR = ROOT_DIR / "huggingface_dataset"


def build_huggingface_dataset():
    if not SPLITS_DIR.exists():
        raise FileNotFoundError(f"Splits directory not found at {SPLITS_DIR}. Run 'python scraper.py split' first.")

    print(f"Preparing Hugging Face dataset directory at {HF_DATASET_DIR}...")
    if HF_DATASET_DIR.exists():
        shutil.rmtree(HF_DATASET_DIR)
    HF_DATASET_DIR.mkdir(parents=True, exist_ok=True)

    # Copy train, val, test splits
    for split_name in ["train", "val", "test"]:
        src_split = SPLITS_DIR / split_name
        dst_split = HF_DATASET_DIR / split_name
        if src_split.exists():
            shutil.copytree(src_split, dst_split)

    # Copy data.yaml
    shutil.copy2(SPLITS_DIR / "data.yaml", HF_DATASET_DIR / "data.yaml")

    # Create Hugging Face Dataset Card README.md with YAML frontmatter
    readme_content = """---
language:
- en
license: cc-by-4.0
tags:
- computer-vision
- object-detection
- yolo
- ewaste
- pcb
- recycling
- hardware-fraud
size_categories:
- 1K<n<10K
task_categories:
- object-detection
task_ids:
- bounding-box-object-detection
---

# πŸ”Œ E-Waste PCB Component Purity & Cannibalization Dataset

This dataset contains **8,190 normalized high-resolution PCB images** with fine-grained object detection bounding boxes designed for real-time edge AI cannibalization detection in e-waste recycling platforms.

## πŸ“Š Dataset Splits

| Split | Images & Bounding Box Pairs | Ratio |
| :--- | :--- | :--- |
| **Train** | **5,733 images** | $70\%$ |
| **Validation** | **1,228 images** | $15\%$ |
| **Test** | **1,229 images** | $15\%$ |
| **Total** | **8,190 images** | $100\%$ |

---

## 🏷️ 7 Fine-Grained Component Taxonomy

| Class ID | Class Name | Description |
| :--- | :--- | :--- |
| `0` | `cpu_socket` | LGA, PGA, or ZIF processor socket footprints |
| `1` | `gold_finger` | Gold-plated edge connector contacts (PCIe, RAM contacts) |
| `2` | `ic_chip` | Packaged ICs and BGA microchips |
| `3` | `tantalum_capacitor` | SMD tantalum capacitors (molded yellow/black/orange) |
| `4` | `forcibly_desoldered_pad` | Exposed pads with jagged solder, blowtorch marks, torn traces (**fraud signal**) |
| `5` | `factory_unpopulated_pad` | Clean silkscreen outline with smooth solder dots left empty (**NOT fraud**) |
| `6` | `occluded_region` | Footprints obscured by heatsinks, metal shielding, or heavy dust |

---

## πŸ’» Usage with Ultralytics YOLOv8

```python
from ultralytics import YOLO

# Load pre-trained model backbone
model = YOLO("yolov8n.pt")

# Fine-tune on Hugging Face dataset
model.train(data="data.yaml", epochs=50, imgsz=960, copy_paste=0.8, cls=2.5)
```

## βš–οΈ License & Attribution
Released under **Creative Commons Attribution 4.0 International (CC BY 4.0)** for e-waste recycling research and component purity index assaying.
"""

    (HF_DATASET_DIR / "README.md").write_text(readme_content, encoding="utf-8")
    print(f"SUCCESS! Hugging Face dataset formatted and ready at:\n  {HF_DATASET_DIR}")
    print("\nYou can now push to Hugging Face Hub using HF CLI:\n  cd huggingface_dataset\n  huggingface-cli upload <your-hf-username>/<your-repo-name> . --repo-type=dataset")


if __name__ == "__main__":
    build_huggingface_dataset()