查看 Markdown

TinyFormer

TinyFormer is a trainable transformer detector with a DINOv3 backbone.

任务
detection
安装
pip install libreyolo
支持层级
核心,自 v1.6.0 起。核心的可训练检测器:功能在同一个发布波次里紧跟旗舰。
上游
TinyFormer,由 TinyFormer authors 发布,采用 Apache-2.0; DINOv3 terms 许可。论文、源码
许可
代码采用 MIT,权重采用 Apache-2.0; DINOv3 terms。商用

Install

bash
pip install "libreyolo"

Predict

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreTinyFormers.pt", device="cpu")result = model(SAMPLE_IMAGE)print(result)

Choose a published checkpoint below. The naming distinguishes the VisDrone variants and Objects365-to-COCO variants. Prediction requires a square imgsz; rectangular inputs raise an error.

Train

Training accepts a detection dataset YAML. Omitted epochs, batch, imgsz, lr0 and amp use the family recipe.

Dataset setup describes the required training data.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreTinyFormers.pt", device="cpu")# coco8.yaml is a built-in 8-image detection dataset that downloads on first use.# Replace it with the path to your own detection dataset YAML.model.train(data="coco8.yaml", epochs=1, device="cpu", workers=0)

Validate

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreTinyFormers.pt", device="cpu")# coco8.yaml downloads on first use; pass your own detection dataset YAML instead.metrics = model.val(data="coco8.yaml", workers=0)print(metrics)

Use the dataset format for this task. Validation explains the dataset requirements and returned metrics.

Export

任务ONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
DetectionDetection to ONNX:支持Detection to TorchScript:支持Detection to ExecuTorch:支持Detection to TensorRT:支持Detection to OpenVINO:支持Detection to Paddle:不支持Detection to MNN:不支持Detection to RKNN:不支持Detection to ncnn:不支持Detection to TFLite:不支持Detection to CoreML:不支持Detection to Core AI:不支持
Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreTinyFormers.pt", device="cpu")model.export(format="onnx")

Export setup lists format dependencies and loading exported artifacts.

ONNX inputs and outputs

张量images float32 [batch, 3, height, width]
颜色RGB
缩放像素 / 255
归一化均值 [0.485,0.456,0.406], 标准差 [0.229,0.224,0.225]
缩放方式拉伸到 宽 x 高(不填充,不保持宽高比), Pillow bilinear
如何复现 Pillow 的双线性缩放

LibreYOLO 使用 Pillow 的 BILINEAR 滤波器(Image.resize)缩放。它不是 OpenCV 的 INTER_LINEAR 或 INTER_AREA:缩小时,Pillow 会按缩小倍数加宽滤波器,而 OpenCV 的缩放会改变检测结果,并使框移动数个像素。要在不使用 Pillow 的情况下复现它,先缩放一个轴,舍入到 8 位,再缩放另一个轴并再次舍入。对每个轴,令 s = in_size / out_size,f = max(s, 1)。输出像素 i 的中心为 c = (i + 0.5) * s,读取源像素 j,范围从 int(c - f + 0.5) 到 int(c + f + 0.5) - 1(限制在图像内),每个像素的权重为 max(0, 1 - |j + 0.5 - c| / f),再除以权重之和。Pillow 使用定点运算,并根据图像形状选择轴的顺序,因此浮点权重在少数像素上可能与它相差一个等级。这不会改变我们检查中的结果。

Square input only. Export rejects a non-square imgsz, and height and width are 640 by default for every size. Another square imgsz must be a multiple of 32.

Batch size 1 only. The graph declares a dynamic batch axis, but batches of 2 or more fail in 1.7.0.

After the resize, divide by 255, then subtract the ImageNet mean and divide by the ImageNet std, per channel in RGB order.

Detection,默认导出
输出形状含义
pred_logits[batch, queries, nc]One logit per query and class. Sigmoid is not applied. queries is 300 for every size.
pred_boxes[batch, queries, 4]cx, cy, w, h of each query, normalized 0 to 1 of the input. The input is the whole image stretched, so these are also fractions of the original image.

后处理

  1. Apply sigmoid to pred_logits.
  2. Flatten the [queries, nc] scores and take the top 300 (max_det, 300 by default). For flat index k, the query is k // nc and the class is k % nc. One query can yield several classes.
  3. Keep the pairs whose score is above the confidence threshold (0.25 by default).
  4. Convert the query's box to x1 = cx - w / 2, y1 = cy - h / 2, x2 = cx + w / 2, y2 = cy + h / 2. Multiply x by the original image width and y by the original image height.
  5. There is no NMS and the iou threshold is not used. TinyFormer predicts a set of boxes, and export with nms=True raises NotImplementedError.
  6. LibreYOLO does not clip these boxes, so an edge can sit slightly outside the image.

要检查你自己的实现,请用 LibreYOLO 运行同一个文件:LibreYOLO("model.onnx").predict("image.jpg") 会返回参考结果。 已用 LibreYOLO 1.7.0 验证。

Checkpoints

Licensing

请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。

这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。

原始工作
TinyFormer, TinyFormer authors
上游许可
Apache-2.0; DINOv3 terms
LibreYOLO 代码
MIT
权重
采用 Apache-2.0; DINOv3 terms 许可,重新发布在 huggingface.co/LibreYOLO
解读
The detector uses Apache-2.0 source and a DINOv3 backbone with its own terms. Check the publisher declarations for the chosen checkpoint.

Citation

@article{hsieh2026tinyformer,

  title={TinyFormer: Preserving Tiny Objects in YOLO-DETR Hybrid Real-time Detectors},

  author={Hsieh, Jun-Wei and Kao, Meng-Yu and Kurniawan, Ghufron Wahyu and Peng, Kuan-Chuan},

  journal={arXiv preprint arXiv:2605.25046},

  year={2026}

}

复制自作者在 raw.githubusercontent.com/mmpmmpmmpjosh/TinyFormer/main/README.md 上提供的引用块。

已针对 LibreYOLO v1.6.0 验证。本页的支持表、检查点和基准测试数据由已发布的库和权重生成,并非手工编写。