g-loubna commited on
Commit
cd5886d
·
1 Parent(s): 6ba0066

Add README with Space metadata1

Browse files
Files changed (1) hide show
  1. README.md +17 -196
README.md CHANGED
@@ -4,8 +4,6 @@ emoji: 🛰️
4
  colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.37.2
8
- python_version: 3.10
9
  app_file: app.py
10
  pinned: false
11
  license: apache-2.0
@@ -18,201 +16,24 @@ An interactive Hugging Face Space for segmenting bridge inspection images into:
18
  - **beton** (concrete)
19
  - **steel**
20
 
21
- The model architecture is **UNet++**. Large weights are stored separately in a model repo and downloaded automatically on first run (cached afterwards).
22
 
23
- > First launch may take a few minutes while the ~800MB weight file downloads.
 
 
 
 
 
24
 
25
- ---
26
-
27
- ## 🚀 Quick Start (Using the Space)
28
-
29
- 1. Open the Space page (this UI).
30
- 2. Upload or paste an RGB image (bridge / structural element).
31
- 3. Choose a visualization mode:
32
- - Colored Mask
33
- - Overlay
34
- - Raw Class Indices (grayscale)
35
- 4. (Optional) Adjust:
36
- - Overlay Opacity (for Overlay mode)
37
- - Background Opacity (for Colored Mask mode)
38
- 5. Click **Run Segmentation**.
39
- 6. Review legend + per‑class pixel counts & percentages.
40
- 7. Download the raw mask (PNG) if needed.
41
-
42
- ---
43
-
44
- ## 🧠 Model Weights
45
-
46
- Weights are pulled from the model repository:
47
-
48
- ```
49
- g-loubna/bridge-unetpp
50
- ```
51
-
52
- In `app.py`:
53
- ```python
54
- HUB_REPO_ID = "g-loubna/bridge-unetpp"
55
- WEIGHTS_FILENAME = "MILESTONE_090_ACHIEVED_iou_0.9077.pth"
56
- ```
57
-
58
- Modify these if you update or rename the weight file. Keep the filename stable to leverage caching.
59
-
60
- ---
61
-
62
- ## 🗂 Repository Structure
63
-
64
- | File | Purpose |
65
- |------|---------|
66
- | `app.py` | Gradio interface + weight download logic |
67
- | `inference.py` | Helper functions for loading model & running prediction |
68
- | `model.py` | Model architecture / wrapper code |
69
- | `style.css` | Custom UI styling |
70
- | `requirements.txt` | Python dependencies |
71
- | `.gitignore` | Excludes venv, caches, large artifacts |
72
-
73
- ---
74
-
75
- ## 📦 Dependencies (from `requirements.txt`)
76
- Key packages (versions resolved by the Space at build time):
77
- ```
78
- gradio
79
- torch
80
- torchvision
81
- timm
82
- segmentation-models-pytorch
83
- numpy
84
- Pillow
85
- huggingface-hub
86
- ```
87
-
88
- If a future build fails due to incompatible Torch / CUDA combos, pin Torch + torchvision versions explicitly.
89
-
90
- ---
91
-
92
- ## 🖥 Local Development
93
-
94
- ```bash
95
- git clone https://huggingface.co/spaces/Suzyloubna/Bridge.Semantic.Segmentation
96
- cd Bridge.Semantic.Segmentation
97
- python -m venv venv
98
- venv\Scripts\activate # (Windows) OR source venv/bin/activate (Linux/Mac)
99
- pip install -r requirements.txt
100
-
101
- # (Optional) Manually fetch weights if you want to avoid first-run download delay:
102
- python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='g-loubna/bridge-unetpp', filename='MILESTONE_090_ACHIEVED_iou_0.9077.pth')"
103
-
104
- python app.py
105
- ```
106
-
107
- Then open the local Gradio link it prints.
108
-
109
- ---
110
-
111
- ## 🎨 Visualization Modes
112
-
113
- | Mode | Description | Notes |
114
- |------|-------------|-------|
115
- | Colored Mask | Pure color rendering per class | Background alpha adjustable |
116
- | Overlay | Blends original image + color mask | Alpha slider controls blend |
117
- | Raw Class Indices | Grayscale index visualization | Pixel values scaled 0–255 |
118
-
119
- ---
120
-
121
- ## 📊 Legend & Statistics
122
-
123
- The legend shows:
124
- - Class ID & name
125
- - Pixel count
126
- - Percentage of total area
127
-
128
- This is computed after each run using a NumPy bincount on the predicted mask.
129
-
130
- ---
131
 
132
- ## 🧪 Inference Flow
133
-
134
- 1. Load / download weights (only if not present).
135
- 2. Preprocess image (convert to tensor as defined in `inference.py`).
136
- 3. Forward pass through UNet++ model.
137
- 4. Argmax over class dimension → class index mask.
138
- 5. Post-process & display in selected mode.
139
- 6. Generate stats + optional downloadable raw mask.
140
-
141
- ---
142
-
143
- ## 🔄 Updating the Weights
144
-
145
- If you generate improved weights:
146
- 1. Upload new `.pth` to the model repo (`g-loubna/bridge-unetpp`).
147
- 2. Either keep the same filename OR update:
148
- - `WEIGHTS_FILENAME` in `app.py`
149
- 3. Commit & push the Space:
150
- ```bash
151
- git add app.py
152
- git commit -m "Update to new weights file"
153
- git push
154
- ```
155
- 4. First Space run after that re-downloads the new file.
156
-
157
- ---
158
-
159
- ## 🧹 Not Tracked (Good)
160
-
161
- - `venv/`
162
- - `__pycache__/`
163
- - Large weight file (`.pth`) — intentionally excluded; downloaded at runtime.
164
-
165
- ---
166
-
167
- ## 🛠 Troubleshooting
168
-
169
- | Issue | Cause | Fix |
170
- |-------|-------|-----|
171
- | Build error: `python:3.1 not found` | Typo in `python_version` | Use `3.10` in front matter |
172
- | `ModuleNotFoundError: huggingface_hub` | Missing dependency | Add to `requirements.txt`, push |
173
- | Long startup time | First-time weight download | Wait; subsequent runs are faster |
174
- | Authentication error when pushing | Wrong token / no write scope | Create token with read+write scopes |
175
- | Blank UI / model error | Weight not downloaded | Check logs for download failure |
176
-
177
- ---
178
-
179
- ## 🔐 Tokens & Auth (For Development Pushes)
180
-
181
- Generate token: https://huggingface.co/settings/tokens
182
- Use as password for `git push` (username = your HF username).
183
-
184
- ---
185
-
186
- ## 📄 License
187
-
188
- Licensed under **Apache-2.0** (see `license` field).
189
- Change to `mit` in header and add a LICENSE file if you prefer MIT—ask if you want an MIT license file generated.
190
-
191
- ---
192
-
193
- ## 📌 Roadmap / Ideas
194
-
195
- - Add more structural material classes
196
- - On-the-fly tiling for huge images
197
- - Batch processing / ZIP export
198
- - Per-class IoU benchmark viewer
199
- - Lightweight quantized model for faster inference
200
-
201
- ---
202
-
203
- ## 🙌 Acknowledgements
204
-
205
- - UNet++ architecture inspiration from academic literature.
206
- - Hugging Face for model & Space hosting.
207
- - Gradio for rapid UI prototyping.
208
-
209
- ---
210
-
211
- ## ✅ Status
212
-
213
- If you see this README rendered correctly, the Space config front‑matter is valid.
214
- Check the Logs panel if something fails during runtime.
215
-
216
- ---
217
 
218
- Feel free to open an issue / request enhancements (or ask here) if you need more features.
 
 
4
  colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
 
 
7
  app_file: app.py
8
  pinned: false
9
  license: apache-2.0
 
16
  - **beton** (concrete)
17
  - **steel**
18
 
19
+ > First launch may take a few minutes while the ~800MB weight file downloads from `g-loubna/bridge-unetpp`.
20
 
21
+ ## Features
22
+ - Colored Mask / Overlay / Raw Class Indices modes
23
+ - Adjustable background transparency (Colored Mask)
24
+ - Adjustable overlay opacity (Overlay)
25
+ - Legend with pixel counts & percentages
26
+ - Downloadable raw mask
27
 
28
+ ## Files
29
+ - `app.py` – Gradio interface + weight download
30
+ - `inference.py` Prediction utilities
31
+ - `model.py` – Model definition/wrapper
32
+ - `style.css` Custom UI styling
33
+ - `requirements.txt` Dependencies
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ ## Troubleshooting
36
+ If build fails with a python:3.1 image again, ensure this header appears exactly as shown (no `python_version` line). Push a new commit.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
+ ## License
39
+ Apache-2.0 (see header). Change `license:` field and add a LICENSE file if you prefer another license.