# ๐Ÿ”Œ 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 / . --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)*