Published on

Image Classification with DINOv3 — "Portrait Shooting Style"

CAUTION

This article was translated from Chinese by an AI model and may contain inaccuracies. If you find issues, please refer to the original or suggest corrections.

Determining "Portrait Shooting Style"

I used DINOv3 ViT (Visual Transformer) for image classification. One part of it — the test entry for "Portrait Shooting Style" — is available at the Photo Blog.

The first run takes a while, about 20–30s.

photoblog_classify_en
Frontend result
clip_photo_viewer_01
Full result

Concepts

DINOv3 is a family of versatile vision foundation models that outperform specialized state-of-the-art techniques across a wide range of settings without fine-tuning. DINOv3 produces high-quality dense features and excels at a variety of vision tasks, significantly outperforming previous self-supervised and weakly supervised foundation models.

Model familyTypical specsParameter count reference
ViT seriesViT-S/16, ViT-B/16, ViT-L/16, ViT-7B/16, etc.21M ~ 6,716M
ConvNeXt seriesTiny, Small, Base, Large29M ~ 198M

Some common usages listed officially:

…

The final approach for this project is to freeze all Backbone weights so they don't participate in updates, and train only a linear classifier. This is an analytical method for evaluating whether the model's internal representations can be linearly decoded — i.e., a linear probe (Linear Probe).

Backbone: the network that extracts features from images.

Workflow

Flowchart

…

Defining the problem

Portrait shooting styles include: selfie, taken by others.

The selected images all have a portrait as the main subject and an unambiguous shooting style. For the actual application side: 1. a conditional branch for the portrait subject needs to be added to the pipeline; 2. low-confidence results are abstained via a threshold.

Preparing data

…

Prerequisite for images: the subject is a portrait.

Images taken by others are mainly filtered from COCO 2017 person_keypoints.json; selfies mainly come from the Selfie Data Set.

Preparing data:

  1. Use DINOv3 to encode all images (CLS token); DINOv3 output contains three types of tokens, and their uses:
    TokenMeaningUsed in this project
    CLS tokenGlobal semantic aggregation position (the "whole-image representation" for classification/retrieval)✅ Used
    patch tokenRepresentation of each image patch (dense tasks: segmentation, depth, detection)❌ Not used for the classification probe
    register tokenThe "registers" newly added in DINOv3, which absorb global information and improve dense features; not involved in classification❌ Not used as features
  2. Use YOLO26 Pose to analyze the visible body parts in each image;
  3. Use YOLO26 Detect to detect the device used for taking the photo: phone, camera;
  4. Images finally selected into the training pipeline still need a round of manual label correction. Testing with large models to re-label showed that different prompt versions produce different error patterns, so in the end only manual correction works. Common error example: the following is a portrait of someone taking a selfie, but taken by others, and should be labeled "taken by others".
    VCG41634460937
    Example image

Image selection and allocation

tsne_diversity_20261123_181800
Analysis of the two image sources
  • Method 1 (failed): Group by image source. This causes strong coupling between image source × shooting style, so the model learns the source style rather than the shooting style.
    • All COCO images are hard-assigned "taken by others", all UCF images are hard-assigned "selfie".
  • Method 2 (failed): Seed clustering + neighborhood retrieval. The manually defined cluster boundaries are extremely unstable.
    • Label portrait images found via Pexels search, run K-Center clustering within each shooting style → style clusters. Stratified sampling by cluster to val/test.
    • For each cluster, retrieve nearest neighbors from COCO/UCF candidate sources, assign in descending similarity order val/test/train, inherit the cluster label, and correct manually.
  • Method 3 (failed): Group by analytical features. Too fine-grained, insufficient samples, uneven groups.
    • Grouping: shooting style × number of people × body parts × face orientation × device.
    • Within each group, select images with K-Center-Greedy, assign val/test/train.

…
  • Method 4: Portrait area ratio (mean) bucketing.

    BucketRangeMeaning
    b0_40< 40%Long shot
    b40_7040–70%Medium shot
    b70_100≥ 70%Close-up
  • Analysis approach

    1. Perform diversity analysis on each image source to see how many images can represent the source's style.

    2. The selected images go through a round of label correction.

      After label correction, the image counts for the two shooting styles become imbalanced, so more images need to be added.

    3. OOF internal evaluation

      • Data allocation: shooting style × bucket × allocation amount per image source

        Avoid over-concentration; there is a cap on the proportion from each image source.

      • Hyperparameter C configuration. The sample size used for OOF is much larger than in the training pipeline, so differences in C can be distinguished.

        Cbalancedmacro
        1.092.8892.70
        0.193.0392.85
        0.0393.2493.06
        0.0193.5593.33
        0.00394.1593.91
        0.00194.3494.07
        0.000393.4093.18
      • Quota evaluation. The conf value is used on the application side, leaving low-confidence results blank.

        Quota other/selfieaccbalancedselfiemacroMean conf of error imagesCoverage acc@10% / 15%
        400/40095.3794.3493.1994.220.59098.16 / 98.68
        max_all (2000/624)96.3794.4992.3794.300.63199.01 / 99.27
        max_1to1 (624/624)96.3594.2691.9094.200.60598.91 / 99.18
    4. Fix the training image set.

Training, evaluation, and deployment

Training: embeddings are read from the pre-encoding cache, then training starts (StandardScaler data standardization + LogisticRegression logistic regression + Cs hyperparameters).

Evaluation: evaluate on the fixed test image set. Multi-dimensional analysis is possible: error rate by shooting style / bucket / image source / confidence interval.

Deployment: deploy the .npz and .json (recording training config and base parameters, etc.) files to the application side; the application-side classification pipeline filters out low-confidence results.

记录
  "head": {
    "type": "logistic_regression",
    "C": 0.001,
    "class_weight": "balanced",
    "penalty": "l2",
    "solver": "lbfgs",
    "max_iter": 2000,
    "l1_ratio": null,
    "scaler": "standard",
    "select_by": "val",
    "select_scores": {
      "0.001": 0.9166
    },

Extended usage

  • Similar image identification. In practice, all images are encoded first and cached, then merged for global retrieval on the frontend.
clip_photo_viewer_02.jpg
Similar image identification
  • Label video files using (burst) screenshots.
clip_photo_viewer_03.jpg
Video labels
0 characters
Sort:
0 comments
No comments yet. Be the first!