--- license: other license_name: mixed-apache-2.0-dinov3-cc-by-nc-4.0 license_link: https://huggingface.co/chandlerWang/BruNet#licence pipeline_tag: image-segmentation tags: - medical-imaging - bruise-segmentation - skin-lesion-segmentation - segment-anything - dinov3 - vision-transformer --- # BruNet Weights for BruNet ([*BruNet: A Cross-Domain Transfer Framework for Bruise Segmentation*](https://arxiv.org/html/2609.11463v1)). BruNet trains only on HAM10000 skin-lesion masks and segments bruises in photographs without bruise labels and without any prompt. This repository holds the weights and the code that runs them: the `clipdinosam` Python package, as source and as an installable wheel. | Folder | Encoder | Input | Bruise F1 | Bruise IoU | |---|---|---|---:|---:| | [`lingbot/`](lingbot) | LingBot-Vision ViT-B/16 | 512 × 512 | **0.8911** | **0.8251** | | [`dinov3/`](dinov3) | DINOv3 ViT-B/16 | 224 × 224 | 0.8081 | 0.7289 | Each folder contains: - `model.safetensors`: the full model `state_dict` (fp32, 92 M values, 368 MB). The optimizer and RNG state of the training checkpoint are not included. - `config.yaml`: the training config stored in the checkpoint. The two dataset paths are replaced with `/path/to/...` placeholders. Code: - `clipdinosam/`: the package source (model definition, weight loader, trainer). - `dist/clipdinosam-0.1.0-py3-none-any.whl`: the same code as a wheel. - `pyproject.toml`: dependencies. Running the DINOv3 model needs only the core set. ## Model - **Encoder.** ViT-B/16. LingBot-Vision takes a 512 × 512 input and yields a 32 × 32 token grid; DINOv3 takes 224 × 224 and yields 14 × 14. - **Adapter.** Projects the token grid to 256 channels, upsamples it bilinearly to 56 × 56 and applies two 3 × 3 convolution blocks (GroupNorm with 8 groups, GELU). The output has the shape of a SAM ViT-B image embedding, so one decoder serves both encoders. - **Decoder.** The architecture of the SAM ViT-B mask decoder, randomly initialised: no SAM weights are loaded. Its 44 linear layers stay at their random initialisation and receive rank-8 LoRA updates; its normalisation layers, output tokens, prompt embeddings and upscaling convolutions train directly. - **No prompt.** The sparse prompt holds only SAM's padding-point token and the dense prompt its no-mask embedding, the same for every image, in training and at test time. - **Output.** One logit map (`low_res_masks`, 224 × 224). Upsample it to the image size, apply a sigmoid and threshold at 0.5. ## Training - **Data.** HAM10000 lesion masks: 7,010 training images, each used as captured and after Multi-Scale Retinex with Chromaticity Preservation (MSRCP), giving 14,020 samples. No bruise image was used for training, checkpoint selection or threshold choice. - **Recipe.** AdamW, bfloat16, Dice plus binary cross-entropy loss. No text encoder and no auxiliary loss. - **DINOv3.** 150 epochs at learning rate 2e-5 on 224 × 224 crops, batch 64. - **LingBot.** 10 epochs with the backbone frozen, then 40 epochs unfrozen (backbone 3e-6, adapter 2e-5, LoRA 3e-4) on 512 × 512 crops, batch 8 with 8 gradient-accumulation steps. - **Checkpoint.** The lowest-training-loss epoch: epoch 148 of 150 (DINOv3) and epoch 40 of the 40 unfrozen epochs (LingBot). - **Validation.** HAM10000 validation Dice at threshold 0.5 (1,502 images, both views): LingBot 0.9559, DINOv3 0.9579. For both models, 0.5 is the Dice-maximising threshold on this split among ten values from 0.5 to 0.999. ## Bruise results 86 bruise photographs (256 × 256), each with two expert contours: pixels inside the confident inner contour are bruise, pixels outside the permissive outer contour are background, and the band between them is ignored. Threshold 0.5; each metric is computed per image and averaged over the 86 images. F1 is identical to Dice. | Model | Precision | Recall | F1 | IoU | Accuracy | |---|---:|---:|---:|---:|---:| | BruNet-LingBot (`lingbot/`) | 0.9126 | 0.9003 | 0.8911 | 0.8251 | 0.9583 | | BruNet-DINOv3 (`dinov3/`) | 0.7793 | 0.9202 | 0.8081 | 0.7289 | 0.9181 | ## Usage Install the code. Python 3.10 or newer. ```bash # BruNet-DINOv3 pip install https://huggingface.co/chandlerWang/BruNet/resolve/v0.1.0/dist/clipdinosam-0.1.0-py3-none-any.whl # BruNet-LingBot: also installs the official LingBot-Vision code at the commit used for the paper pip install "clipdinosam[lingbot] @ https://huggingface.co/chandlerWang/BruNet/resolve/v0.1.0/dist/clipdinosam-0.1.0-py3-none-any.whl" ``` Load a model and get the bruise probability map of an image: ```python from clipdinosam.hub import load_brunet, predict_proba model = load_brunet("dinov3") # or "lingbot"; add device="cuda" for a GPU prob = predict_proba(model, "bruise.jpg") # float32 array, H x W, values in [0, 1] mask = prob >= 0.5 ``` - `load_brunet` downloads the config and weights from this repository and returns the model in eval mode with gradients switched off (`freeze=False` keeps them). Every weight comes from `model.safetensors`; the original DINOv3 or LingBot-Vision checkpoint is not needed. - `predict_proba` takes a file path or an H x W x 3 uint8 RGB array. It follows the evaluation path of the paper: resize to `model.input_size`, ImageNet normalisation, bilinear upsampling of the logits to the image size, sigmoid. - For batches, call the model on a normalised `B x 3 x S x S` tensor, `S = model.input_size`: `logits = model(x)["low_res_masks"][:, :1]` has shape `B x 1 x 224 x 224`. The optional `train` extra adds the libraries used by the trainer and by components that BruNet does not use (CLIP text encoder, DINOv2 and Swin backbones). **Tested.** The loader reproduces the two table rows above on `transformers` 4.56.0 and 5.24.0, on GPU (torch 2.7) and on CPU (torch 2.15), including a clean environment with only the wheel installed. Across devices and library versions about 80 of 5.6 million pixels change side, which moves a metric by at most 0.0001. `transformers` 5.4 renamed the DINOv3 encoder keys; the package loads these weights under either naming. ## Limitations - Evaluated on 86 bruise photographs only; per-image skin-tone and age labels were not collected. - Research use only; not validated for clinical or forensic use. ## Licence | Part | Licence | |---|---| | Code: `clipdinosam/`, `pyproject.toml`, `dist/` | Apache License 2.0, see [`LICENSE`](LICENSE) | | `dinov3/model.safetensors` | DINOv3 License, see [`dinov3/LICENSE.md`](dinov3/LICENSE.md). These weights are a fine-tuned derivative of Meta's DINOv3 ViT-B/16, which may be redistributed only under that agreement. | | `lingbot/model.safetensors` | CC BY-NC 4.0, see [`lingbot/LICENSE.md`](lingbot/LICENSE.md). The encoder was fine-tuned from LingBot-Vision ViT-B/16 (Apache License 2.0). | Both models were trained on HAM10000, which is distributed under CC BY-NC 4.0. Use both for non-commercial research only. ## Citation ```bibtex @article{wang2026brunet, title = {BruNet: A Cross-Domain Transfer Framework for Bruise Segmentation}, author = {Wang, Qiming and Motley, Richard J. and Obi, Ebube E. and Sun, Xianfang and Rosin, Paul L.}, journal = {arXiv preprint arXiv:2609.11463}, year = {2026} } ``` BruNet builds on DINOv3 (Meta), LingBot-Vision (Robbyant), the Segment Anything mask decoder (Meta) and HAM10000 (Tschandl et al.).