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/model/label_downsample.py from MRiabov/WireSegHR: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/MRiabov/WireSegHR/resolve/main/src/wireseghr/model/label_downsample.py
- Command line
-
hf download hf://MRiabov/WireSegHR/src/wireseghr/model/label_downsample.py
-
curl -L -o label_downsample.py https://huggingface.co/MRiabov/WireSegHR/resolve/main/src/wireseghr/model/label_downsample.py
861 Bytes
| # MaxPool-based downsampling for coarse labels | |
| """Downsample binary masks preserving thin positives. | |
| We use area-based resize on float32 masks followed by a >0 threshold. | |
| This emulates block-wise max pooling: any positive in the source region | |
| produces a positive in the target pixel. | |
| """ | |
| import numpy as np | |
| def downsample_label_maxpool(mask: np.ndarray, out_h: int, out_w: int) -> np.ndarray: | |
| """ | |
| Args: | |
| mask: HxW binary (0/1) numpy array | |
| out_h, out_w: target size | |
| Returns: | |
| H'xW' binary array via max-pooling-like downsample | |
| """ | |
| assert mask.ndim == 2 | |
| # Convert to float32 so area resize yields fractional averages > 0 if any positive present | |
| import cv2 | |
| m = mask.astype(np.float32) | |
| r = cv2.resize(m, (out_w, out_h), interpolation=cv2.INTER_AREA) | |
| out = (r > 0.0).astype(np.uint8) | |
| return out | |