File size: 4,309 Bytes
11a414e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Implementation Plan: E-Waste Dataset Scraper & Pipeline (v2 Architecture)

Build a modular, production-grade Python web scraper and image preprocessing pipeline following `scraper_plan_v2.md` to harvest, clean, deduplicate, and prepare high-resolution e-waste PCB dataset images for fine-tuning YOLOv8 micro-component detectors.

## User Review Required

> [!IMPORTANT]
> **Scraping Target & Volume:** The pilot harvest target will be set to **500 images per query batch** across Bing and Flickr to keep the pilot run under 10–15 minutes while establishing real attrition rates.
> **Dependency Note:** `icrawler`, `pillow`, `imagehash`, and `open_clip_torch` (or lightweight CLIP filtering) will be installed in the environment.

## Open Questions

> [!NOTE]
> **CLIP Relevance Filter Mode:** Should the initial script execute CLIP zero-shot relevance filtering locally via PyTorch, or fall back to rule-based aspect-ratio/color-histogram heuristic filtering if PyTorch GPU memory is constrained during background runs? (Default: Rule-based + optional CLIP module).

---

## Proposed Changes

### Scraping & Pipeline Package (`ewaste_dataset_pipeline/`)

Creation of a self-contained, modular Python CLI pipeline under `ewaste_dataset_pipeline/`.

#### [NEW] [`config/taxonomy.yaml`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/config/taxonomy.yaml)
- Defines the 5 target YOLO detection classes: `cpu_socket`, `gold_finger`, `ic_chip`, `tantalum_capacitor`, `desoldered_zone`.
- Defines image-level tags: `board_type`, `condition`, `source_type`.

#### [NEW] [`config/queries.yaml`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/config/queries.yaml)
- Search query expansion matrix across search terms, condition variants, board types, and multilingual terms.

#### [NEW] [`pipeline/manifest.py`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/pipeline/manifest.py)
- SQLite database abstraction layer (`manifest.db`) tracking URL provenance, download status, MD5 checksums, resolution, pHash values, cluster IDs, and split assignments.

#### [NEW] [`pipeline/crawler.py`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/pipeline/crawler.py)
- URL harvester using `icrawler` (Bing, Flickr, Baidu) with exponential backoff retries, custom headers, and rate limiting. Saves raw bytes to `data/originals/`.

#### [NEW] [`pipeline/validator.py`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/pipeline/validator.py)
- Validation engine checking file integrity (`verify()` + `load()`), short/long resolution cutoffs ($\ge 480\text{ px}$ short side), and aspect ratio bounds (flag $> 3:1$, drop $> 6:1$).

#### [NEW] [`pipeline/processor.py`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/pipeline/processor.py)
- Image normalizer handling EXIF auto-rotation (`exif_transpose`), RGBA alpha white-background compositing, CMYK to RGB conversion, and JPEG 95 quality encoding.

#### [NEW] [`pipeline/dedup.py`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/pipeline/dedup.py)
- Multi-tier deduplication engine (SHA-256 exact byte hash + perceptual `pHash`/`dHash` with horizontal flip awareness).

#### [NEW] [`scraper.py`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/scraper.py)
- Unified CLI entry point supporting subcommands: `harvest`, `validate`, `process`, `dedup`, `report`.

#### [NEW] [`requirements.txt`](file:///home/taruns/sih2026_kabadiwala/ewaste_dataset_pipeline/requirements.txt)
- Dependency specifications (`icrawler`, `Pillow`, `imagehash`, `pyyaml`, `tqdm`).

---

## Verification Plan

### Automated Verification
1. **Unit & Module Tests:**
   - Test image validation on corrupted, truncated, transparent PNG, CMYK, and EXIF-rotated sample images.
   - Verify pHash deduplication on identical vs resized/flipped images.
2. **CLI Execution Runs:**
   - Execute pilot harvest run:
     ```bash
     cd ewaste_dataset_pipeline
     python3 scraper.py harvest --max-num 50
     python3 scraper.py validate
     python3 scraper.py process
     python3 scraper.py dedup
     python3 scraper.py report
     ```

### Manual Verification
- Inspect generated `reports/summary.json` to verify image yield, discard counts by reason, and clean `dataset_raw/` outputs.