table-transformer-detection-mlx

ζ—₯本θͺžη‰ˆγ―こけら (README.ja.md)

Model Summary

This is an unofficial MLX conversion of microsoft/table-transformer-detection (a table-region detector for document images, using a ResNet18 backbone and a DETR-style encoder-decoder). All credit for the original model goes to its authors (Microsoft).

This cannot be loaded with mlx-vlm

A ResNet18 + DETR-style encoder-decoder with learned object queries isn't in mlx-vlm's list of supported architectures, so this was reimplemented from scratch for MLX and requires the bundled table_transformer_mlx.py.

Limitation: fixed square input only, no padding

This implementation is simplified by assuming pixel_mask is always fully valid (no padding). Concretely, it only works correctly when input images are always resized to a fixed 800x800 square (not when batching images of different aspect ratios with letterbox-style padding). This simplification lets the implementation skip the attention-mask handling that DETR-family models normally require.

Usage

import mlx.core as mx
from mlx.utils import tree_unflatten
from PIL import Image
import numpy as np

from table_transformer_mlx import TableTransformerMLX, IMAGE_SIZE

model = TableTransformerMLX()
weights = mx.load("model.safetensors")
model.update(tree_unflatten(list(weights.items())))
mx.eval(model.parameters())

image = Image.open("document.png").convert("RGB").resize((IMAGE_SIZE, IMAGE_SIZE))
pixel_values = np.asarray(image, dtype=np.float32) / 255.0
pixel_values = (pixel_values - np.array([0.485, 0.456, 0.406])) / np.array([0.229, 0.224, 0.225])
pixel_values = mx.array(pixel_values[None].astype(np.float16))  # (1, 800, 800, 3), NHWC

logits, boxes = model(pixel_values)  # logits: (1, 15, 3), boxes: (1, 15, 4) normalized cxcywh

id2label is the same as the original model: {0: "table", 1: "table rotated"} (class 2 means "no object"). boxes are (center_x, center_y, width, height) normalized to [0, 1].

Accuracy

Compared against the PyTorch fp32 reference on a COCO validation image:

Precision Logits cosine sim. Boxes cosine sim. Label agreement
MLX fp32 1.0 1.0 100%
MLX fp16 (this release) 0.9999995 0.9999999 100%

Specs

Item Value
Base model microsoft/table-transformer-detection (ResNet18 + DETR, 28.8M params)
Precision float16
Input 800x800, NHWC, fixed size, no padding
Framework MLX (from-scratch table_transformer_mlx.py)

Notes

  • This is a community conversion, not an official release from Microsoft.
  • Security audit uses model-audit-lite (see SECURITY.md for details).

Security

Audited against its upstream with model-audit-lite: weight format, bundled code, and a machine-readable lineage (ML-BOM). Details, checksums and how to reproduce: SECURITY.md.

Downloads last month

-

Downloads are not tracked for this model. How to track
Safetensors
Model size
28.8M params
Tensor type
F16
Β·
MLX
Hardware compatibility
Log In to add your hardware

Quantized

Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for masahiroid/table-transformer-detection-mlx

Finetuned
(17)
this model