RefDiffNet / README.md
ShashwatGupta23's picture
Fix startup: pin Python 3.10 for Gradio/pydub audioop
63a615f
|
Raw History Blame
2.88 kB
---
title: RefDiffNet
emoji: 🔬
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: "4.44.0"
python_version: "3.10"
app_file: app.py
pinned: false
license: agpl-3.0
---
# RefDiffNet — PCB Reference–Defect Enrichment (A11_CA)
**Space:** [vinayedula/RefDiffNet](https://huggingface.co/spaces/vinayedula/RefDiffNet)
Gradio demo for the **A11_CA** prebackbone trained with YOLO12n on HR-IPCB.
- **Inputs:** defect PCB image + golden reference image
- **Output:** enriched image (`enriched = defect + α · gate · delta`)
Weights: `weights/prebackbone_a11_ca.pt` (~few MB, prebackbone only — not full `best.pt`)
## Deploy to Hugging Face Spaces
### 1. Prepare the Space folder locally
From the VYOLO repo root:
```bash
cd /mnt/data/vinay/work/VYOLO
bash hf_prebackbone_demo/prepare_space.sh
```
This will:
- Copy the custom **Ultralytics** fork into `hf_prebackbone_demo/vendor/`
- Extract `prebackbone_a11_ca.pt` from `best.pt` (small file for the Space)
- Copy example image pairs into `hf_prebackbone_demo/examples/`
### 2. Create a new Space on Hugging Face
1. Go to [huggingface.co/new-space](https://huggingface.co/new-space)
2. Choose **Gradio** SDK
3. Clone the empty Space repo locally
### 3. Push to [vinayedula/RefDiffNet](https://huggingface.co/spaces/vinayedula/RefDiffNet)
```bash
cd hf_prebackbone_demo
bash deploy_to_refdiffnet.sh
```
Or manually:
```bash
git clone https://huggingface.co/spaces/vinayedula/RefDiffNet
cd RefDiffNet
# copy app.py, vendor/, weights/prebackbone_a11_ca.pt, examples/, etc.
git add . && git commit -m "RefDiffNet demo" && git push
```
> **Note:** `prebackbone_a11_ca.pt` is only a few MB (no LFS needed). Full `best.pt` is optional.
### 4. Space settings (recommended)
| Setting | Value |
|---------|--------|
| Hardware | CPU Basic (works) or **GPU** for faster loads |
| Secrets | Optional: `HF_TOKEN` if weights are in a private model repo |
### Alternative: host weights on the Hub
Upload `prebackbone_a11_ca.pt` to a model repo, then set:
```
HF_MODEL_REPO=YOUR_USER/YOUR_MODEL
```
The app downloads `prebackbone_a11_ca.pt` from that repo.
## Run locally
```bash
cd hf_prebackbone_demo
pip install -r requirements.txt
pip install -e ../ultralytics # custom fork with A11_CA
python extract_prebackbone_weights.py --ckpt /path/to/best.pt
export PREBACKBONE_ONLY_WEIGHTS=weights/prebackbone_a11_ca.pt
python app.py
```
Open http://localhost:7860
## Environment variables
| Variable | Description |
|----------|-------------|
| `PREBACKBONE_ONLY_WEIGHTS` | Path to `prebackbone_a11_ca.pt` |
| `PREBACKBONE_FULL_CKPT` | Full `best.pt` (only for one-time extraction) |
| `HF_MODEL_REPO` | Hub repo with `prebackbone_a11_ca.pt` |
| `PREBACKBONE_IMGSZ` | Letterbox size (default `640`) |
| `ULTRALYTICS_ROOT` | Path to ultralytics repo if not vendored |
| `PORT` | Gradio port (default `7860`) |