Transformers documentation

PPLCNetV3

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

该模型于 2021-09-17 在 HF papers 上发布,并于 2026-03-13 贡献给 Hugging Face Transformers。

PPLCNetV3

PPLCNetV3 是一种轻量级、针对 CPU 优化的卷积骨干网络,旨在高效地执行图像分类及下游视觉任务。它在 PP-LCNet 架构的基础上,通过改进的训练策略和结构优化,在 CPU 硬件上实现了更优的精度与延迟平衡。

备注

  • PPLCNetV3 仅作为骨干网络提供。官方尚未发布任何预训练图像分类检查点。

PPLCNetV3Config

class transformers.PPLCNetV3Config

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonescale: float | int = 1.0block_configs: list | None = Nonestem_channels: int = 16stem_stride: int = 2reduction: int = 4divisor: int = 8hidden_act: str = 'hardswish'_out_features: list[str] | None = None_out_indices: list[int] | None = Noneconv_symmetric_num: int = 4 )

参数

  • scale (float,可选,默认为 1.0) — 用于调整模型通道维度的缩放因子,可在不改变整体架构的情况下调整模型大小和计算成本(例如 0.25、0.5、1.0、1.5)。
  • block_configs (list[list[tuple]],可选,默认为 None) — 每个阶段中每个块的配置。每个元组包含: (kernel_size, in_channels, out_channels, stride, use_squeeze_excitation)。 如果为 None,则使用默认的 PP-LCNet 配置。
  • stem_channels (int,可选,默认为 16) — stem 层的输出通道数。
  • stem_stride (int,可选,默认为 2) — Stem 卷积层的步长。
  • reduction (int,可选,默认为 4) — 在 squeeze-and-excitation (SE) 块中用于特征通道维度的缩减因子,用于在保持特征表示能力的同时减少模型参数量和计算复杂度。
  • divisor (int, 可选,默认为 8) — 用于确保各种模型参数(例如通道维度、卷积核大小)均为该值的倍数,从而促进高效的模型实现和资源利用。
  • hidden_act (str,可选,默认为 hardswish) — 解码器中的非线性激活函数(函数或字符串)。例如,"gelu"、 "relu"、"silu" 等。
  • conv_symmetric_num (int, 可选,默认为 4) — 可学习重参数化层中 kxk 卷积分支的数量。该参数用于在训练阶段通过多分支架构增强特征提取能力,同时通过结构重参数化实现高效的推理。

这是用于存储 Pp Lcnet V3Model 配置的类。它根据指定的参数实例化 Pp Lcnet V3 模型,并定义模型架构。使用默认值实例化配置将得到与 PaddlePaddle/Not_yet_released 类似的配置。

配置对象继承自 PreTrainedConfig,可用于控制模型输出。有关更多信息,请参阅 PreTrainedConfig 的文档。

PPLCNetV3Backbone

class transformers.PPLCNetV3Backbone

< >

( config: PPLCNetV3Config )

参数

  • config (PPLCNetV3Config) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

用于特征提取的 PPLCNetV3 骨干模型。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensor**kwargs: *<class 'transformers.utils.generic.TransformersKwargs'> ) → BackboneOutput or tuple(torch.Tensor)

参数

  • pixel_values(形状为 (batch_size, num_channels, image_size, image_size) 的 torch.Tensor)— 对应于输入图像的张量。可以使用 image_processor_class 获取像素值。有关详细信息,请参阅 image_processor_class.__call__(processor_class 使用 image_processor_class 来处理图像)。

返回值

BackboneOutput 或 tuple(torch.Tensor)

BackboneOutput 或 torch.Tensor 元组(如果传入 return_dict=False 或 config.return_dict=False),其包含的元素取决于配置(PPLCNetV3Config)和输入。

PPLCNetV3Backbone 的 forward 方法重写了 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

  • feature_maps(形状为 (batch_size, num_channels, height, width) 的 tuple(torch.Tensor))— 各阶段的特征图。

  • hidden_states (tuple(torch.Tensor),可选,在传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — 一个 torch.Tensor 元组(包含嵌入层的输出以及每一层的输出),形状为 (batch_size, sequence_length, hidden_size) 或 (batch_size, num_channels, height, width),具体取决于骨干网络。

    模型在每个阶段输出处的隐藏状态,以及初始嵌入输出。

  • attentions (tuple(torch.Tensor),可选,当传入 output_attentions=True 或 config.output_attentions=True 时返回) — 一个 torch.Tensor 元组(每层一个),形状为 (batch_size, num_heads, sequence_length, sequence_length)。仅当主干网络使用注意力机制时适用。

    注意力权重,即经过注意力 softmax 之后的权重,用于在自注意力头中计算加权平均值。

示例:

>>> from transformers import PPLCNetV3Config, PPLCNetV3Backbone
>>> import torch

>>> config = PPLCNetV3Config()
>>> model = PPLCNetV3Backbone(config)

>>> pixel_values = torch.randn(1, 3, 224, 224)

>>> with torch.no_grad():
...     outputs = model(pixel_values)

>>> feature_maps = outputs.feature_maps
>>> list(feature_maps[-1].shape)
Update on GitHub