split / implementation_plan.md
FaustDerLegende's picture
Upload folder using huggingface_hub (part 61)
11a414e verified
|
Raw History Blame Contribute Delete
4.31 kB

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

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

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

  • 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

  • Search query expansion matrix across search terms, condition variants, board types, and multilingual terms.

[NEW] 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

  • 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

  • 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

  • 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

  • Multi-tier deduplication engine (SHA-256 exact byte hash + perceptual pHash/dHash with horizontal flip awareness).

[NEW] scraper.py

  • Unified CLI entry point supporting subcommands: harvest, validate, process, dedup, report.

[NEW] 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:
      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.