Instructions to use MRiabov/WireSegHR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MRiabov/WireSegHR with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="MRiabov/WireSegHR")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("MRiabov/WireSegHR", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download src/wireseghr/data/sampler.py from MRiabov/WireSegHR: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/MRiabov/WireSegHR/resolve/main/src/wireseghr/data/sampler.py
- Command line
-
hf download hf://MRiabov/WireSegHR/src/wireseghr/data/sampler.py
-
curl -L -o sampler.py https://huggingface.co/MRiabov/WireSegHR/resolve/main/src/wireseghr/data/sampler.py
1.28 kB
| # Balanced patch sampler (>=1% wire pixels) | |
| """Balanced patch sampling with >= ``min_wire_ratio`` positives. | |
| Sampling is uniform over valid top-left positions for up to ``max_tries``. | |
| If no patch meets ``min_wire_ratio``, it falls back to the best observed | |
| candidate (highest wire ratio) instead of raising. | |
| """ | |
| from dataclasses import dataclass | |
| import numpy as np | |
| class BalancedPatchSampler: | |
| patch_size: int = 768 | |
| min_wire_ratio: float = 0.01 | |
| max_tries: int = 200 | |
| def sample(self, image: np.ndarray, mask: np.ndarray) -> tuple[int, int]: | |
| h, w = mask.shape | |
| p = self.patch_size | |
| assert h >= p and w >= p, "Image smaller than patch size" | |
| best_ratio = -1.0 | |
| best_y = 0 | |
| best_x = 0 | |
| for _ in range(self.max_tries): | |
| y = np.random.randint(0, h - p + 1) | |
| x = np.random.randint(0, w - p + 1) | |
| m = mask[y : y + p, x : x + p] | |
| ratio = float(m.sum()) / float(p * p) | |
| if ratio > best_ratio: | |
| best_ratio = ratio | |
| best_y, best_x = y, x | |
| if ratio >= self.min_wire_ratio: | |
| return int(y), int(x) | |
| # Fallback: return best candidate even if below threshold | |
| return int(best_y), int(best_x) | |