Instructions to use HCedric/IMPACTSeg with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KonfAI
How to use HCedric/IMPACTSeg with KonfAI:
pip install "konfai[imaging]" konfai-apps
# List the apps this repository holds konfai-apps list HCedric/IMPACTSeg # Run one of them on an image konfai-apps infer HCedric/IMPACTSeg:<app> -i image.nii.gz -o Output
- Notebooks
- Google Colab
- Kaggle
Download extension/src/lib.rs from HCedric/IMPACTSeg: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/HCedric/IMPACTSeg/resolve/main/extension/src/lib.rs
- Command line
-
hf download hf://HCedric/IMPACTSeg/extension/src/lib.rs
-
curl -L -o lib.rs https://huggingface.co/HCedric/IMPACTSeg/resolve/main/extension/src/lib.rs
1.56 kB
| // SPDX-License-Identifier: Apache-2.0 | |
| //! IMPACT-Seg's extension of KonfAI Edge. | |
| use konfai_edge_ext::{Opened, PatchCombine}; | |
| /// Each pixel keeps the label of the patch surest of it: a patch is `[label, score]`, the higher score stays, the | |
| /// later patch's at a tie, and the labels are written. | |
| struct MostConfident; | |
| impl PatchCombine for MostConfident { | |
| fn output_channels(&self, _channels: usize) -> usize { | |
| 1 | |
| } | |
| fn fold(&self, held: &mut [&mut [f32]], patch: &[&[f32]]) { | |
| let ([labels, scores], [patch_labels, patch_scores]) = (held, patch) else { | |
| panic!("MostConfident folds [label, score]") | |
| }; | |
| let patch = patch_labels.iter().zip(patch_scores.iter()); | |
| for ((label, score), (&patch_label, &patch_score)) in labels.iter_mut().zip(scores.iter_mut()).zip(patch) { | |
| let keep = patch_score >= *score; | |
| *label = if keep { patch_label } else { *label }; | |
| *score = if keep { patch_score } else { *score }; | |
| } | |
| } | |
| fn leave(&self, held: &[&[f32]], output: &mut [&mut [f32]]) { | |
| output[0].copy_from_slice(held[0]); | |
| } | |
| } | |
| /// The classes of the app's own, by the classpath its configs name each by. The classes the model ignores are | |
| /// zeroed as a patch enters the fold, in the model's graph: the fold reads none of its parameters. | |
| fn open(name: &str, _params: &str) -> Option<Opened> { | |
| (name == "fusion:MostConfident").then(|| Opened::PatchCombine(Box::new(MostConfident))) | |
| } | |
| konfai_edge_ext::export!(open); | |