Skip to content

Train ReID

Use train-reid to fit a ReID backbone on a supported person or vehicle re-identification dataset.

Examples

Example

Train on Market1501:

boxmot train-reid \
  --model osnet_x0_25 \
  --dataset market1501 \
  --data-dir /data/reid \
  --device 0

Joint training on multiple datasets:

boxmot train-reid \
  --model lmbn_n \
  --dataset market1501,duke,cuhk03 \
  --data-dir /data/reid \
  --loss triplet \
  --preprocess resize_pad \
  --epochs 120 \
  --project runs/reid_train \
  --name lmbn_joint

Joint training from ReID data YAMLs:

boxmot train-reid \
  --model csl_tinyvit_23m \
  --data market1501.yaml \
  --data duke.yaml \
  --epochs 120 \
  --device 0

Train from a BoxMOT ReID config:

boxmot train-reid --cfg custom_config.yaml

The training-only GlobalAP, human-pretraining, and privileged-teacher pipeline for the 7M V20 model is documented in CSL-TinyViT-7M HP-GRD.

Train the promoted CSL-TinyViT-11M V20 preset on Market1501:

MARKET1501_DIR=/data/Market-1501-v15.09.15 \
  ./train_csl_tinyvit_11m_v20.sh

The equivalent direct command is:

uv run --no-sync python -m boxmot.engine.cli train-reid \
  --recipe csl_tinyvit_11m \
  --model csl_tinyvit_11m_v20 \
  --data-dir /data/Market-1501-v15.09.15 \
  --device mps \
  --num-workers 4 \
  --project runs/csl_tinyvit_11m_v20 \
  --name market1501_seed0

This is the validated RGB-only semantic-fine recipe, without Hi-AFA or multilevel-suppression experiments. It starts a fresh run from the checksum-verified official TinyViT-11M weights; use --resume only for an existing compatible checkpoint. The canonical recipe uses four data workers on MPS. The launcher validates all three dataset splits and lets you override that default with CSL_TINYVIT_11M_NUM_WORKERS.

The best recorded 11M run is not that RGB-only training policy. It is the A11v8 multiscale EMA pose-teacher treatment (91.02% mAP and 95.90% rank-1 at epoch 190). Train its current-code, checkpoint-safe equivalent with:

MARKET1501_DIR=/data/Market-1501-v15.09.15 \
PAV_METADATA_DIR=/data/Market-1501-pav-metadata-clean \
  ./train_csl_tinyvit_11m_v20_pose_teacher.sh

The equivalent direct command is:

uv run --no-sync python -m boxmot.engine.cli train-reid \
  --recipe csl_tinyvit_11m_v20_pose_teacher \
  --model csl_tinyvit_11m_v20 \
  --data-dir /data/Market-1501-v15.09.15 \
  --anatomical-metadata-dir /data/Market-1501-pav-metadata-clean \
  --device mps \
  --num-workers 4 \
  --project runs/csl_tinyvit_11m_v20_pose_teacher \
  --name market1501_seed0

Pose metadata is privileged training supervision only. Deployment prunes the teacher and retains the same 1536-D RGB descriptor. Start a fresh run from the checksum-verified official weights; the historical A11v8 best.pt is an inference checkpoint and cannot be resumed.

Train the stabilized Hi-AFA reproduction profile on Market1501:

MARKET1501_DIR=/data/Market-1501-v15.09.15 \
  ./train_hi_afa_market1501.sh

This uses the registered hi_afa backbone at 384x128, PK sampling with 8 identities x 8 instances, and the paper's summed 17-head CE and 5-stream multi-similarity objectives. The paper's 22-stream center term does not specify shared versus branch-specific centers; the stabilized profile disables BoxMOT's ambiguous shared-center interpretation.

LDAM's trainable spatial and channel residual gates are initialized at zero, keeping the pretrained OSNet path identity-safe at startup. Evaluation excludes the DropBlock copy of g4 and emits an 8192-D descriptor from 16 unique 512-D raw pooled streams. Each stream is L2 normalized before concatenation and the concatenated descriptor is normalized once more. The config documents the remaining explicit defaults for details that the paper does not report. Its default run name is stable_seed0, separate from literal-paper experiments.

Transfer the promoted 7M V20 hierarchy and training-only pose teacher to the MobileNetV4 Medium backbones:

boxmot train-reid \
  --recipe mobilenetv4_conv_medium_v20 \
  --data-dir /data/Market-1501-v15.09.15 \
  --anatomical-metadata-dir /data/Market-1501-pav-metadata-clean

boxmot train-reid \
  --recipe mobilenetv4_hybrid_medium_v20 \
  --data-dir /data/Market-1501-v15.09.15 \
  --anatomical-metadata-dir /data/Market-1501-pav-metadata-clean

Both recipes use the standard 1/2/4 scale-balanced head, shared multiscale MCPT, and a training-only EMA anatomical teacher, while deploying a 1,152-D RGB-only descriptor. Their 100-epoch horizon adopts the matched Conv-M evidence that an 80-epoch cosine LR collapses before the observed epoch-70 optimum; Hybrid-M still requires its own sweep. The 200-epoch TinyViT phases are scaled to MCPT 10→25 with its identity prior removed at 35, and anatomy ramp 0→25, hold to 60, decay to 85, followed by 15 RGB-only consolidation epochs. Conv-M promotes the resolution-matched mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k checkpoint, spatial_linear C5 projection, stride-16 final map, normal MobileNet augmentation, backbone LR multiplier 1.0, weight decay 1e-4, and the CNN ReID neck. Hybrid-M retains the stable ix/e550/r256 MQA pretrained family and its lower fine-tuning LR.

The generic MobileNetV4 default is --timm-head-mode pooled, matching timm's classification path by globally pooling C5 before its pretrained head. The promoted Conv-M V20 recipe overrides it with spatial_linear. The available modes are:

  • spatial retains the C5 map through the complete pretrained head.
  • spatial_adapt_norm also updates the head normalization during the frozen-backbone warm-start.
  • spatial_linear retains the pretrained 1x1 projection but bypasses its pooled-domain normalization and activation.
  • off bypasses the classification projection and uses raw C5.

The completed ablation_mobilenetv4_medium_v20_timm_head.sh and ablation_mobilenetv4_medium_v20_next.sh scripts preserve the original pooled/spatial and optimization studies. Their results rejected strong augmentation and a 0.25 backbone LR multiplier, found 5e-4 weight decay neutral, and promoted the r384 checkpoint. The matched 100-epoch stride-16-map run reached 86.71% mAP versus 86.18% for its 80-epoch counterpart; the shorter cosine horizon was already over-decayed at epoch 70. The spatial LayerNorm neck remains an opt-in experiment. --mobilenetv4-last-stride 1 changes the final map from 12x4 to 24x8 at 384x128.

A saved run can be reproduced with the same path:

boxmot train-reid --cfg runs/my_experiment/hparams.json --name reproduced

Saved hparams.json files use resume-compatible legacy normalization, so fields introduced after an older run retain their historical disabled behavior.

Explicit CLI flags override the config:

boxmot train-reid --cfg custom_config.yaml --epochs 3

Example market1501.yaml:

dataset: market1501
path: ../datasets/Market-1501-v15.09.15
train: bounding_box_train
query: query
gallery: bounding_box_test
download: |
  from pathlib import Path
  Path(yaml["path"]).mkdir(parents=True, exist_ok=True)

Core idea

train-reid builds a ReID backbone, loads one or more registered ReID datasets, and optimizes the model with either softmax or triplet-style training.

The crop preprocessing you choose here should match the preprocessing used later at inference time.

Identity-preserving background mosaic

Background mosaic keeps the complete anchor person and their detected backpack, handbag, or suitcase while replacing only the surrounding background with four donor-background tiles. The anchor PID remains the sole training label, and the augmentation is never applied to query or gallery evaluation images.

Generate dedicated high-confidence masks for the training split first:

uv run --no-sync python -m tools.create_market1501_person_masks \
  --source Market-1501-v15.09.15 \
  --output Market-1501-mosaic-highconf \
  --model weights/yolo26x-seg.pt \
  --device mps \
  --batch-size 16 \
  --conf 0.50 \
  --masks-only

Train on the original images while pointing the augmentation at the generated masks:

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --background-mosaic \
  --background-mosaic-mask-dir Market-1501-mosaic-highconf-masks \
  --background-mosaic-probability 0.30 \
  --device mps \
  --project runs/csl_tinyvit_11m_market1501_mosaic \
  --name a11s2_background_mosaic

The default schedule leaves mosaic disabled through epoch 10 and linearly ramps its probability to 0.30 at epoch 30. Masks retaining less than 20% or more than 90% of an image, masks missing the central crop region, and missing masks all fall back to the unmodified anchor image. The generated mask root contains primary/ masks for preserving only the labeled person and their nearby bags, plus all_people/ masks that remove every high-confidence person and nearby bag from donor tiles.

Cross-camera same-ID part mosaic

Use --same-id-part-mosaic to replace one or two body-aligned regions with corresponding regions from independently augmented images of the same identity in the current P×K batch. Different-camera donors are preferred when available, the hard identity label is unchanged, and evaluation images are never modified.

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --same-id-part-mosaic \
  --same-id-part-mosaic-probability 0.35 \
  --same-id-part-mosaic-max-regions 2 \
  --same-id-part-mosaic-min-area 0.15 \
  --same-id-part-mosaic-max-area 0.40 \
  --same-id-part-mosaic-boundary-jitter 0.05 \
  --same-id-part-mosaic-cross-camera-rate 1.0 \
  --same-id-part-mosaic-min-unaltered 0.5 \
  --device mps \
  --project runs/csl_tinyvit_11m_market1501_sameid_mosaic \
  --name a11s2_sameid_partmosaic_p035

The default policy replaces 15–40% of selected images, jitters anatomical boundaries by up to 5% of image height, and leaves at least half of each batch unaltered. It needs no segmentation masks or mixed labels. The camera-aware sampler is complementary because it makes cross-camera same-ID donors available more consistently. When enabled, the existing Random Erasing policy is applied independently after the part composite.

Pose-aligned view mosaic

PAV-Mosaic uses YOLO pose keypoints to replace semantic body parts instead of horizontal rectangles. Head, torso, left/right arms, upper/lower legs, and nearby bags are selected from high-confidence same-ID observations, preferably from other cameras and poses, then warped into the anchor geometry. The anchor background is unchanged unless context mosaic is also enabled.

Generate the training-only metadata first. YOLO26x-seg supplies the person foreground and separate bag masks used to constrain the pose-derived regions:

uv run --no-sync python -m tools.create_market1501_pav_metadata \
  --source Market-1501-v15.09.15 \
  --output Market-1501-pav-metadata \
  --pose-model https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26x-pose.pt \
  --seg-model https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26x-seg.pt \
  --device mps \
  --batch-size 16 \
  --pose-conf 0.25 \
  --seg-conf 0.50

Then train the PAV-only arm:

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --pav-mosaic \
  --pav-metadata-dir Market-1501-pav-metadata \
  --pav-mosaic-probability 0.25 \
  --pav-mosaic-max-parts 3 \
  --pav-mosaic-max-foreground-replacement 0.45 \
  --pav-mosaic-cross-camera-rate 0.8 \
  --pav-mosaic-different-pose-rate 0.5 \
  --pav-mosaic-min-keypoint-confidence 0.5 \
  --pav-mosaic-min-unaltered 0.5 \
  --pav-mosaic-warmup-epochs 40 \
  --pav-mosaic-decay-start-epoch 170 \
  --pav-mosaic-final-probability-scale 0.5 \
  --device mps \
  --name a11u6_pavmosaic

The context arms additionally enable the existing foreground-preserving background mosaic at probability 0.20. A real, high-confidence donor person can enter from the left, right, or bottom boundary at probability 0.15 and cover 5–20% of the image without contributing its identity to the label. The final arm sets --pav-consistency-weight 0.2; it applies ID loss to both the clean and mosaic observations and cosine consistency to their retrieval descriptors. Only successfully augmented pairs incur the extra clean forward pass.

The complete controlled comparison is in ablation_csl_tinyvit_11m_a11u_sampler_mosaic.sh:

  • a11u4: same-ID rectangular part mosaic.
  • a11u6: PAV-Mosaic.
  • a11u7: PAV-Mosaic plus context mosaic and realistic occluders.
  • a11u8: PAV/context plus clean-view consistency.

Privileged anatomical supervision

--anatomical-auxiliary uses the same pose/person-mask metadata to supervise six ordered RGB tokens: head, torso, left/right arms, and left/right legs. A deterministic pose-mask router defines the spatial target for every cell, while learned RGB queries receive same-scale token consistency, attention KL, visibility, dense geometry, and optional same-part cross-camera contrastive losses. There is no learned pose encoder or second backbone forward, and the normal global/stripe descriptor is unchanged at evaluation and export.

The default --anatomical-target-type deterministic_scale_aware_geometry selects this deterministic router. To reproduce the A11v8 teacher, use --anatomical-target-type learned_pose_concat_ema together with --anatomical-teacher-momentum 0.999. That path restores the learned pose-heatmap encoder, the fine-map online teacher, and its stop-gradient EMA copy. It supervises both the local and fine anatomical students during training, but is still omitted from evaluation and export. Legacy A11v8 hyperparameters that contain a teacher momentum but no target type are mapped to this path automatically.

Target routing uses an actual pose-aligned 4x2 grid for every part. The torso grid is mapped through the shoulder/hip quadrilateral, limb rows follow the shoulder-elbow-wrist or hip-knee-ankle chain from proximal to distal, and the head grid is oriented by bilateral eye/ear landmarks. Each valid cell creates a normalized spatial routing distribution, clipped by its cleaned person-part mask when one is available. Its stop-gradient, same-scale RGB feature average is the token target. Every grid cell owns a slice of the token channels and a separately supervised RGB-student attention map, preserving anatomical layout instead of reducing it to an unordered image-space average.

Set --anatomical-descriptor-distill-weight above zero to enable the stronger descriptor path. The six visibility-weighted local semantic tokens form a geometry-routed descriptor that supervises the deployed global/stripe descriptor with both cosine alignment and pairwise-similarity distillation. The comparison projection is training-only; inference input, descriptor shape, and compute remain unchanged.

Set --anatomical-pose-teacher-weight above zero for dense geometric coverage. Transformed COCO-17 grids and cleaned person-part masks deterministically define where each anatomical cell must attend. Local targets cover a broader fraction of the person to match the semantic map's receptive field; fine targets are sharper and retain limb and boundary detail. RGB is never concatenated with pose, so the model cannot bypass the privileged signal through an RGB-only teacher projection. Pose is not passed through the model and is never required by evaluation or export.

Person-mask-validated grid cells take priority whenever a mask exists. Pose-only records can remain usable at reduced reliability, though cleaned metadata can set this reliability to zero. Geometry-routed feature averages provide same-scale token-consistency targets, and all anatomical losses can still be ramped and removed before the final retrieval-only epochs. At startup, the trainer verifies that metadata records match the selected training images and that declared person-mask files exist. Usable coverage counts only confidence-qualified poses and, when pose-only reliability is zero, readable nonempty masks; it must meet --anatomical-min-effective-coverage. The resume contract fingerprints the metadata manifest and referenced mask bytes, so annotation drift cannot silently enter an exact continuation. Routing, normalization, and anatomical KL/contrastive calculations run in FP32 even when the RGB model uses CUDA mixed precision, preventing empty-cell underflow from contaminating a batch.

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --anatomical-auxiliary \
  --anatomical-target-type deterministic_scale_aware_geometry \
  --anatomical-metadata-dir Market-1501-pav-metadata \
  --anatomical-token-dim 128 \
  --anatomical-distill-weight 0.10 \
  --anatomical-attention-weight 0.10 \
  --anatomical-visibility-weight 0.05 \
  --anatomical-contrastive-weight 0.10 \
  --anatomical-descriptor-distill-weight 0 \
  --anatomical-pose-teacher-weight 0.03 \
  --anatomical-pose-only-reliability 0.35 \
  --anatomical-min-effective-coverage 0.8 \
  --anatomical-student-start-epoch 20 \
  --anatomical-student-ramp-end-epoch 50 \
  --anatomical-decay-start-epoch 120 \
  --anatomical-decay-end-epoch 170 \
  --anatomical-temperature 0.07

Masks, pose grids, and keypoints follow resizing, random translation, horizontal flips, RandomPatch, and Random Erasing. Horizontal flips also exchange left/right token labels. A sample with valid cached pose but no person mask can still train the RGB student at the configured pose-only reliability; mask-dependent visibility supervision is skipped. A sample without valid geometry remains ordinary RGB-only ReID training. When both estimates exist, mask-validated cells define the target and low pose/person-mask agreement reduces its anatomical weight. Sparse targets are compressed in memory after their first construction, and metrics report each anatomical loss component, usable part coverage, and cross-camera-positive coverage separately.

Enable --anatomical-multiscale to mirror the hierarchical stripe routing. The existing Stage-2/local anatomical student and a new Stage-0/fine student share a role basis, while explicit cell embeddings, scale-specific query offsets, projections, and normalization let each resolution specialize. Each student learns from geometry and RGB targets constructed at its own resolution. Their complete token-consistency, attention, visibility, geometry, and cross-camera contrastive losses are balanced with --anatomical-local-scale-weight and --anatomical-fine-scale-weight, which must sum to one. Corresponding fine/local tokens align only their within-image role-similarity structure using --anatomical-cross-scale-weight; raw tokens remain free to encode scale-specific information. These branches remain training-only. By default the fine-map and cross-scale terms follow the shared anatomical student schedule. Set --anatomical-fine-start-epoch and --anatomical-fine-ramp-end-epoch to introduce those terms later while the Stage-2/local student retains the shared schedule. The cross-scale term follows the fine-map ramp.

Select --anatomical-target-type privileged_mask_pose_attention to use pose and masks strictly as targets for an RGB attention adapter. The adapter predicts person foreground and six soft anatomical maps at the Stage-2 and Stage-0 resolutions. A bounded residual gate modifies the local and fine RGB maps before the existing fixed-stripe pooling. Mask foreground and pose-part evidence have independent learned strengths, so retrieval can retain either cue if the other is noisy. Both strengths are initialized to zero, share a bounded residual budget, and remain disabled during the configured backbone-freeze epochs. The global branch and the 1536-D retrieval contract are unchanged.

Use --anatomical-person-mask-dir to supply the external high-confidence masks. They take priority over masks referenced by the pose metadata. Pose-only images train the six part maps at reduced reliability, mask-only images train the foreground map, and images with neither annotation retain the ordinary ReID loss. --anatomical-foreground-weight controls the BCE/Dice foreground objective. A11v8's same-scale token consistency remains enabled, now using stop-gradient RGB averages routed by the pose/mask regions. Descriptor and stripe-branch distillation should remain disabled for this target type.

The supplied training script inherits the complete A11v8 control configuration, uses cleaned pose metadata with pose-only reliability set to zero, and preserves the successful multi-scale supervision schedule: ramp to full strength by epoch 50, decay from epochs 120 through 170, then finish with 30 retrieval-only epochs. Its startup preflight rejects a control run whose architecture, sampler, optimizer, schedule, or recorded best result no longer matches A11v8.

At evaluation and export, the adapter predicts its gate from RGB features. No metadata, mask, pose tensor, pose estimator, or segmentation estimator is loaded. The complete Market-1501 command is provided by train_csl_tinyvit_11m_privileged_mask_pose_attention.sh.

Use learned_pose_semantic_ema to keep the complete A11v8 retrieval path and add local/fine foreground and six-part prediction heads strictly during training. learned_pose_semantic_fused_ema additionally blends each pose-cell attention target with its person-mask-clipped part mask. The blend is computed per image and part: weak pose confidence shifts weight toward the semantic mask, while low pose-mask agreement shifts it back toward pose geometry. Neither mode instantiates the privileged residual gate or changes the 1536-D inference descriptor.

--anatomical-foreground-weight and --anatomical-semantic-part-weight control the training-only foreground and six-part BCE/Dice objectives. Current Market-1501 PAV metadata provides pose-routed part masks clipped by a high-confidence person silhouette; it is not independent human parsing for garment or shoe classes. The prediction-head interface can consume richer six-role parsing masks when such annotations are available.

The controlled A11v18 sequence is in ablation_csl_tinyvit_11m_pose_semantic_teacher.sh: a current-code A11v8 replication, two channel-representation controls, semantic losses without target fusion, confidence-fused targets, then coarse/fine-only branch distillation at weight 0.025. All arms preserve A11v8's multi-scale weights and supervision schedule. stage2_channel2 appends two shared 128-D Stage-2 channel specialists and evaluates a 1792-D descriptor. multiscale_channel2 instead adds two 128-D channel summaries to each of the global, coarse, and fine source maps. With --multiscale-channel-alpha 0.5, every scale assigns 75% of its descriptor power to spatial branches and 25% to its channel pair; final normalization still assigns one-third total power to each scale. Its raw metric and deployed BN descriptors both include all six summaries and have 2304 dimensions. The three scale-specific projections and shared-within-scale BNNecks add 388,224 parameters for Market-1501. The pose/semantic-only arms retain the 1536-D descriptor.

For a fully decoupled parsing treatment, select decoupled_pose_parsing_teacher. Private local/fine parsing adapters receive foreground and dense part supervision, and parsing masks restrict a shared set of teacher queries. Corresponding RGB queries attend without masks and learn from stop-gradient teacher tokens. Query diversity and visible-part hard triplet losses are controlled by --anatomical-query-diversity-weight and --anatomical-part-triplet-weight; their ramp has separate query start/end options. --anatomical-accessory-query adds an optional seventh bag query whose reliability is zero when no bag mask exists.

--anatomical-query-relational-distill-weight additionally matches the student and masked teacher cosine-similarity matrices separately for each semantic query. Only reliable cross-camera pairs contribute, and same-ID and different-ID pair groups are balanced before averaging. This transfers identity geometry without adding a deployed branch.

--clean-student-consistency-weight creates a deterministic resized clean teacher view alongside the normal augmented RGB student. Clean masked teacher queries supervise the augmented unrestricted queries, while the detached clean retrieval descriptor provides view consistency. This treatment is mutually exclusive with PAV mosaic consistency and does not add clean-view ID loss.

Both query paths are training-only. The local/fine retrieval maps are never gated or replaced, and evaluation keeps A11v8's 1536-D RGB descriptor. Run the four controlled arms with ablation_csl_tinyvit_11m_decoupled_pose_parsing_teacher.sh. The gated V20 control, relational-query, clean-student, and branch-only suite is in ablation_csl_tinyvit_11m_pose_distillation_v20.sh.

The promoted V8 pose-teacher policy has both an explicit RGB architecture preset and a width-adapted training recipe named csl_tinyvit_7m_v20. Direct preset construction does not require pose or mask metadata and has 6,937,893 parameters for 751 training identities. The recipe opts into a 227,118-parameter privileged anatomy teacher, bringing its training model to 7,165,011 parameters; that branch is absent from the deployed RGB model. Both retain the 384×128 global/two-stripe/four-stripe hierarchy, rectangular attention, scale-balanced descriptor, PK sampling, and pose-loss schedule. The fusion/retrieval width is reduced from 512 to 384 and the anatomical bottleneck from 128 to 96 to match the 7M backbone's 64/128/160/320 stage widths. Consequently, global, coarse, and fine scales contribute 384 dimensions each to a 1152-D deployed RGB descriptor. Run the recommended model with ablation_csl_tinyvit_7m_v20_transfer.sh; optional rgb and unscaled arms provide matched controls.

The controlled Hi-AFA-lite treatment is the csl_tinyvit_7m_hi_afa_lite recipe. It is identical to csl_tinyvit_7m_v20 except that a reduction-4 ReID adapter is enabled at Stage 3 and its lateral input uses feature-selective suppression with tau=0.7. The main TinyViT stream remains dense, the adapter gate remains zero-initialized, and evaluation still emits the standard 1152-D RGB descriptor. Because the V20 pose teacher is preserved, training also requires the generated PAV metadata:

MARKET1501_DIR=/data/Market-1501-v15.09.15 \
PAV_METADATA_DIR=/data/Market-1501-pav-metadata-clean \
  ./train_csl_tinyvit_7m_hi_afa_lite.sh

The equivalent direct command is:

uv run --no-sync python -m boxmot.engine.cli train-reid \
  --recipe csl_tinyvit_7m_hi_afa_lite \
  --data-dir /data/Market-1501-v15.09.15 \
  --anatomical-metadata-dir /data/Market-1501-pav-metadata-clean

The training-only multilevel classifier-guided suppression treatment is available as csl_tinyvit_7m_multilevel_suppression. It is an exact V20 feature-evidence ablation inspired by Hi-AFA, not a paper-faithful Hi-AFA implementation. Stage-3 ReID adapters remain disabled and the deployed model uses a 7,165,011-parameter training graph and the same pruned 1152-D RGB descriptor at deployment. During training, a detached target-class Grad-CAM from a frozen copy of the global classifier masks the strongest locations independently in each stripe of a private coarse-map copy. The frozen scorer uses accumulated BN running statistics, so each image's CAM is independent of the other identities in its batch. The two coarse classifiers then produce separate CAMs for their own halves; those CAMs are stitched and resized to guide a private four-stripe fine-map copy. Stripes with a constant or invalid CAM are left intact and are excluded from the auxiliary CE loss. The clean global, coarse, and fine maps, logits, descriptor, and BN statistics are never modified.

This corrected activity-masked objective is implementation version 2. Its version is stored in hparams and resumable checkpoints, so an older multilevel-suppression run cannot be resumed under different loss semantics. The launcher therefore defaults to the distinct run name class_cam_q15_v2_seed0.

Suppression starts at epoch 20, ramps to a loss weight of 0.2 and a ratio of 0.15 by epoch 50, begins decaying at epoch 140, and is disabled after epoch 170. The ratio is rounded up to a whole spatial location within each stripe, so the recorded erase fraction can be slightly above the requested value. Because the underlying V20 pose-teacher recipe is unchanged, the launcher requires the same PAV metadata:

MARKET1501_DIR=/data/Market-1501-v15.09.15 \
PAV_METADATA_DIR=/data/Market-1501-pav-metadata-clean \
  ./train_csl_tinyvit_7m_multilevel_suppression.sh

To customize the output without editing the recipe, set MULTILEVEL_SUPPRESSION_PROJECT, MULTILEVEL_SUPPRESSION_NAME, MULTILEVEL_SUPPRESSION_DEVICE, or MULTILEVEL_SUPPRESSION_NUM_WORKERS. Set VALIDATE_ONLY=1 to check the two input roots and print the resolved command without starting training. Epoch metrics record the scheduled ratio, actual coarse/fine erase fractions, and both CAM-active fractions so degenerate or ineffective masks are visible during the run.

The focused ablation_csl_tinyvit_7m_mcpt_pose.sh study combines this training-only V8 teacher with shared-multiscale MCPT in a same-source 2×2 factorial: RGB, MCPT, pose, and MCPT plus pose. The combination is intentionally limited to the 7M standard scale-balanced stripe head and the multiscale learned_pose_concat_ema teacher. Evaluation still requires RGB only and emits the same 1152-D descriptor; MCPT remains active while the pose branch is discarded. Optional foreground and foreground_combo arms compare the foreground-aware MCPT alternative.

The corresponding larger-backbone recipe is csl_tinyvit_23m_v8. It keeps the same V8 policy while scaling the retrieval width to 640 and the anatomical bottleneck to 160 for the 23M backbone's 96/192/384/576 stage widths. Global, two-stripe, and four-stripe scales therefore contribute 640 dimensions each to the 1920-D deployed RGB descriptor. The 23M backbone retains its native 0.20 DropPath rate. Run the matched RGB and pose-teacher treatments with ablation_csl_tinyvit_23m_v8_transfer.sh.

For a deployed slot representation, select --head-type body_slot --anatomical-target-type body_slot_privileged_ema. This replaces the fixed global/two-stripe/four-stripe head with a 512-D global descriptor and eight persistent 128-D RGB slots. The same slots read Stage 0, Stage 2, and Stage 3, so the final normalized descriptor remains 1536-D. Visibility controls descriptor power within the slot stream, while --body-slot-alpha controls the global-versus-slot split.

The recommended --body-slot-mode recurrent_read never changes backbone features. recurrent_read_write adds slot-to-spatial attention at all three stages, with every residual gate initialized to exactly zero. With 751 Market-1501 classes, the read-only replacement has 13,522,022 parameters versus 13,514,597 for the stripe model; read/write has 13,853,289.

Pose-derived parts, the person mask, and the accessory mask form weak teacher roles only during training. Masked EMA projections supervise slot embeddings, attention, visibility, diversity, foreground coverage, and visible cross-camera part triplets. Evaluation, export, and tracking receive RGB images only. The controlled Tier B command and opt-in Tier C arm are in ablation_csl_tinyvit_11m_body_slots.sh.

Enable --anatomical-deployment to make the six pose-supervised RGB students part of the retrieval descriptor. Local and fine tokens for head, torso, left/right arms, and left/right legs are fused and reduced to --anatomical-deployment-dim channels each. Their RGB visibility predictions weight the normalized part descriptor, which is appended to the unchanged base descriptor with relative energy --anatomical-deployment-alpha.

Only the training teacher consumes pose. Evaluation, export, and tracking run the RGB student path without keypoints. With the 1536-D hierarchical base, six 64-D parts produce a 1920-D descriptor. Visibility-weighted part-ID and cross-camera metric losses remain active after scheduled teacher losses decay; their weights are controlled by --anatomical-deployment-id-weight and --anatomical-deployment-metric-weight.

This treatment requires the learned EMA pose teacher, multi-scale anatomy, and norm_concat_bn. It is intentionally incompatible with descriptor distillation, stripe branch distillation, and the compact deployment head so each experiment has one deployed representation treatment.

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --anatomical-auxiliary \
  --anatomical-target-type learned_pose_concat_ema \
  --anatomical-metadata-dir Market-1501-pav-metadata-clean \
  --anatomical-multiscale \
  --anatomical-deployment \
  --anatomical-deployment-dim 64 \
  --anatomical-deployment-alpha 0.25 \
  --anatomical-deployment-id-weight 0.25 \
  --anatomical-deployment-metric-weight 0.10 \
  --anatomical-descriptor-distill-weight 0 \
  --anatomical-branch-distill-weight 0

For A11v13-style branch-aligned EMA distillation, set --anatomical-branch-distill-weight above zero with --anatomical-target-type learned_pose_concat_ema. The stop-gradient EMA teacher softly assigns reliable canonical cells to the deployed global, two-stripe, and four-stripe descriptors, then matches same-ID and different-ID cross-camera relations at each level. The global, coarse, and fine coefficients must sum to one. This path requires the standard scale-balanced hierarchical stripe head and norm_concat_bn, and adds no inference output, parameters, or latency.

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --anatomical-auxiliary \
  --anatomical-target-type learned_pose_concat_ema \
  --anatomical-metadata-dir Market-1501-pav-metadata-clean \
  --anatomical-pose-teacher-weight 0.03 \
  --anatomical-multiscale \
  --anatomical-local-scale-weight 0.60 \
  --anatomical-fine-scale-weight 0.40 \
  --anatomical-cross-scale-weight 0.05 \
  --anatomical-branch-distill-weight 0.05 \
  --anatomical-branch-global-coefficient 0.20 \
  --anatomical-branch-coarse-coefficient 0.30 \
  --anatomical-branch-fine-coefficient 0.50 \
  --anatomical-fine-start-epoch 40 \
  --anatomical-fine-ramp-end-epoch 80

Width-first hierarchy and identity registers

--width-first-hierarchy changes CSL-TinyViT's early spatial allocation from the usual joint height/width reduction to 48x16 -> 48x8 -> 24x8. Stage 1 therefore models the full pedestrian height with alternating 12x4 and 16x4 windows before a height-only merge. The intended compute-balanced setting moves one block from Stage 2 to Stage 3 with --stage2-depth 5 --stage3-depth 3.

--identity-registers adds four recurrent global tokens after Stage 2 and Stage 3. Each register reads window summaries, and the resulting context is broadcast back to the spatial map through a scalar zero-initialized gate. Window summaries are projected from 448 dimensions into the --identity-register-dim 128 communication bottleneck, then projected back to the 448-D spatial map. The two communication modules therefore add about 0.63M parameters rather than the roughly 5.24M required by full-width registers. --identity-register-dropout drops whole registers during training, while --identity-register-diversity-weight 0.01 weakly discourages duplicated registers. The registers require the unchanged standard global/2-stripe/ 4-stripe head. They are treated as ReID adaptation parameters, so their randomly initialized communication modules train at head LR during backbone warm-start; the learned register seed is not weight-decayed. They are internal backbone state: evaluation still emits the same RGB-only 1536-D norm_concat_bn descriptor.

The controlled A11v8-based register treatment is:

./ablation_csl_tinyvit_11m_reid_x.sh

The default a11x2r_v8_four_identity_registers_d128 arm changes only the register path and retains A11v8's Stage-2/3 depths 6/2 and normal hierarchy. The earlier compound x2 arm used the unvalidated width-first 5/3 backbone and collapsed to 15.88% mAP while its register gates remained near zero; it was not a valid register ablation. Use INCLUDE_WIDTH_FIRST=1 only to retain that known-negative x1 diagnostic. Use INCLUDE_CONTROL=1 to add a current-source A11v8 replication or DRY_RUN=1 to print and preflight commands without training.

Fixed camera-aware PK sampling

Use --camera-aware-sampler to draw one image from each available camera before adding same-camera instances for an identity. --pk-steps-per-epoch fixes the number of training batches so changing K does not silently shorten an epoch.

The batch-96 P16K6 procedure matching the promoted P12K8 training budget is:

boxmot train-reid \
  --cfg boxmot/reid/training/configs/recipes/csl_tinyvit_11m.yaml \
  --data-dir Market-1501-v15.09.15 \
  --p-ids 16 \
  --k-instances 6 \
  --pk-steps-per-epoch 62 \
  --camera-aware-sampler \
  --project runs/csl_tinyvit_11m_market1501_sampler \
  --name a11s2_p16k6_camera_aware_s62

This produces exactly 62 batches and 5,952 image draws per epoch, matching the current P12K8 procedure while increasing the identity count per batch.

Modular CSL-TinyViT ablations

CSL-TinyViT training resolves the flat CLI/config values into a canonical ablation plan before model construction. The plan separates five independent axes:

  • architecture
  • retrieval head
  • augmentation
  • privileged supervision
  • auxiliary objective

The selected head and every enabled treatment are written to model.ablation in hparams.json and checkpoint metadata. This makes reports show the actual treatment set instead of requiring experiment names to encode it. Existing commands remain unchanged; for example, --head-type multiscale_channel2 --pav-mosaic --csmm-loss-weight 0.2 resolves to one head, one augmentation, and one objective.

Implementation registries are intentionally separated by responsibility:

  • boxmot.reid.backbones.head_registry defines supported heads and their capabilities once for the CLI, trainer, and models.
  • boxmot.reid.backbones.option_registry defines categorical mode choices such as feature fusion, pooling, and descriptor selection.
  • boxmot.reid.training.ablation defines named optional treatments, dependencies, and mutually exclusive groups.
  • boxmot.reid.training.model_options groups trainer-to-model arguments by component.
  • boxmot.reid.training.augmentations validates and assembles the image, sample-level, clean-view, and privileged-target pipeline.

When adding an ablation, add one named treatment to the registry, put its model arguments in the corresponding option group, and add a focused component test. Avoid creating a second boolean for a mode that is already represented by head_type, feature_fusion, or another exclusive selector.

Supported datasets

The built-in dataset registry currently includes common ReID benchmarks such as:

  • market1501
  • duke / dukemtmcreid
  • cuhk03
  • msmt17
  • msmt17_merged

You pass the dataset root through --data-dir, and BoxMOT resolves the expected subdirectory layout for the selected dataset.

Alternatively, pass one or more --data YAML configs. YAML path values are resolved relative to the YAML file, and download is a local Python block executed only when that root is missing or empty. Built-in ReID datasets still use their registered parsers; train, query, and gallery are saved in hparams as dataset metadata.

Main outputs

Training writes an experiment directory under --project/--name, typically containing:

  • best and last checkpoints
  • training logs and metrics
  • periodic validation results

When training finishes, BoxMOT reports the best checkpoint path along with the best validation mAP and rank-1 score.

Resuming and evaluation during training

  • Use --resume with a checkpoint directory or last.pt file to continue an interrupted run.
  • Use --eval-interval to control how often validation runs during training.
  • Use --eval-datasets for extra cross-domain checks during training.

Scope

The CLI command is train-reid; the same workflow is available through the high-level BoxMOT.train(...) Python facade.

from boxmot import BoxMOT

model = BoxMOT("mobilenetv4")
model.train(cfg="mobilenetv4_custom.yaml")

When the first positional argument matches a registered ReID training recipe or backbone, it is used as the training profile; detector names still configure tracking detectors. A ReID weight filename can also seed the training profile while binding the object to that weight for later export or embedding:

reid = BoxMOT(reid="mobilenetv4.pt")
reid.train(cfg="custom_config.yaml")

CLI Arguments

boxmot train-reid

Train a ReID model

Usage:

boxmot train-reid [OPTIONS]

Options:

Name Type Description Default
--cfg file BoxMOT ReID YAML/JSON config or saved hparams.json. Explicit CLI flags override config values. None
--recipe choice (csl_tinyvit_11m | csl_tinyvit_11m_v20_pose_teacher | csl_tinyvit_23m | csl_tinyvit_23m_v8 | csl_tinyvit_7m | csl_tinyvit_7m_hi_afa_lite | csl_tinyvit_7m_hpgrd | csl_tinyvit_7m_multilevel_suppression | csl_tinyvit_7m_v20 | hi_afa_market1501 | lmbn_n | lmbn_n_market1501 | mobilenetv4 | mobilenetv4_conv_large | mobilenetv4_conv_medium | mobilenetv4_conv_medium_v20 | mobilenetv4_conv_small | mobilenetv4_conv_small_a11k | mobilenetv4_hybrid_medium_v20 | vit) Training recipe preset (overrides defaults; CLI flags still take priority). Available: csl_tinyvit_11m, csl_tinyvit_11m_v20_pose_teacher, csl_tinyvit_23m, csl_tinyvit_23m_v8, csl_tinyvit_7m, csl_tinyvit_7m_hi_afa_lite, csl_tinyvit_7m_hpgrd, csl_tinyvit_7m_multilevel_suppression, csl_tinyvit_7m_v20, hi_afa_market1501, lmbn_n, lmbn_n_market1501, mobilenetv4, mobilenetv4_conv_large, mobilenetv4_conv_medium, mobilenetv4_conv_medium_v20, mobilenetv4_conv_small, mobilenetv4_conv_small_a11k, mobilenetv4_hybrid_medium_v20, vit None
--model choice (csl_tinyvit_11m | csl_tinyvit_11m_lmbn | csl_tinyvit_11m_v20 | csl_tinyvit_23m | csl_tinyvit_23m_lmbn | csl_tinyvit_7m | csl_tinyvit_7m_lmbn | csl_tinyvit_7m_v20 | csl_tinyvit_large | csl_tinyvit_lmbn | csl_tinyvit_normal | csl_tinyvit_small | hacnn | hi_afa | lmbn_ain_n | lmbn_n | mlfn | mobilenetv2_x1_0 | mobilenetv2_x1_4 | mobilenetv4_conv_large | mobilenetv4_conv_medium | mobilenetv4_conv_medium_v20 | mobilenetv4_conv_small | mobilenetv4_hybrid_large | mobilenetv4_hybrid_medium | mobilenetv4_hybrid_medium_v20 | osnet_ain_x0_25 | osnet_ain_x0_5 | osnet_ain_x0_75 | osnet_ain_x1_0 | osnet_ibn_x1_0 | osnet_x0_25 | osnet_x0_5 | osnet_x0_75 | osnet_x1_0 | resnet101 | resnet152 | resnet18 | resnet34 | resnet50 | resnet50_fc512 | resnext101_32x8d | resnext50_32x4d) ReID backbone architecture csl_tinyvit_11m_v20
--data text ReID dataset name or YAML data config. Repeat or comma-separate for multi-dataset training, e.g. --data market1501.yaml --data duke.yaml. YAML supports dataset/name, path, train, val, query, gallery, and download. ()
--dataset text Training dataset (comma-separated for joint training, e.g. market1501,duke,cuhk03,msmt17). Available: cuhk03, duke, market1501, mot171501, msmt17, msmt17_merged, veri market1501
--data-dir path Root directory of the dataset (inferred from hparams.json when --resume is used) None
--loss choice (softmax | triplet | wrt | circle | ms) Metric loss type (triplet=batch-hard triplet, wrt=weighted regularized triplet, circle=Circle loss, ms=multi-similarity, softmax=classifier only) triplet
--classifier-loss choice (ce | arcface | cosface) ID classifier loss: ce, arcface, or cosface ce
--preprocess choice (resize | resize_pad) Crop preprocessing method; must match inference-time preprocessing resize
--imgsz text Image size as H,W (e.g. 256,128) 384,128
--batch-size integer Evaluation batch size; training uses --p-ids × --k-instances 64
--lr float Base learning rate 0.0007
--weight-decay float Weight decay 0.1
--epochs integer Number of training epochs 200
--warmup-epochs integer Linear warmup epochs 20
--vit-lr-profile choice (layer_decay | reid_lrd) Transformer LR grouping profile: geometric layer decay or ReID stage-wise decay layer_decay
--layer-decay float Geometric per-stage LR decay for hierarchical transformer backbones 0.95
--backbone-lr-mult float Persistent pretrained-backbone LR multiplier for MobileNetV4 1.0
--backbone-freeze-epochs integer Freeze pretrained backbone layers for the first N epochs 10
--gradual-unfreeze / --no-gradual-unfreeze boolean Use staged ReID unfreeze: head/neck, last backbone stage, then full model False
--gradual-unfreeze-head-epochs integer Gradual unfreeze head/neck-only epoch boundary 5
--gradual-unfreeze-stage-epochs integer Gradual unfreeze last-stage epoch boundary before full model training 20
--gradual-unfreeze-backbone-lr-mult float Backbone LR multiplier for early full-model gradual-unfreeze epochs 0.1
--gradual-unfreeze-backbone-lr-epochs integer Number of full-model epochs using the gradual-unfreeze backbone LR multiplier 5
--eval-interval integer Validate every N epochs 10
--p-ids integer Number of identities per PK batch 12
--k-instances integer Number of instances per identity 8
--source-balance text Source-balanced PK sampler spec, e.g. 'market1501:8,4;mot17_1501:8,4'. Empty uses the global --p-ids x --k-instances sampler. ``
--pk-steps-per-epoch integer Fixed PK batches per epoch; zero uses one shuffled identity pass 0
--camera-aware-sampler / --no-camera-aware-sampler boolean Prefer distinct-camera instances within each identity; cameras affect sampling only False
--margin float Triplet loss margin 0.3
--triplet-soft-margin / --triplet-hard-margin boolean Use softplus batch-hard triplet instead of the hard margin. Default: auto for transformer-family recipes, hard margin otherwise. True
--arcface-scale float ArcFace logit scale 30.0
--arcface-margin float ArcFace angular margin 0.5
--cosface-scale float CosFace logit scale 30.0
--cosface-margin float CosFace cosine margin 0.35
--label-smooth float Label smoothing epsilon 0.05
--center-loss-weight float Center loss weight 0.005
--id-loss-weight float Weight applied to the ID classification loss term 1.0
--metric-loss-weight float Weight applied to the metric loss term (triplet/wrt/circle/ms) 1.0
--adasp-loss-weight float Weight for AdaSP on the full normalized descriptor; 0 disables 0.0
--adasp-temperature float AdaSP similarity temperature 0.04
--adasp-scale float AdaSP paper-scale multiplier applied before its ablation weight 0.1
--coarse-branch-ce-weight float Relative CE weight for two-stripe branches; 0 disables coarse CE 1.0
--fine-branch-ce-weight float Relative CE weight for four-stripe branches; 0 disables fine CE 1.0
--part-relation-weight float EMA cross-ID neighborhood loss weight for corresponding fine parts 0.0
--part-to-global-weight float Weight for distilling aggregate part neighborhoods into global features 0.0
--part-relation-teacher-momentum float EMA momentum for the training-only part-relation teacher 0.999
--part-relation-temperature float Temperature for cross-ID part-neighborhood distillation 0.07
--compact-metric-loss-weight float Triplet-loss weight for an enabled compact deployment descriptor 1.0
--compact-cosine-distill-weight float Cosine alignment weight from compact student to the full teacher descriptor 1.0
--compact-pairwise-distill-weight float PK-batch pairwise-distance distillation weight for the compact student 1.0
--csmm-loss-weight float Cross-scale majority-margin auxiliary loss weight; 0 disables 0.0
--csmm-margin float Target cosine ranking margin for the median descriptor scale 0.1
--csmm-temperature float Softplus temperature for the cross-scale majority-margin loss 0.05
--csmm-topk-negatives integer Closest full-descriptor negatives evaluated per CSMM anchor 8
--csmm-start-epoch integer Epoch through which the CSMM auxiliary weight remains zero 20
--csmm-ramp-end-epoch integer Epoch where CSMM reaches --csmm-loss-weight 40
--treeboost-loss-weight float TreeBoost-AP hierarchical retrieval auxiliary loss weight; 0 disables 0.0
--treeboost-coarse-coefficient float Coefficient for coarse residual ranking supervision inside TreeBoost-AP 1.0
--treeboost-fine-coefficient float Coefficient for fine residual ranking supervision inside TreeBoost-AP 1.0
--treeboost-node-coefficient float Coefficient for upper/lower parent-child refinement terms 0.25
--treeboost-regression-coefficient float Coefficient penalizing ranking regressions at finer hierarchy levels 0.1
--treeboost-difficulty-floor float Minimum supervision retained for hierarchy levels after easy parent rankings 0.25
--treeboost-regression-tolerance float Allowed SmoothAP loss increase when adding a finer hierarchy level 0.02
--treeboost-temperature float Pairwise sigmoid temperature for cross-camera-positive TreeBoost SmoothAP 0.05
--treeboost-start-epoch integer Epoch through which the TreeBoost-AP auxiliary weight remains zero 30
--treeboost-ramp-end-epoch integer Epoch where TreeBoost-AP reaches --treeboost-loss-weight 60
--global-ap-loss-weight float Identity-defined dataset-memory SmoothAP weight on the deployed descriptor; 0 disables 0.0
--global-ap-temperature float Pairwise rank-relaxation temperature for GlobalAP 0.05
--global-ap-topk integer Different-identity hard negatives per GlobalAP query; all non-self same-identity positives remain 500
--global-ap-memory-size integer Stable sample-index capacity of the GlobalAP memory 16384
--global-ap-momentum float Descriptor momentum for repeated GlobalAP memory rows 0.2
--global-ap-max-age integer Maximum memory age in optimizer steps; 0 keeps all populated rows 0
--global-ap-start-epoch integer Last epoch with GlobalAP disabled 20
--global-ap-ramp-end-epoch integer Epoch where GlobalAP reaches full weight 50
--global-ap-decay-start-epoch integer Last epoch with GlobalAP at full weight 130
--global-ap-decay-end-epoch integer Epoch where GlobalAP returns to zero 170
--hpgrd-cache-dir path Offline human-privileged teacher cache used only during training None
--hpgrd-global-weight float External-teacher identity-relational distillation weight 0.0
--hpgrd-part-weight float Visibility-aware fixed-mask part relational distillation weight 0.0
--hpgrd-background-weight float Background-intervention descriptor consistency weight 0.0
--hpgrd-part-drop-weight float Semantic part leave-out teacher consistency weight 0.0
--hpgrd-part-drop-probability float Probability of masking one visible semantic part in a student view 0.0
--hpgrd-gradient-fraction float Maximum shared-feature HP-GRD gradient norm as a fraction of the base objective 0.3
--hpgrd-min-confidence float Minimum fused pose/parser teacher confidence 0.05
--early-id-loss-weight float Temporary ID loss weight for the first --early-id-loss-epochs epochs; 0 disables 0.0
--early-id-loss-epochs integer Number of initial epochs using --early-id-loss-weight 0
--center-loss-ramp-start-epoch integer Epoch through which center loss weight stays at 0; 0 disables unless end is set 0
--center-loss-ramp-end-epoch integer Epoch where center loss reaches --center-loss-weight; 0 disables ramping 0
--aux-ce-weight float Relative CE weight for auxiliary branch classifiers; 1.0 preserves equal branch averaging 1.0
--aux-ce-drop-epoch integer Set auxiliary CE weight to 0 after this epoch; 0 keeps it active for all epochs 0
--branch-loss-agg choice (mean | sum) How to aggregate multi-branch losses before weighting mean
--scale-balanced-branches / --no-scale-balanced-branches boolean Give global, two-stripe, and four-stripe scales equal CE and descriptor weight True
--multilevel-suppression / --no-multilevel-suppression boolean Train coarse and fine classifiers on evidence suppressed by the preceding scale False
--multilevel-suppression-ratio float Maximum top-saliency spatial fraction suppressed in the auxiliary path 0.15
--multilevel-suppression-loss-weight float Peak weight of scale-balanced multilevel suppression CE 0.2
--multilevel-suppression-start-epoch integer Epoch through which multilevel suppression remains disabled 20
--multilevel-suppression-ramp-end-epoch integer Epoch where suppression ratio and auxiliary CE reach full strength 50
--multilevel-suppression-decay-start-epoch integer Last epoch at full multilevel suppression strength 140
--multilevel-suppression-decay-end-epoch integer Epoch where multilevel suppression and auxiliary CE return to zero 170
--hierarchical-branch-attention / --no-hierarchical-branch-attention boolean Refine the 1-to-2-to-4 branch descriptors with tree-masked token attention False
--branch-attention-token-dim integer Token width used by hierarchical branch attention 96
--branch-attention-num-heads integer Attention heads used by hierarchical branch attention 4
--branch-attention-num-layers integer Transformer layers used by hierarchical branch attention 1
--branch-attention-mlp-ratio float Transformer MLP expansion ratio for hierarchical branch attention 2.0
--branch-attention-dropout float Dropout used by hierarchical branch attention 0.0
--branch-set-attention / --no-branch-set-attention boolean Refine all seven pooled 512-D branches with shared unmasked attention False
--branch-set-attention-token-dim integer Shared token width used by branch-set attention 128
--branch-set-attention-num-heads integer Attention heads used by branch-set attention 4
--branch-set-attention-num-layers integer Transformer layers used by branch-set attention 1
--branch-set-attention-mlp-ratio float Transformer MLP expansion ratio for branch-set attention 2.0
--branch-set-attention-dropout float Dropout used by branch-set attention 0.0
--multiscale-query-decoder / --no-multiscale-query-decoder boolean Decode seven pooled queries against final, Stage-2, and Stage-0 spatial maps False
--query-decoder-dim integer Shared query and spatial-memory token width 128
--query-decoder-num-heads integer Self- and cross-attention head count for the query decoder 4
--query-decoder-num-layers integer Number of residual multi-scale query decoder layers 1
--query-decoder-mlp-ratio float Query-decoder FFN expansion ratio 2.0
--query-decoder-dropout float Dropout used by the query decoder 0.0
--hierarchical-late-interaction / --no-hierarchical-late-interaction boolean Train the pair-conditioned hierarchical matcher and top-k reranker False
--late-interaction-dim integer Shared branch-token width for hierarchical late interaction 128
--late-interaction-num-heads integer Cross-attention head count for hierarchical late interaction 4
--late-interaction-num-layers integer Pair-conditioned cross-attention layer count 1
--late-interaction-sinkhorn-iters integer Sinkhorn normalization iterations for pair alignment 5
--late-interaction-null-tokens integer Learned null evidence tokens per image 1
--late-interaction-negative-identities integer Detached-base hard negative identities per anchor 16
--late-interaction-rerank-topk integer Base-cosine candidates reranked by late interaction 100
--late-interaction-base-score-init float Initial contribution of the proven base descriptor score 0.9
--late-interaction-loss-weight float Full-weight multi-positive matcher loss coefficient 0.2
--late-interaction-distill-weight float Full-weight matcher-to-base ranking distillation coefficient 0.05
--late-interaction-temperature float Listwise matcher and distillation temperature 0.07
--late-interaction-start-epoch integer Epoch through which late-interaction auxiliary weights remain zero 20
--late-interaction-ramp-end-epoch integer Epoch where matcher and distillation reach full weight 50
--mcpt-mode choice (none | dataset_boundaries | per_image_stage2 | shared_multiscale | foreground_aware_shared_multiscale) Monotonic canonical part transport treatment none
--mcpt-hidden-dim integer Hidden row-predictor width for RGB-conditioned MCPT 64
--mcpt-max-displacement float Maximum normalized vertical displacement 0.15
--mcpt-smoothness-weight float Second-difference MCPT regularization weight 0.01
--mcpt-identity-weight float Initial identity-warp regularization weight 0.02
--mcpt-identity-decay-epoch integer Epoch where MCPT identity regularization reaches zero 60
--mcpt-lr-multiplier float MCPT learning-rate multiplier relative to the head 2.0
--mcpt-start-epoch integer Last epoch with transport forced exactly off 10
--mcpt-ramp-end-epoch integer Epoch where the MCPT gate schedule reaches full scale 40
--mcpt-disabled-eval / --no-mcpt-disabled-eval boolean Also validate with MCPT forcibly disabled False
--jpm / --no-jpm boolean Enable training-only TransReID Jigsaw Patch Module False
--jpm-num-groups integer Number of JPM shuffled patch groups 4
--jpm-shift integer Patch-token cyclic shift before JPM shuffle 5
--jpm-token-dim integer JPM auxiliary transformer bottleneck width 96
--jpm-num-heads integer JPM shared transformer attention heads 4
--jpm-mlp-ratio float JPM shared transformer MLP expansion 4.0
--jpm-dropout float JPM shared transformer dropout 0.0
--jpm-id-loss-weight float Mean JPM local identity-loss coefficient 1.0
--jpm-metric-loss-weight float Mean JPM local triplet-loss coefficient 1.0
--metric-feature choice (auto | global | coarse_concat | raw_mean | raw_concat | concat_bn | dse_weighted | dse_mix) Feature representation used for metric losses when the model supports multiple branches raw_concat
--inference-feature choice (concat_bn | norm_concat_bn | global | raw_mean | raw_concat | visibility_weighted_parts | evidence_sinkhorn | dse_weighted | dse_mix) Feature representation emitted by CSL-TinyViT at validation/inference time norm_concat_bn
--feature-fusion choice (final | last2 | last3 | last4_layer0_target | last3_stage2_target | last3_stage1_concat | global_final_parts_stage1_concat | global_final_parts_fpn_layer0 | last3_fpn_stage1_add | last3_fpn_stage1_split | last3_panet_stage1_split | last3_panet_stage1_shared | last3_panet_stage1_scale_aware | last3_bifpn_stage1_split | last3_bifpn_stage1_branch_aware | global_final_parts_hierarchical_fpn | last3_fpn_stage2 | last3_pafpn_stage2 | last4_fpn_layer0_target | global_final_parts_stage2 | global_final_parts_stage2_semantic_residual | global_final_parts_stage2_hierarchical_control | global_final_parts_stage0_semantic_fine_reference | global_final_parts_stage0_semantic_fine | global_final_parts_stage0_fine_lite | global_final_parts_stage0_panet_lite | global_final_parts_stage0_bifpn_lite | global_final_parts_stage0_native_pyramid | global_final_parts_stage0_pool_first | late_concat_stage2 | weighted_last2 | weighted_last3 | normpres_last2 | normpres_last3 | dynamic_last3 | dynamic_last3_scale_token | dpt_fpn) CSL-TinyViT static or per-image dynamic spatial fusion before the ReID head global_final_parts_stage0_semantic_fine
--pyramid-resize-mode choice (bilinear | pool_nearest | pool_bilinear) Pyramid resizing: bilinear, average-pool down/nearest up, or average-pool down/bilinear up bilinear
--spatial-conv-mode choice (standard | depthwise_separable | bottleneck_depthwise) CSL-TinyViT neck/FPN 3x3 convolution implementation depthwise_separable
--post-fusion-mixer choice (none | dwconv) Optional zero-gated local mixer after CSL-TinyViT feature fusion none
--post-fusion-mixer-reduction integer Channel reduction ratio for the post-fusion local mixer 4
--post-fusion-mixer-kernel text Post-fusion depthwise mixer kernel as H,W, e.g. 5,3 5,3
--post-fusion-mixer-gamma-init float Initial residual scale for the post-fusion local mixer 0.0
--feat-dim integer Per-branch embedding dimension for ReID heads that support projection 512
--neck-dim integer Neck channel dimension for ReID backbones that support a feature neck 512
--drop-path-rate float Maximum stochastic-depth probability for CSL-TinyViT 0.1
--timm-model-name text Optional exact timm pretrained model tag for MobileNetV4 ``
--timm-head-mode choice (pooled | spatial | spatial_adapt_norm | spatial_linear | off) MobileNetV4 C5 head path, including spatial normalization controls pooled
--mobilenetv4-last-stride integer range (between 1 and 2) MobileNetV4 final spatial stride: 1 retains stride-16 C5; 2 keeps ImageNet topology 2
--mobilenetv4-neck-mode choice (cnn | spatial_ln) MobileNetV4 ReID neck: CNN projection or TinyViT-matched spatial LayerNorm neck cnn
--attention-window-layout choice (legacy | rect) CSL-TinyViT attention windows: legacy square windows or ReID rectangular windows rect
--attention-bias choice (absolute | signed_factorized) CSL-TinyViT relative attention bias parameterization absolute
--interpolate-pretrained-attention-bias / --no-interpolate-pretrained-attention-bias boolean Resize official absolute attention-bias tables for non-legacy attention windows True
--attention-mask / --no-attention-mask boolean Mask padded tokens in CSL-TinyViT window attention True
--attention-shift / --no-attention-shift boolean Alternate shifted CSL-TinyViT windows in attention stages 1 and 2 False
--stage3-global / --no-stage3-global boolean Use full 24x8 attention in the final CSL-TinyViT block False
--stage3-downsample / --no-stage3-downsample boolean Downsample only the final/global transformer stage while retaining Stage-2 local tokens False
--stage2-width-merge-after integer Merge adjacent Stage-2 columns after this many blocks; 0 disables 0
--stage2-mlp-ratio float MLP expansion ratio used only in CSL-TinyViT Stage 2 4.0
--stage3-mlp-ratio float MLP expansion ratio used only in CSL-TinyViT Stage 3 4.0
--stage2-depth integer Number of transformer blocks used only in CSL-TinyViT Stage 2 6
--stage3-depth integer Number of transformer blocks used only in CSL-TinyViT Stage 3 2
--width-first-hierarchy / --no-width-first-hierarchy boolean Preserve vertical detail via 48x16 -> 48x8 -> 24x8 CSL-TinyViT stages False
--identity-registers / --no-identity-registers boolean Exchange Stage-2/3 context through global identity-register tokens False
--identity-register-count integer Number of global identity-register tokens 4
--identity-register-dim integer Bottleneck width used for identity-register communication 128
--identity-register-num-heads integer Attention heads used by identity-register communication 4
--identity-register-dropout float Training-time probability of dropping each identity register 0.1
--identity-register-gate-init float Initial residual broadcast gate for identity registers 0.0
--identity-register-diversity-weight float Weight for the weak identity-register diversity loss 0.0
--identity-register-diversity-margin float Maximum unpenalized cosine similarity between identity registers 0.1
--native-branch-widths / --no-native-branch-widths boolean Keep global/local/fine fusion maps at descriptor-native 512/256/128 widths False
--fine-map-dim integer Fine Stage-0 fusion-map channels; 0 keeps the full neck width 0
--compact-deployment-head / --no-compact-deployment-head boolean Train seven teacher branches but emit one distilled 512-D descriptor at inference False
--reid-adapter-stages text CSL-TinyViT attention stages that receive zero-gated ReID residual adapters ``
--reid-adapter-reduction integer Channel reduction ratio for CSL-TinyViT ReID residual adapters 4
--reid-adapter-suppression-tau float RMS-saliency suppression threshold for ReID adapters; 0 disables 0.0
--head-pool choice (avg | gem | dse | gelu_gem | relu_gem | softplus_gem) Pooling layer used by CSL-TinyViT multi-branch heads gelu_gem
--head-parts text CSL-TinyViT head granularities, e.g. 1,2 for global+2 parts or 1,2,4 for MGN 1,2,4
--head-type choice (standard | gpc_lite | stage2_channel2 | multiscale_channel2 | stage2_pg | stage2_gpc_lite | stage2_gpc_lite_gate | stage2_pg_gate | suppressed_global | body_slot) CSL-TinyViT branch head, including optional channel and G/P/C specialists standard
--multiscale-channel-alpha float Channel power amplitude mixed inside each global/coarse/fine scale 0.5
--body-slot-mode choice (recurrent_read | recurrent_read_write) Persistent body-slot communication: read-only Tier B or zero-gated read/write Tier C recurrent_read
--body-slot-alpha float Descriptor power allocated to the 512-D global stream 0.45
--body-slot-visibility-floor float Minimum retrieval power retained for every body slot 0.05
--part-pooling choice (stripes | overlap_stripes | tokens | semantic_parts) CSL-TinyViT local pooling: fixed, overlapping, learned-token, or semantic-visibility parts stripes
--num-part-tokens integer Number of learned local/evidence queries for token or semantic-part pooling 4
--evidence-num-roles integer Number of latent semantic role bins for CSL-TinyViT evidence tokens 8
--decouple-patterns / --no-decouple-patterns boolean Use separate zero-initialized residual adapters for global and local features False
--pattern-adapter-dim integer Bottleneck width of each global/local pattern adapter 128
--stripe-visibility / --no-stripe-visibility boolean Learn a per-image confidence for each fixed local stripe False
--drop-global-aux / --no-drop-global-aux boolean Add a training-only dropped-global CE auxiliary classifier to the standard CSL-TinyViT head False
--drop-global-aux-ratio float Horizontal activation-band ratio suppressed by --drop-global-aux 0.25
--branch-aware-metric / --no-branch-aware-metric boolean Apply metric loss separately to CSL-TinyViT global and part branches False
--branch-metric-part-weight float Weight for each part branch metric loss when branch-aware metric is enabled 0.5
--evidence-alignment-loss-weight float Weight for batch Sinkhorn evidence alignment loss; 0 disables 0.0
--evidence-alignment-margin float Negative-pair margin for evidence alignment loss 0.2
--evidence-sinkhorn-iters integer Sinkhorn iterations for evidence alignment and reranking 20
--evidence-sinkhorn-temperature float Sinkhorn temperature for evidence alignment and reranking 0.1
--evidence-rerank-topk integer Gallery top-K reranked with evidence Sinkhorn distance; 0 reranks all 100
--evidence-null-loss-weight float Weight for explicit final-token null/background supervision; 0 disables 0.0
--evidence-diversity-loss-weight float Weight for role/descriptor diversity regularization across evidence tokens 0.0
--head-warmup-epochs integer Train only CSL-TinyViT neck/head for the first N epochs 0
--head-warmup-lr-mult float LR multiplier for neck/head parameter groups during head warmup 2.0
--eta-min float Minimum learning rate for cosine annealing schedule 1e-07
--pretrained / --no-pretrained boolean Use ImageNet-pretrained backbone True
--pretrained-weights file Local exact-backbone checkpoint from human pretraining; overrides model-zoo init None
--device text cuda device, e.g. 0 or cpu or mps mps
--project path Save directory runs/reid_train
--name text Experiment name exp
--num-workers integer Dataloader workers 4
--seed integer Global random seed for Python, NumPy, PyTorch, samplers, and dataloader workers 0
--deterministic / --no-deterministic boolean Require deterministic PyTorch algorithms and backend behavior True
--eval-datasets text Comma-separated list of extra datasets for cross-domain evaluation (e.g. duke,cuhk03,msmt17) ``
--flip-tta / --no-flip-tta boolean Use horizontal flip augmentation during validation (default: recipe value) None
--ema-decay float EMA momentum decay for model averaging (e.g. 0.999). Disabled by default. Inspired by DynaMix 0.0
--gaussian-blur / --no-gaussian-blur boolean Apply random Gaussian blur augmentation True
--color-jitter / --no-color-jitter boolean Apply color jitter augmentation (auto-enabled for transformer-family recipes) True
--random-grayscale float Probability of random grayscale conversion (0 to disable) 0.1
--random-erasing float Probability of random erasing augmentation (0 to disable) 0.5
--random-patch / --no-random-patch boolean Apply random patch augmentation True
--random-crop-scale float Random2DTranslation resize factor before crop; 1.05 matches LMBN implementation 1.05
--color-augmentation / --no-color-augmentation boolean Enable additional color augmentation mix used by LMBN-style recipes True
--background-mosaic / --no-background-mosaic boolean Replace only the anchor background with a four-source donor mosaic False
--background-mosaic-mask-dir path Mask root containing primary/ anchor and all_people/ donor trees None
--background-mosaic-probability float Maximum probability of identity-preserving background mosaic 0.3
--background-mosaic-start-epoch integer Keep background mosaic disabled through this epoch 10
--background-mosaic-ramp-end-epoch integer Epoch at which background mosaic reaches its maximum probability 30
--background-mosaic-min-foreground-ratio float Reject anchor masks retaining less than this image fraction 0.2
--background-mosaic-max-foreground-ratio float Reject anchor masks retaining more than this image fraction 0.9
--background-mosaic-feather float Gaussian mask-edge feather radius in source-image pixels 1.5
--background-mosaic-dilation integer Foreground-mask dilation radius before background compositing 2
--background-mosaic-occluder-probability float Probability of adding a boundary-entering person occluder 0.0
--background-mosaic-occluder-min-area float Minimum image fraction covered by a context occluder 0.05
--background-mosaic-occluder-max-area float Maximum image fraction covered by a context occluder 0.2
--same-id-part-mosaic / --no-same-id-part-mosaic boolean Copy body-aligned regions from same-ID batch donors False
--same-id-part-mosaic-probability float Probability of selecting each sample for same-ID part mosaic 0.35
--same-id-part-mosaic-max-regions integer Maximum number of body regions copied per augmented sample 2
--same-id-part-mosaic-min-area float Minimum total image fraction replaced by same-ID regions 0.15
--same-id-part-mosaic-max-area float Maximum total image fraction replaced by same-ID regions 0.4
--same-id-part-mosaic-boundary-jitter float Body-region boundary jitter as a fraction of image height 0.05
--same-id-part-mosaic-cross-camera-rate float Rate of preferring different-camera same-ID donors when available 1.0
--same-id-part-mosaic-min-unaltered float Minimum fraction of each training batch left unaltered 0.5
--pav-mosaic / --no-pav-mosaic boolean Warp semantic body parts from pose-aligned same-ID donors False
--pav-metadata-dir path PAV metadata root generated by tools.create_market1501_pav_metadata None
--pav-mosaic-probability float Maximum scheduled probability of PAV-Mosaic 0.25
--pav-mosaic-max-parts integer Maximum semantic body parts replaced per PAV sample 3
--pav-mosaic-max-foreground-replacement float Maximum anchor-foreground fraction replaced by PAV 0.45
--pav-mosaic-cross-camera-rate float Rate of preferring cross-camera same-ID PAV donors 0.8
--pav-mosaic-different-pose-rate float Rate of favoring pose-diverse PAV donors 0.5
--pav-mosaic-min-keypoint-confidence float Minimum pose-keypoint confidence for a semantic part 0.5
--pav-mosaic-min-unaltered float Minimum fraction of each batch reverted to a clean view 0.5
--pav-mosaic-warmup-epochs integer Epochs used to ramp PAV probability from zero 40
--pav-mosaic-decay-start-epoch integer Epoch at which final PAV probability decay begins 170
--pav-mosaic-final-probability-scale float Fraction of maximum PAV probability retained at the final epoch 0.5
--pav-consistency-weight float Clean-versus-PAV cosine embedding consistency weight 0.0
--clean-student-consistency-weight float Weight for clean-teacher query and descriptor consistency on augmented RGB views 0.0
--anatomical-auxiliary / --no-anatomical-auxiliary boolean Train RGB anatomical tokens from privileged pose/mask targets False
--anatomical-metadata-dir path Pose/person-mask metadata root used only during training None
--anatomical-person-mask-dir path External high-confidence person-mask directory used only during training None
--anatomical-min-keypoint-confidence float Minimum pose confidence used to rasterize anatomical targets 0.5
--anatomical-token-dim integer Width of the six grid-aligned anatomical tokens (minimum 16) 128
--anatomical-distill-weight float Weight for same-scale mask-routed token consistency 0.2
--anatomical-attention-weight float Weight for scale-aware anatomical cell-routing KL supervision 0.1
--anatomical-foreground-weight float Weight for RGB foreground mask supervision 0.15
--anatomical-semantic-part-weight float Weight for training-only six-part semantic BCE/Dice supervision 0.0
--anatomical-visibility-weight float Weight for per-part visibility supervision 0.05
--anatomical-contrastive-weight float Weight for visible same-part cross-camera contrastive learning 0.1
--anatomical-descriptor-distill-weight float Weight for local semantic anatomy distillation into the final descriptor 0.0
--anatomical-branch-distill-weight float Weight for EMA anatomy relations distilled into deployed 1/2/4-stripe branches 0.0
--anatomical-branch-global-coefficient float Global-level share of anatomical branch distillation 0.2
--anatomical-branch-coarse-coefficient float Two-stripe-level share of anatomical branch distillation 0.3
--anatomical-branch-fine-coefficient float Four-stripe-level share of anatomical branch distillation 0.5
--anatomical-pose-teacher-weight float Weight for the selected privileged pose-teacher objective 0.0
--anatomical-query-distill-weight float Weight for masked-teacher to unrestricted-RGB query distillation 0.0
--anatomical-query-relational-distill-weight float Weight for visibility-weighted teacher/student query relation matching 0.0
--anatomical-query-diversity-weight float Weight discouraging collapse among RGB anatomical queries 0.0
--anatomical-query-diversity-margin float Maximum allowed cosine similarity between distinct queries 0.1
--anatomical-part-triplet-weight float Weight for visible same-part cross-camera hard triplets 0.0
--anatomical-target-type choice (deterministic_scale_aware_geometry | learned_pose_concat_ema | learned_pose_semantic_ema | learned_pose_semantic_fused_ema | privileged_mask_pose_attention | decoupled_pose_parsing_teacher | body_slot_privileged_ema) Anatomical teacher implementation used for training deterministic_scale_aware_geometry
--anatomical-teacher-momentum float EMA momentum for learned pose-teacher targets 0.99
--anatomical-multiscale / --no-anatomical-multiscale boolean Supervise matched anatomical roles on Stage-2 local and Stage-0 fine maps False
--anatomical-accessory-query / --no-anatomical-accessory-query boolean Add a training-only seventh mask-supervised bag/accessory query False
--anatomical-deployment / --no-anatomical-deployment boolean Append six pose-supervised RGB semantic-part tokens to the retrieval descriptor False
--anatomical-deployment-dim integer Deployed width of each RGB anatomical part token 64
--anatomical-deployment-alpha float Relative retrieval energy assigned to the deployed anatomical descriptor 0.25
--anatomical-deployment-id-weight float Persistent visibility-weighted ID loss for deployed anatomical parts 0.25
--anatomical-deployment-metric-weight float Persistent cross-camera contrastive loss for deployed anatomical parts 0.1
--anatomical-local-scale-weight float Balanced contribution of the Stage-2 anatomical student 0.6
--anatomical-fine-scale-weight float Balanced contribution of the Stage-0 anatomical student 0.4
--anatomical-cross-scale-weight float Weight aligning within-image anatomical role relations across scales 0.05
--anatomical-pose-only-reliability float Reliability multiplier for pose targets without a person mask 0.35
--anatomical-min-effective-coverage float Minimum fraction of training samples with usable anatomical targets 0.0
--anatomical-student-start-epoch integer Last epoch before shared anatomical supervision starts 0
--anatomical-student-ramp-end-epoch integer Epoch at which anatomy distillation reaches full weight 0
--anatomical-query-start-epoch integer Last epoch before decoupled query distillation and triplets start 20
--anatomical-query-ramp-end-epoch integer Epoch at which decoupled query losses reach full weight 50
--anatomical-fine-start-epoch integer Last epoch before fine-map anatomy starts; 0/0 follows the shared student schedule 0
--anatomical-fine-ramp-end-epoch integer Epoch at which fine-map and cross-scale anatomy reach full weight 0
--anatomical-decay-start-epoch integer Epoch at which all anatomical losses begin decaying 0
--anatomical-decay-end-epoch integer Epoch at which all anatomy losses become zero 0
--anatomical-temperature float Temperature for anatomical supervised contrastive learning 0.07
--resume path Resume training from a checkpoint dir or last.pt file None
--help boolean Show this message and exit. False