File size: 6,235 Bytes
ff85f82 | 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | # π E-Waste PCB Component Purity & Cannibalization Index
An Edge-AI system designed for Kabadiwala Connect to detect real-time, on-device PCB component cannibalization (the illicit stripping of valuable components like CPU sockets, gold edge connector fingers, IC microchips, and SMD tantalum capacitors).
The system calculates a dynamic **Board Integrity Score (BIS 0β100)**, applies category scrap grade pricing floors, emits **8-language vernacular voice warnings** to scrap collectors, and tracks intake discrepancy tolerance bands ($<12\%$ pass, $12\text{--}25\%$ advisory, $>25\%$ fraud alert) to stop supply chain fraud.
---
## π Repository & Directory Structure
```
.
βββ README.md # Master project documentation
βββ PROJECT_CONTEXT_AND_ACTION_PLAN.md # Architectural specification & action plan
βββ huggingface_dataset/ # Formatted Hugging Face Hub dataset folder
β βββ README.md # Dataset Card with YAML metadata
β βββ data.yaml # YOLO dataset configuration
β βββ train/ # 5,733 training image & label pairs
β βββ val/ # 1,228 validation image & label pairs
β βββ test/ # 1,229 test image & label pairs
βββ splits/ # Local leak-free cluster-isolated splits
βββ purity_engine/ # Integrity Engine & Vernacular Voice Package
β βββ model_client.py # Mock & TFLite INT8 model abstraction
β βββ board_profiles.json # Baseline component expectations & scrap floors
β βββ purity_assay.py # BIS calculation & dynamic pricing formula
β βββ vernacular_voice.py # 8-language voice alert generator (.opus fallback)
β βββ pcb_analyzer.py # Unified orchestrator entry point
βββ training/ # Custom YOLOv8 training pipeline
β βββ train.py # Fine-tuning & TFLite export script
β βββ train_config.yaml # Copy-paste & class-weighted loss config
βββ pipeline/ # Dataset harvesting, validation & dedup
β βββ auto_annotate.py # Zero-shot YOLO-World auto-annotation engine
β βββ crawler.py # Multi-threaded web harvester (16 threads)
β βββ validator.py # Image integrity & resolution validator
β βββ processor.py # EXIF transpose & image normalizer
β βββ dedup.py # Exact & perceptual hash deduplication
β βββ splitter.py # Cluster-aware dataset partitioner
βββ prepare_hf_dataset.py # Formats splits into huggingface_dataset/
βββ tests/ # Automated pytest test suite (20 tests)
βββ test_purity_assay.py
```
---
## π Dataset Statistics & Hugging Face Hub CLI Upload
The dataset contains **8,190 clean normalized JPEGs** and **6,377 fine-grained bounding boxes**.
### Dataset Partitioning
| 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\%$ |
### π Pushing Dataset to Hugging Face via HF CLI
The dataset is pre-formatted in `huggingface_dataset/` with YAML metadata. Push it directly to your Hugging Face Hub account using the Hugging Face CLI:
```bash
# 1. Login to Hugging Face
huggingface-cli login
# 2. Upload the staged huggingface_dataset directory
cd huggingface_dataset
huggingface-cli upload <your-hf-username>/<your-dataset-name> . --repo-type=dataset
```
---
## π·οΈ 7 Fine-Grained Class 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 |
---
## ποΈ Custom Model Training Pipeline
Fine-tune YOLOv8 on the dataset using **Copy-Paste synthetic augmentation** (`copy_paste: 0.8`) and **elevated class loss gain** (`cls: 2.5`):
```bash
# Run training using project virtual environment
.venv/bin/python training/train.py --epochs 50 --imgsz 960 --batch 8
```
### Dynamic Scrap Grade Price Formula
$$\text{Adjusted Price} = \text{Base Price} \times \left( \text{Floor}_{\text{category}} + (1 - \text{Floor}_{\text{category}}) \times \frac{\text{BIS}}{100} \right)$$
* **Server / GPU PCBs**: $\text{Floor} = 15\%$
* **Desktop PCBs**: $\text{Floor} = 30\%$
* **Low-Grade Power PCBs**: $\text{Floor} = 60\%$
---
## π‘οΈ Running Integrity Assay Engine (`purity_engine`)
```python
from purity_engine import PCBAnalyzer
analyzer = PCBAnalyzer()
# 2-Photo Workflow (Front + Back PCB Photos)
result = analyzer.analyze_board(
front_image="front_top_down.jpg",
back_image="back_bottom_down.jpg",
base_price=100.0,
form_factor="desktop_atx",
lang="hi", # Hindi voice alert
)
print(f"Board Integrity Score: {result['board_integrity_score']}%")
print(f"Adjusted Purchase Price: βΉ{result['adjusted_price']}")
print(f"Voice Alert: {result['voice_alert']['transcript']}")
```
---
## π§ͺ Running Automated Unit Tests
```bash
.venv/bin/python -m pytest tests/test_purity_assay.py tests/test_pipeline.py
```
*(All 20 unit tests passing)*
|