Spaces:
Sleeping
Sleeping
File size: 2,879 Bytes
add24bd 63a615f add24bd | 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | ---
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`) |
|