Skip to content

The tail-suspension mouse detector, and the trackers that use no neural network ​

TUTORIAL 3 · MOUSEDETECTOR

The third bundled model is a small object detector for multi-chamber tail-suspension videos. This page describes what the package records, how the app uses it, and how to train a detector for your own rig.

YOLO11n detect1 class320 pxCore ML · FP16 · NMS

What the detector does in the app ​

In the Tail Suspension Test — Multi-Chamber workflow, one recording shows several mice hanging in neighbouring chambers. The detector finds a box around each mouse in sampled frames. RodentFlow uses those boxes to locate the chambers (from boxes with confidence ≥ 0.35), to pre-select the chambers in which a mouse was seen in at least two sampled frames and, while scanning the video, to find the moment each mouse is suspended. Immobility itself is scored from frame-to-frame motion of the mouse's outline, not by the detector.

The settings offer three detector modes: Automatic (YOLO when a model is available), YOLO model, and Classical (a dark blob per chamber). A model the user imports takes precedence over the bundled one, and the exports record which detector was actually used.

What the package records ​

Shipped fileMouseDetector.mlpackage (5.14 MiB), in TSTMulti/Models/
Description“Ultralytics YOLO11n model trained on …/datasets/tst_mouse/data.yaml”
Task / classesObject detection; names = {0: 'mouse'}
Input320 × 320 RGB image, plus two optional numbers, iouThreshold (default 0.7) and confidenceThreshold (default 0.25)
Outputsconfidence and coordinates (normalized box centre, width, height) after non-maximum suppression
Export settings{'batch': 1, 'quantize': 16, 'nms': True, 'dynamic': False} → FP16 weights, Core ML pipeline with an NMS stage
SoftwareUltralytics 8.4.182, PyTorch 2.14.1 (CUDA 13.0), coremltools 9.0; exported 18 October 2026
Licence fieldAGPL-3.0 (written by Ultralytics on export)
Source: the package's Core ML specification, read with coremltools. Note one oddity: the `confidence` output declares 80 columns although only one class is named. The app reads results by label name, so this does not affect it, but it is a reminder to inspect a package rather than assume its layout.

How the app runs it ​

Unlike the two pose models, the detector does not rely on Vision's own resizing. RodentFlow letterboxes each processed (grey, oriented, downscaled) frame itself, centred on a grey (114) background exactly as Ultralytics does during training, and then asks Vision to use the image as is:

// TSTMulti/Detection/YOLOMouseDetector.swift (condensed)
let r = min(Double(inputW) / Double(frame.width), Double(inputH) / Double(frame.height))
let padX = (Double(inputW) - Double(frame.width) * r) / 2
let padY = (Double(inputH) - Double(frame.height) * r) / 2
ctx.setFillColor(CGColor(gray: 114.0 / 255.0, alpha: 1))          // Ultralytics' padding colour
ctx.fill(CGRect(x: 0, y: 0, width: inputW, height: inputH))
ctx.draw(src, in: CGRect(x: padX, y: padY, width: dw, height: dh))
request.imageCropAndScaleOption = .scaleFill                      // already the exact input size
// NMS pipelines take their thresholds as extra inputs:
vnModel.featureProvider = try? MLDictionaryFeatureProvider(dictionary: [
    "iouThreshold": MLFeatureValue(double: 0.45),
    "confidenceThreshold": MLFeatureValue(double: 0.1)])           // low; the app applies its own minimum

Boxes come back as VNRecognizedObjectObservations and are mapped to frame pixels with (x − padX) / r. The same class also decodes raw (non-NMS) exports and runs its own NMS, so a lab can import either kind of export.

Training a detector for your rig ​

The recipe below is the generic Ultralytics workflow that produces a package of the same kind. Use it to train a detector on images of your own rig.

# data.yaml: one class
#   path: /data/tst_mouse
#   train: images/train
#   val: images/val
#   names: {0: mouse}
from ultralytics import YOLO
model = YOLO('yolo11n.pt')                                   # COCO-pretrained YOLO11 nano detector
model.train(data='data.yaml', imgsz=320, epochs=100)
model.export(format='coreml', imgsz=320, quantize=16, nms=True)   # Ultralytics 8.4.x argument names
  • Label real frames from your rig, including empty chambers, climbing mice and partial views.
  • Split by recording, not by frame, and keep some recordings for testing.
  • Report precision and recall on those held-out recordings, then import the .mlpackage in the TST settings.

Trackers without a neural network ​

Not every RodentFlow workflow uses a trained model. These need no model citation, but should be described in methods:

  • RodentFlow workflows (open field, EPM, light–dark box, Y- and T-maze, NOR, water maze, Barnes maze, fear conditioning, place preference) use a classical single-mouse tracker ported from RodentFlow 1.3. Its pipeline is a temporal-median background, absolute difference, adaptive threshold, connected components and a contrast-weighted centroid, sampled at 10 Hz. The source states that no pose estimation, optical flow or neural network is used.
  • Classical TST detector: finds the dark blob in each chamber, used when no YOLO model is available or when chosen in settings.

What to cite ​

If the YOLO detector was used, cite Ultralytics YOLO11 (software) and RodentFlow with its version, and state the detector mode recorded in the export. See the citation page.