FaustDerLegende's picture
Upload folder using huggingface_hub (part 53)
ff85f82 verified
|
Raw History Blame Contribute Delete
6.24 kB
# πŸ”Œ 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)*