Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,8 @@
title: SigLIP
- local: model_doc/siglip2
title: SigLIP2
- local: model_doc/slanet
title: SLANet
- local: model_doc/slanext
title: SLANeXt
- local: model_doc/smollm3
Expand Down
80 changes: 80 additions & 0 deletions docs/source/en/model_doc/slanet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!--Copyright 2026 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.

-->
*This model was released on 2025-03-07 and added to Hugging Face Transformers on 2026-04-22.*

# SLANet

<div class="flex flex-wrap space-x-1">
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
</div>

## Overview

**SLANet** and **SLANet_plus** are part of a series of dedicated lightweight models for table structure recognition, focusing on accurately recognizing table structures in documents and natural scenes. For more details about the SLANet series model, please refer to the [official documentation](https://www.paddleocr.ai/latest/en/version3.x/module_usage/table_structure_recognition.html).

## Model Architecture

SLANet is a table structure recognition model developed by Baidu PaddlePaddle Vision Team. The model significantly improves the accuracy and inference speed of table structure recognition by adopting a CPU-friendly lightweight backbone network PP-LCNet, a high-low-level feature fusion module CSP-PAN, and a feature decoding module SLA Head that aligns structural and positional information.

## Usage

### Single input inference

The example below demonstrates how to detect text with SLANet using the [`AutoModel`].

<hfoptions id="usage">
<hfoption id="AutoModel">

```py
from io import BytesIO

import httpx
from PIL import Image
from transformers import AutoImageProcessor, AutoModelForTableRecognition

model_path="PaddlePaddle/SLANet_plus_safetensors"
model = AutoModelForTableRecognition.from_pretrained(model_path, device_map="auto")
image_processor = AutoImageProcessor.from_pretrained(model_path)

image = Image.open(BytesIO(httpx.get(image_url).content))
inputs = image_processor(images=image, return_tensors="pt").to(model.device)
outputs = model(**inputs)

results = image_processor.post_process_table_recognition(outputs)

print(result['structure'])
print(result['structure_score'])
```

</hfoption>
</hfoptions>

## SLANetConfig

[[autodoc]] SLANetConfig

## SLANetForTableRecognition

[[autodoc]] SLANetForTableRecognition

## SLANetBackbone

[[autodoc]] SLANetBackbone

## SLANetSLAHead

[[autodoc]] SLANetSLAHead

1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
from .shieldgemma2 import *
from .siglip import *
from .siglip2 import *
from .slanet import *
from .slanext import *
from .smollm3 import *
from .smolvlm import *
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/auto_mappings.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, already used the auto mappings :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
("siglip2_vision_model", "Siglip2VisionConfig"),
("siglip_text_model", "SiglipTextConfig"),
("siglip_vision_model", "SiglipVisionConfig"),
("slanet", "SLANetConfig"),
("slanext", "SLANeXtConfig"),
("smollm3", "SmolLM3Config"),
("smolvlm", "SmolVLMConfig"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/image_processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
("sam3_video", {"torchvision": "Sam3ImageProcessor"}),
("sam_hq", {"torchvision": "SamImageProcessor", "pil": "SamImageProcessorPil"}),
("shieldgemma2", {"torchvision": "Gemma3ImageProcessor", "pil": "Gemma3ImageProcessorPil"}),
("slanet", {"torchvision": "SLANeXtImageProcessor"}),
("swiftformer", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
("swin", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
("swinv2", {"torchvision": "ViTImageProcessor", "pil": "ViTImageProcessorPil"}),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/modeling_auto.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add the slanext image processor to the auto mappings in image_processing_auto (under MISSING_IMAGE_PROCESSOR_MAPPING_NAMES)

Seems like the auto mappings didnt pick it up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):

MODEL_FOR_TABLE_RECOGNITION_MAPPING_NAMES = OrderedDict(
[
("slanet", "SLANetForTableRecognition"),
("slanext", "SLANeXtForTableRecognition"),
]
)
Expand Down
28 changes: 28 additions & 0 deletions src/transformers/models/slanet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2026 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING

from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_slanet import *
from .modeling_slanet import *
else:
import sys

_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
77 changes: 77 additions & 0 deletions src/transformers/models/slanet/configuration_slanet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# This file was automatically generated from src/transformers/models/slanet/modular_slanet.py.
# Do NOT edit this file manually as any edits will be overwritten by the generation of
# the file from the modular. If any change should be done, please apply the change to the
# modular_slanet.py file directly. One of our CI enforces this.
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# Copyright 2026 The PaddlePaddle Team and The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from huggingface_hub.dataclasses import strict

from ...backbone_utils import consolidate_backbone_kwargs_to_config
from ...configuration_utils import PreTrainedConfig
from ...utils import auto_docstring
from ..auto import AutoConfig


@auto_docstring(checkpoint="PaddlePaddle/SLANet_plus_safetensors")
@strict
class SLANetConfig(PreTrainedConfig):
r"""
post_conv_out_channels (`int`, *optional*, defaults to 96):
Number of output channels for the post-encoder convolution layer.
out_channels (`int`, *optional*, defaults to 50):
Vocabulary size for the table structure token prediction head, i.e., the number of distinct structure
tokens the model can predict.
hidden_size (`int`, *optional*, defaults to 256):
Dimensionality of the hidden states in the attention GRU cell and the structure/location prediction heads.
max_text_length (`int`, *optional*, defaults to 500):
Maximum number of autoregressive decoding steps (tokens) for the structure and location decoder.
csp_kernel_size (`int`, *optional*, defaults to 5):
The kernel size of the Cross Stage Partial (CSP) layer.
csp_num_blocks (`int`, *optional*, defaults to 1):
Number of blocks within the Cross Stage Partial (CSP) layer.
"""

model_type = "slanet"

sub_configs = {"backbone_config": AutoConfig}
post_conv_out_channels: int = 96
out_channels: int = 50
hidden_size: int = 256
max_text_length: int = 500
backbone_config: dict | PreTrainedConfig | None = None

hidden_act: str = "hardswish"
csp_kernel_size: int = 5
csp_num_blocks: int = 1

def __post_init__(self, **kwargs):
self.backbone_config, kwargs = consolidate_backbone_kwargs_to_config(
backbone_config=self.backbone_config,
default_config_type="pp_lcnet",
default_config_kwargs={
"scale": 1,
"out_features": ["stage2", "stage3", "stage4", "stage5"],
"out_indices": [2, 3, 4, 5],
"divisor": 16,
},
**kwargs,
)
super().__post_init__(**kwargs)


__all__ = ["SLANetConfig"]
Loading
Loading