Models / DINOv3 ViT-L
code
hubAttention · Vision Transformer

DINOv3 ViT-L

Meta's self-supervised vision transformer, adapted to nine weapon classes with a lightweight LoRA fine-tune.

analytics94.9% clean · 97.2% leaky9 classes · ~720 imagesLoRA fine-tune
Concepts in play
play_circleDINOv3 — image patches, self-attention, a trained 9-class head
  1. The image is cut into a grid of patches; each patch becomes a token, and a special CLS token is prepended to summarise the whole image.
  2. Self-attention lets the CLS query attend to every patch at once — thicker arcs mean more attention. A transformer sees globally from the first layer, where a CNN only sees a small local window.
  3. Only the LoRA adapters on the attention projections and the fresh head are trained; the 300M-parameter backbone stays frozen.
  4. The contextualised CLS token feeds the head, which scores the nine weapon classes.
How it works

The attention model

DINOv3 is a large vision transformer from Meta, pretrained self-supervised on a very large image collection. It reads an image as a grid of patches and uses self-attention to relate every patch to every other, so it learns global structure rather than only local texture.

Training the whole backbone on a few hundred weapon images would overfit instantly, so we kept the backbone frozen and adapted it with LoRA — a handful of small low-rank matrices on the attention projections plus a fresh 9-class head. That is roughly 3 MB of trainable weights on top of a 300 M-parameter backbone.

It is the attention half of a deliberate contrast: DINOv3 (attention) versus ConvNeXt-V2 (convolution), two opposite design philosophies measured on the same data.

At a glanceSpecification
BackboneDINOv3 ViT-L/16 (self-supervised, Meta)
Backbone parameters~300 M (frozen)
Trainable parameters~3 MB — LoRA + linear head
Input224×224 → 16×16 patches → 196 tokens + CLS
AdaptationLoRA (rank-r) on attention q_proj / v_proj
Classifier headLinear on the CLS token → 9 classes

Patches and tokens

A vision transformer does not slide kernels over pixels. It cuts the 224×224 image into a grid of non-overlapping 16×16 patches — 196 of them — flattens each into a vector, and linearly projects it into a token. A learned positional encoding is added so the model still knows where each patch came from, and a special learnable CLS token is prepended to stand in for the whole image.

From this point the image is just a sequence of 197 tokens. Everything the network does is token-to-token; there is no notion of a local pixel neighbourhood baked into the architecture.

Self-attention: every token sees every other

In each layer every token produces a query, a key, and a value. Attention scores each token against every other as softmax(Q·Kᵀ / √d), then mixes the values by those weights. The practical consequence is a global receptive field from the very first layer — any patch can be informed by any other patch, however far apart. A CNN only reaches that after many stacked layers grow its receptive field.

Classification reads off the CLS token, which has spent every layer aggregating a whole-image summary. This global view is why transformers are strong at relating distant parts of an object — useful when a weapon's identity depends on the relationship between its parts (a stock, a barrel, a grip) rather than any single local texture.

Frozen backbone, LoRA adaptation

Fine-tuning all 300 M backbone parameters on a few hundred weapon images would overfit almost immediately. Instead the backbone is frozen and adapted with LoRA: for a weight matrix W, training learns a small low-rank update ΔW = B·A (with A, B much smaller than W) added only to the attention q_proj and v_proj. The pretrained features are preserved; the model is nudged, not rewritten.

Only those low-rank matrices and the new 9-class head are trainable — roughly 3 MB on top of a frozen 300 M-parameter backbone. It is fast, hard to overfit, and the same checkpoint loads on top of the public DINOv3 weights.

Design choice

Why we chose it

We needed a model that could learn nine classes from only a few hundred images. DINOv3's self-supervised pretraining yields features that transfer extremely well with little labelled data, which makes it the natural choice for the data-scarce regime this dataset sits in.

It also sets up a clean architectural contrast: DINOv3 is pure self-attention, ConvNeXt-V2 is pure convolution. Running both on the identical clean split tests whether the result depends on the architecture or on the data — and, as the results show, it is the data.

Training

How we fine-tuned it

Fine-tuning all ~300 M backbone parameters on a few hundred images would overfit immediately, so the backbone is frozen and only the LoRA adapters on the attention projections plus a fresh linear head are trained — about 3 MB of weights. The pretrained representation is preserved, not rewritten. To push back on the small-data regime we also augment heavily: the online transforms above, plus a DiffuseMix corpus that expands the clean training images roughly fivefold with diffusion-generated variations.

We train for 30 epochs but keep the best-validation checkpoint, not the last. The curve below shows why: clean-split accuracy peaks at epoch 8 (94.9%) and then drifts down as the small training set begins to overfit. Every number reported on this page is that peak checkpoint, and the prediction files used for the metrics come from it.

Fine-tuningSetting
StrategyFrozen backbone + LoRA + new linear head
Trainable weightsLoRA (q_proj, v_proj) + head — ~3 MB
LoRA configrank r=8 · α=16 · dropout 0.05
OptimizerAdamW · weight decay 0.05
Learning rate1e-3 · cosine annealing
Epochs / batch30 / 16 · best-val checkpoint kept
PrecisionAMP fp16
Augmentation (online)TrivialAugment + RandomErasing + MixUp/CutMix + label smoothing
Augmentation (corpus)DiffuseMix (CVPR 2024) — clean training set expanded ~5× (395 → 1,975 generated views)
Hardwaresingle RTX 3060 (12 GB)
Seed42
DINOv3 ViT-L validation accuracy per epoch on both splits
Validation accuracy per epoch on both splits. Marked peaks are the kept checkpoints — clean ep 8 = 94.9%, original ep 5 = 97.2%; accuracy declines afterward as the ~400-image training set overfits.

Compare the other design

ConvNeXt-V2-L — Convolution · Modern CNN

view_in_arView ConvNeXt-V2-L

Sources & further reading

A 9-class weapons image classifier, audited end to end: a dataset that leaks ~31% duplicates, the accuracy inflation that leakage hides, and two opposite frontier architectures that finish in a statistical tie on genuinely unseen images.

scienceTry it · Live inference

DINOv3 ViT-L · Live Inference

Real forward passes on CPU: the nine-class prediction, an out-of-distribution signal and robustness probes. Try a non-weapon and watch what a closed-set model does.

DINOv3 ViT-L · CPU
analytics97.2% orig · 94.9% cleanWeapons · 9-class300M (LoRA)In this workshop:PredictionsAttention mapsFGSM attackCorruptionsOOD signal
Recognizes9 weapon categories9 classes · bazooka, grenade launcher, rifle, shotgun, smg, sniper, knife, sword, handgun
Accuracy97.2% orig · 94.9% clean97.2% on the original split, 94.9% on the clean (leakage-proof) split
Works best onA photo of one of the nine weapon typesResized to 224×224 color, ImageNet-normalized.
warning
Expect confident mistakes outside its scope

This model only knows nine weapon classes and has no "no weapon" option. Shown an ordinary object — an animal, a vehicle, a face — it will still return a weapon label, sometimes confidently. We measured this directly: 27 of 27 non-weapons were labelled as weapons. Treat the confidence value, not just the label, as the signal.

Concepts in play

Top-5 Predictions

Upload an image and run analysis to see predictions.

info

No Grad-CAM for DINOv3 ViT-L: it is a vision transformer, so there is no final convolutional feature map for Grad-CAM to localize over. The transformer-native equivalent is the Attention map (tab above), showing which image patches the classification token attends to. The convolutional model, ConvNeXt-V2, exposes Grad-CAM.

These flagships are closed-set: every image is forced into one of the nine weapon classes. Confidence and entropy are the only signal that an input doesn't belong — there is no "no weapon" option.

Input

image

Confidence vs. OOD

reject < 0.80low confidencehigh confidence
Real weapons (~96%) Non-weapons (~55% median)

Confidence (top-1)

—

Run analysis to compute

Inference Latency

—

CPU forward pass