Transformers 4.37 中文文档(六十九)(1)https://developer.aliyun.com/article/1564101
MaskFormerModel
class transformers.MaskFormerModel
( config: MaskFormerConfig )
参数
config
(MaskFormerConfig)- 具有模型所有参数的模型配置类。使用配置文件初始化不会加载与模型相关的权重,只加载配置。查看 from_pretrained()方法以加载模型权重。
裸的 MaskFormer 模型输出原始隐藏状态,没有特定的头部。此模型是 PyTorch torch.nn.Module子类。将其用作常规 PyTorch 模块,并参考 PyTorch 文档以获取有关一般用法和行为的所有相关信息。
forward
( pixel_values: Tensor pixel_mask: Optional = None output_hidden_states: Optional = None output_attentions: Optional = None return_dict: Optional = None ) → export const metadata = 'undefined';transformers.models.maskformer.modeling_maskformer.MaskFormerModelOutput or tuple(torch.FloatTensor)
参数
pixel_values
(形状为(batch_size, num_channels, height, width)
的torch.FloatTensor
)- 像素值。可以使用 AutoImageProcessor 获取像素值。有关详细信息,请参阅 MaskFormerImageProcessor.call
()。pixel_mask
(形状为(batch_size, height, width)
的torch.LongTensor
,可选)- 避免在填充像素值上执行注意力的掩码。选择的掩码值在[0, 1]
范围内:
- 1 表示真实像素(即
未遮罩
), - 0 表示填充像素(即
已遮罩
)。
- 注意力掩码是什么?
output_hidden_states
(bool
,可选)- 是否返回所有层的隐藏状态。有关更多详细信息,请查看返回张量下的hidden_states
。output_attentions
(bool
,可选)- 是否返回 Detr 解码器注意力层的注意力张量。return_dict
(bool
,可选)- 是否返回~MaskFormerModelOutput
而不是普通元组。
返回
transformers.models.maskformer.modeling_maskformer.MaskFormerModelOutput 或tuple(torch.FloatTensor)
transformers.models.maskformer.modeling_maskformer.MaskFormerModelOutput 或torch.FloatTensor
元组(如果传递了return_dict=False
或config.return_dict=False
时)包含根据配置(MaskFormerConfig)和输入的各种元素。
encoder_last_hidden_state
(torch.FloatTensor
of shape(batch_size, num_channels, height, width)
) — 编码器模型(骨干)最后阶段的隐藏状态(最终特征图)。pixel_decoder_last_hidden_state
(torch.FloatTensor
of shape(batch_size, num_channels, height, width)
) — 像素解码器模型(FPN)最后阶段的隐藏状态(最终特征图)。transformer_decoder_last_hidden_state
(torch.FloatTensor
of shape(batch_size, sequence_length, hidden_size)
) — 变压器解码器模型最后阶段的隐藏状态(最终特征图)。encoder_hidden_states
(tuple(torch.FloatTensor)
,可选,当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 形状为(batch_size, num_channels, height, width)
的torch.FloatTensor
元组。编码器模型在每个阶段输出的隐藏状态(也称为特征图)。pixel_decoder_hidden_states
(tuple(torch.FloatTensor)
,可选,当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 形状为(batch_size, num_channels, height, width)
的torch.FloatTensor
元组。像素解码器模型在每个阶段输出的隐藏状态(也称为特征图)。transformer_decoder_hidden_states
(tuple(torch.FloatTensor)
,可选,当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 形状为(batch_size, sequence_length, hidden_size)
的torch.FloatTensor
元组。变压器解码器在每个阶段输出的隐藏状态(也称为特征图)。hidden_states
tuple(torch.FloatTensor)
,可选,当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 包含encoder_hidden_states
、pixel_decoder_hidden_states
和decoder_hidden_states
的torch.FloatTensor
元组attentions
(tuple(torch.FloatTensor)
,可选,当传递output_attentions=True
或config.output_attentions=True
时返回) — 包含每个层的torch.FloatTensor
元组,形状为(batch_size, num_heads, sequence_length, sequence_length)
。Detr 解码器在注意力 softmax 之后的注意力权重,用于计算自注意力头中的加权平均值。
MaskFormerModel 的前向方法,覆盖了__call__
特殊方法。
虽然前向传递的方法需要在此函数内定义,但应该在此之后调用Module
实例,而不是在此处调用,因为前者会处理运行前处理和后处理步骤,而后者会默默地忽略它们。
示例:
>>> from transformers import AutoImageProcessor, MaskFormerModel >>> from PIL import Image >>> import requests >>> # load MaskFormer fine-tuned on ADE20k semantic segmentation >>> image_processor = AutoImageProcessor.from_pretrained("facebook/maskformer-swin-base-ade") >>> model = MaskFormerModel.from_pretrained("facebook/maskformer-swin-base-ade") >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" >>> image = Image.open(requests.get(url, stream=True).raw) >>> inputs = image_processor(image, return_tensors="pt") >>> # forward pass >>> outputs = model(**inputs) >>> # the decoder of MaskFormer outputs hidden states of shape (batch_size, num_queries, hidden_size) >>> transformer_decoder_last_hidden_state = outputs.transformer_decoder_last_hidden_state >>> list(transformer_decoder_last_hidden_state.shape) [1, 100, 256]
MaskFormerForInstanceSegmentation
class transformers.MaskFormerForInstanceSegmentation
( config: MaskFormerConfig )
forward
( pixel_values: Tensor mask_labels: Optional = None class_labels: Optional = None pixel_mask: Optional = None output_auxiliary_logits: Optional = None output_hidden_states: Optional = None output_attentions: Optional = None return_dict: Optional = None ) → export const metadata = 'undefined';transformers.models.maskformer.modeling_maskformer.MaskFormerForInstanceSegmentationOutput or tuple(torch.FloatTensor)
参数
pixel_values
(torch.FloatTensor
of shape(batch_size, num_channels, height, width)
) — 像素值。像素值可以使用 AutoImageProcessor 获得。有关详细信息,请参阅 MaskFormerImageProcessor.call
()。pixel_mask
(torch.LongTensor
of shape(batch_size, height, width)
,可选) — 用于避免在填充像素值上执行注意力的掩码。掩码值选在[0, 1]
之间:
- 1 代表真实像素(即
未被遮蔽
), - 对于填充像素为 0(即
masked
)。
- 什么是注意力掩码?
output_hidden_states
(bool
, 可选) — 是否返回所有层的隐藏状态。有关更多详细信息,请查看返回张量下的hidden_states
。output_attentions
(bool
, 可选) — 是否返回 Detr 解码器注意力层的注意力张量。return_dict
(bool
, 可选) — 是否返回~MaskFormerModelOutput
而不是普通元组。mask_labels
(List[torch.Tensor]
, 可选) — 形状为(num_labels, height, width)
的掩码标签列表,用于馈送给模型。class_labels
(List[torch.LongTensor]
, 可选) — 形状为(num_labels, height, width)
的目标类标签列表,用于馈送给模型。它们标识mask_labels
的标签,例如class_labels[i][j]
的标签是mask_labels[i][j]
的标签。
返回
transformers.models.maskformer.modeling_maskformer.MaskFormerForInstanceSegmentationOutput 或tuple(torch.FloatTensor)
一个 transformers.models.maskformer.modeling_maskformer.MaskFormerForInstanceSegmentationOutput 或一个torch.FloatTensor
元组(如果传递return_dict=False
或config.return_dict=False
)包含根据配置(MaskFormerConfig)和输入的各种元素。
loss
(torch.Tensor
, 可选) — 计算的损失,在存在标签时返回。class_queries_logits
(torch.FloatTensor
) — 形状为(batch_size, num_queries, num_labels + 1)
的张量,表示每个查询的提议类别。注意+ 1
是因为我们包含了空类。masks_queries_logits
(torch.FloatTensor
) — 形状为(batch_size, num_queries, height, width)
的张量,表示每个查询的提议掩码。encoder_last_hidden_state
(torch.FloatTensor
of shape(batch_size, num_channels, height, width)
) — 编码器模型(骨干)最后一个阶段的最后隐藏状态(最终特征图)。pixel_decoder_last_hidden_state
(torch.FloatTensor
of shape(batch_size, num_channels, height, width)
) — 最后一个阶段像素解码器模型(FPN)的最后隐藏状态(最终特征图)。transformer_decoder_last_hidden_state
(torch.FloatTensor
of shape(batch_size, sequence_length, hidden_size)
) — 变压器解码器模型最后一个阶段的最后隐藏状态(最终特征图)。encoder_hidden_states
(tuple(torch.FloatTensor)
, 可选, 当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 形状为(batch_size, num_channels, height, width)
的torch.FloatTensor
元组。编码器模型在每个阶段输出的隐藏状态(也称为特征图)。pixel_decoder_hidden_states
(tuple(torch.FloatTensor)
, 可选, 当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 形状为(batch_size, num_channels, height, width)
的torch.FloatTensor
元组。像素解码器模型在每个阶段输出的隐藏状态(也称为特征图)。transformer_decoder_hidden_states
(tuple(torch.FloatTensor)
, 可选, 当传递output_hidden_states=True
或config.output_hidden_states=True
时返回) — 形状为(batch_size, sequence_length, hidden_size)
的torch.FloatTensor
元组。变压器解码器在每个阶段输出的隐藏状态。hidden_states
tuple(torch.FloatTensor)
, optional, returned whenoutput_hidden_states=True
is passed or whenconfig.output_hidden_states=True
) — Tuple oftorch.FloatTensor
containingencoder_hidden_states
,pixel_decoder_hidden_states
anddecoder_hidden_states
.attentions
(tuple(torch.FloatTensor)
, optional, returned whenoutput_attentions=True
is passed or whenconfig.output_attentions=True
) — Tuple oftorch.FloatTensor
(one for each layer) of shape(batch_size, num_heads, sequence_length, sequence_length)
. Attentions weights from Detr’s decoder after the attention softmax, used to compute the weighted average in the self-attention heads.
MaskFormerForInstanceSegmentation 的前向方法,覆盖了__call__
特殊方法。
尽管前向传递的配方需要在此函数内定义,但应该在此之后调用Module
实例,而不是这个,因为前者负责运行预处理和后处理步骤,而后者则默默地忽略它们。
示例:
语义分割示例:
>>> from transformers import AutoImageProcessor, MaskFormerForInstanceSegmentation >>> from PIL import Image >>> import requests >>> # load MaskFormer fine-tuned on ADE20k semantic segmentation >>> image_processor = AutoImageProcessor.from_pretrained("facebook/maskformer-swin-base-ade") >>> model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-base-ade") >>> url = ( ... "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg" ... ) >>> image = Image.open(requests.get(url, stream=True).raw) >>> inputs = image_processor(images=image, return_tensors="pt") >>> outputs = model(**inputs) >>> # model predicts class_queries_logits of shape `(batch_size, num_queries)` >>> # and masks_queries_logits of shape `(batch_size, num_queries, height, width)` >>> class_queries_logits = outputs.class_queries_logits >>> masks_queries_logits = outputs.masks_queries_logits >>> # you can pass them to image_processor for postprocessing >>> predicted_semantic_map = image_processor.post_process_semantic_segmentation( ... outputs, target_sizes=[image.size[::-1]] ... )[0] >>> # we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs) >>> list(predicted_semantic_map.shape) [512, 683]
全景分割示例:
>>> from transformers import AutoImageProcessor, MaskFormerForInstanceSegmentation >>> from PIL import Image >>> import requests >>> # load MaskFormer fine-tuned on COCO panoptic segmentation >>> image_processor = AutoImageProcessor.from_pretrained("facebook/maskformer-swin-base-coco") >>> model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-base-coco") >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg" >>> image = Image.open(requests.get(url, stream=True).raw) >>> inputs = image_processor(images=image, return_tensors="pt") >>> outputs = model(**inputs) >>> # model predicts class_queries_logits of shape `(batch_size, num_queries)` >>> # and masks_queries_logits of shape `(batch_size, num_queries, height, width)` >>> class_queries_logits = outputs.class_queries_logits >>> masks_queries_logits = outputs.masks_queries_logits >>> # you can pass them to image_processor for postprocessing >>> result = image_processor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0] >>> # we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs) >>> predicted_panoptic_map = result["segmentation"] >>> list(predicted_panoptic_map.shape) [480, 640]
MobileNet V1
原文链接:
huggingface.co/docs/transformers/v4.37.2/en/model_doc/mobilenet_v1
概述
MobileNet 模型是由 Andrew G. Howard, Menglong Zhu, Bo Chen, Dmitry Kalenichenko, Weijun Wang, Tobias Weyand, Marco Andreetto, Hartwig Adam 在MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications中提出的。
论文摘要如下:
我们提出了一类称为 MobileNets 的高效模型,用于移动和嵌入式视觉应用。MobileNets 基于一种简化的架构,使用深度可分离卷积来构建轻量级深度神经网络。我们引入了两个简单的全局超参数,有效地在延迟和准确性之间进行权衡。这些超参数允许模型构建者根据问题的约束选择适合其应用的正确大小的模型。我们进行了大量的资源和准确性权衡实验,并展示了与 ImageNet 分类中其他流行模型相比的强大性能。然后,我们展示了 MobileNets 在广泛的应用和用例中的有效性,包括目标检测、细粒度分类、面部属性和大规模地理定位。
此模型由matthijs贡献。原始代码和权重可以在此处找到。
使用提示
- 检查点的命名为mobilenet_v1_depth_size,例如mobilenet_v1_1.0_224,其中1.0是深度乘数(有时也称为“alpha”或宽度乘数),224是模型训练的输入图像的分辨率。
- 尽管检查点是在特定大小的图像上训练的,但模型将适用于任何大小的图像。支持的最小图像大小为 32x32。
- 可以使用 MobileNetV1ImageProcessor 来为模型准备图像。
- 可用的图像分类检查点是在ImageNet-1k上预训练的(也称为 ILSVRC 2012,包含 130 万张图像和 1000 个类)。但是,该模型预测 1001 个类别:来自 ImageNet 的 1000 个类别加上额外的“背景”类(索引 0)。
- 原始的 TensorFlow 检查点使用不同的填充规则比 PyTorch,需要模型在推断时确定填充量,因为这取决于输入图像的大小。要使用本机 PyTorch 填充行为,请创建一个 MobileNetV1Config,其中
tf_padding = False
。
不支持的功能:
- MobileNetV1Model 输出最后隐藏状态的全局池化版本。在原始模型中,可以使用带有步幅 2 的 7x7 平均池化层,而不是全局池化。对于较大的输入,这会产生一个大于 1x1 像素的池化输出。HuggingFace 的实现不支持这一点。
- 目前无法指定
output_stride
。对于较小的输出步幅,原始模型调用扩张卷积以防止空间分辨率进一步降低。HuggingFace 模型的输出步幅始终为 32。 - 原始的 TensorFlow 检查点包括量化模型。我们不支持这些模型,因为它们包括额外的“FakeQuantization”操作来取消量化权重。
- 通常会从逐点层的输出中提取索引为 5、11、12、13 的输出以供下游使用。使用
output_hidden_states=True
返回所有中间层的输出。目前没有办法将其限制在特定层。
资源
一个官方的 Hugging Face 和社区资源列表(由 🌎 表示),帮助您开始使用 MobileNetV1。
图像分类
如果您有兴趣提交资源以包含在此处,请随时打开一个 Pull Request,我们将进行审核!资源应该展示一些新内容,而不是重复现有资源。
MobileNetV1Config
class transformers.MobileNetV1Config
( num_channels = 3 image_size = 224 depth_multiplier = 1.0 min_depth = 8 hidden_act = 'relu6' tf_padding = True classifier_dropout_prob = 0.999 initializer_range = 0.02 layer_norm_eps = 0.001 **kwargs )
参数
num_channels
(int
, optional, defaults to 3) — 输入通道的数量。image_size
(int
, optional, defaults to 224) — 每个图像的大小(分辨率)。depth_multiplier
(float
, optional, defaults to 1.0) — 收缩或扩展每一层中的通道数量。默认值为 1.0,从 32 个通道开始网络。有时也称为“alpha”或“宽度倍增器”。min_depth
(int
, optional, defaults to 8) — 所有层至少具有这么多通道。hidden_act
(str
orfunction
, optional, defaults to"relu6"
) — Transformer 编码器和卷积层中的非线性激活函数(函数或字符串)。tf_padding
(bool
, optional, defaults toTrue
) — 是否在卷积层上使用 TensorFlow 填充规则。classifier_dropout_prob
(float
, optional, defaults to 0.999) — 附加分类器的丢失比例。initializer_range
(float
, optional, defaults to 0.02) — 用于初始化所有权重矩阵的截断正态分布初始化器的标准差。layer_norm_eps
(float
, optional, defaults to 0.001) — 层归一化层使用的 epsilon。
这是用于存储 MobileNetV1Model 配置的配置类。根据指定的参数实例化一个 MobileNetV1 模型,定义模型架构。使用默认值实例化配置将产生类似于 MobileNetV1 google/mobilenet_v1_1.0_224 架构的配置。
配置对象继承自 PretrainedConfig,可用于控制模型输出。阅读来自 PretrainedConfig 的文档以获取更多信息。
示例:
>>> from transformers import MobileNetV1Config, MobileNetV1Model >>> # Initializing a "mobilenet_v1_1.0_224" style configuration >>> configuration = MobileNetV1Config() >>> # Initializing a model from the "mobilenet_v1_1.0_224" style configuration >>> model = MobileNetV1Model(configuration) >>> # Accessing the model configuration >>> configuration = model.config
MobileNetV1FeatureExtractor
class transformers.MobileNetV1FeatureExtractor
( *args **kwargs )
preprocess
( images: Union do_resize: Optional = None size: Dict = None resample: Resampling = None do_center_crop: bool = None crop_size: Dict = None do_rescale: Optional = None rescale_factor: Optional = None do_normalize: Optional = None image_mean: Union = None image_std: Union = None return_tensors: Union = None data_format: Union = <ChannelDimension.FIRST: 'channels_first'> input_data_format: Union = None **kwargs )
参数
images
(ImageInput
) — 要预处理的图像。期望单个或批量图像,像素值范围从 0 到 255。如果传入像素值在 0 到 1 之间的图像,请设置do_rescale=False
。do_resize
(bool
,可选,默认为self.do_resize
) — 是否调整图像大小。size
(Dict[str, int]
,可选,默认为self.size
) — 调整大小后的图像尺寸。图像的最短边被调整为 size[“shortest_edge”],最长边被调整以保持输入的长宽比。resample
(PILImageResampling
过滤器,可选,默认为self.resample
) — 如果调整图像大小,则使用的PILImageResampling
过滤器,例如PILImageResampling.BILINEAR
。仅在do_resize
设置为True
时有效。do_center_crop
(bool
,可选,默认为self.do_center_crop
) — 是否对图像进行中心裁剪。crop_size
(Dict[str, int]
,可选,默认为self.crop_size
) — 中心裁剪的尺寸。仅在do_center_crop
设置为True
时有效。do_rescale
(bool
,可选,默认为self.do_rescale
) — 是否将图像值重新缩放到[0 - 1]之间。rescale_factor
(float
,可选,默认为self.rescale_factor
) — 如果do_rescale
设置为True
,要按照此因子重新缩放图像。do_normalize
(bool
,可选,默认为self.do_normalize
) — 是否对图像进行归一化。image_mean
(float
或List[float]
,可选,默认为self.image_mean
) — 如果do_normalize
设置为True
,要使用的图像均值。image_std
(float
或List[float]
,可选,默认为self.image_std
) — 如果do_normalize
设置为True
,要使用的图像标准差。return_tensors
(str
或TensorType
,可选) — 要返回的张量类型。可以是以下之一:
- 未设置:返回一个
np.ndarray
列表。 TensorType.TENSORFLOW
或'tf'
:返回一个类型为tf.Tensor
的批处理。TensorType.PYTORCH
或'pt'
:返回一个类型为torch.Tensor
的批处理。TensorType.NUMPY
或'np'
:返回一个类型为np.ndarray
的批处理。TensorType.JAX
或'jax'
:返回一个类型为jax.numpy.ndarray
的批处理。
data_format
(ChannelDimension
或str
,可选,默认为ChannelDimension.FIRST
) — 输出图像的通道维度格式。可以是以下之一:
"channels_first"
或ChannelDimension.FIRST
:图像以(num_channels, height, width)格式。"channels_last"
或ChannelDimension.LAST
:图像以(height, width, num_channels)格式。- 未设置:使用输入图像的通道维度格式。
input_data_format
(ChannelDimension
或str
,可选) — 输入图像的通道维度格式。如果未设置,将从输入图像中推断通道维度格式。可以是以下之一:
"channels_first"
或ChannelDimension.FIRST
:图像以(num_channels, height, width)格式。"channels_last"
或ChannelDimension.LAST
:图像以(height, width, num_channels)格式。"none"
或ChannelDimension.NONE
:图像以(height, width)格式。
对图像或图像批处理进行预处理。
MobileNetV1ImageProcessor
class transformers.MobileNetV1ImageProcessor
( do_resize: bool = True size: Optional = None resample: Resampling = <Resampling.BILINEAR: 2> do_center_crop: bool = True crop_size: Dict = None do_rescale: bool = True rescale_factor: Union = 0.00392156862745098 do_normalize: bool = True image_mean: Union = None image_std: Union = None **kwargs )
参数
do_resize
(bool
,可选,默认为True
) — 是否将图像的(高度,宽度)维度调整为指定的size
。可以被preprocess
方法中的do_resize
覆盖。size
(Dict[str, int]
可选,默认为{"shortest_edge" -- 256}
):调整大小后的图像尺寸。图像的最短边被调整为 size[“shortest_edge”],最长边被调整以保持输入的长宽比。可以被preprocess
方法中的size
覆盖。resample
(PILImageResampling
,可选,默认为PILImageResampling.BILINEAR
) — 如果调整图像大小,则使用的重采样滤波器。可以被preprocess
方法中的resample
参数覆盖。do_center_crop
(bool
,可选,默认为True
) — 是否对图像进行中心裁剪。如果输入尺寸小于任何边沿的crop_size
,则图像将填充为 0,然后进行中心裁剪。可以被preprocess
方法中的do_center_crop
参数覆盖。crop_size
(Dict[str, int]
,可选,默认为{"height" -- 224, "width": 224}
):应用中心裁剪时的期望输出大小。仅在do_center_crop
设置为True
时有效。可以被preprocess
方法中的crop_size
参数覆盖。do_rescale
(bool
,可选,默认为True
) — 是否按指定比例rescale_factor
重新缩放图像。可以被preprocess
方法中的do_rescale
参数覆盖。rescale_factor
(int
或float
,可选,默认为1/255
) — 如果重新缩放图像,则使用的缩放因子。可以被preprocess
方法中的rescale_factor
参数覆盖。do_normalize — 是否对图像进行归一化。可以被preprocess
方法中的do_normalize
参数覆盖。image_mean
(float
或List[float]
,可选,默认为IMAGENET_STANDARD_MEAN
) — 如果对图像进行归一化,则使用的均值。这是一个浮点数或与图像通道数相同长度的浮点数列表。可以被preprocess
方法中的image_mean
参数覆盖。image_std
(float
或List[float]
,可选,默认为IMAGENET_STANDARD_STD
) — 如果对图像进行归一化,则使用的标准差。这是一个浮点数或与图像通道数相同长度的浮点数列表。可以被preprocess
方法中的image_std
参数覆盖。
构建一个 MobileNetV1 图像处理器。
preprocess
( images: Union do_resize: Optional = None size: Dict = None resample: Resampling = None do_center_crop: bool = None crop_size: Dict = None do_rescale: Optional = None rescale_factor: Optional = None do_normalize: Optional = None image_mean: Union = None image_std: Union = None return_tensors: Union = None data_format: Union = <ChannelDimension.FIRST: 'channels_first'> input_data_format: Union = None **kwargs )
参数
images
(ImageInput
) — 需要预处理的图像。期望单个或批量图像,像素值范围为 0 到 255。如果传入像素值在 0 到 1 之间的图像,请设置do_rescale=False
。do_resize
(bool
,可选,默认为self.do_resize
) — 是否调整图像大小。size
(Dict[str, int]
,可选,默认为self.size
) — 调整大小后的图像尺寸。图像的最短边被调整为 size[“shortest_edge”],最长边被调整以保持输入的长宽比。resample
(PILImageResampling
过滤器,可选,默认为self.resample
) — 调整图像大小时使用的PILImageResampling
过滤器,例如PILImageResampling.BILINEAR
。仅在do_resize
设置为True
时有效。do_center_crop
(bool
,可选,默认为self.do_center_crop
) — 是否对图像进行中心裁剪。crop_size
(Dict[str, int]
,可选,默认为self.crop_size
) — 中心裁剪的大小。仅在do_center_crop
设置为True
时有效。do_rescale
(bool
,可选,默认为self.do_rescale
) — 是否将图像值重新缩放在[0-1]之间。rescale_factor
(float
,可选,默认为self.rescale_factor
) — 如果do_rescale
设置为True
,则用于重新缩放图像的缩放因子。do_normalize
(bool
,可选,默认为self.do_normalize
) — 是否对图像进行归一化。image_mean
(float
或List[float]
,可选,默认为self.image_mean
) — 如果do_normalize
设置为True
,则使用的图像均值。image_std
(float
或List[float]
,可选,默认为self.image_std
) — 如果do_normalize
设置为True
,则使用的图像标准差。return_tensors
(str
或TensorType
,可选) — 要返回的张量类型。可以是以下之一:
- 未设置:返回
np.ndarray
列表。 TensorType.TENSORFLOW
或'tf'
:返回类型为tf.Tensor
的批量。TensorType.PYTORCH
或'pt'
:返回类型为torch.Tensor
的批量。TensorType.NUMPY
或'np'
:返回类型为np.ndarray
的批量。TensorType.JAX
或'jax'
:返回类型为jax.numpy.ndarray
的批量。
data_format
(ChannelDimension
或str
,optional,默认为ChannelDimension.FIRST
) — 输出图像的通道维度格式。可以是以下之一:
"channels_first"
或ChannelDimension.FIRST
:图像以(num_channels, height, width)格式。"channels_last"
或ChannelDimension.LAST
:图像以(height, width, num_channels)格式。- 未设置:使用输入图像的通道维度格式。
input_data_format
(ChannelDimension
或str
,optional) — 输入图像的通道维度格式。如果未设置,则从输入图像中推断通道维度格式。可以是以下之一:
"channels_first"
或ChannelDimension.FIRST
:图像以(num_channels, height, width)格式。"channels_last"
或ChannelDimension.LAST
:图像以(height, width, num_channels)格式。"none"
或ChannelDimension.NONE
:图像以(height, width)格式。
预处理图像或一批图像。
Transformers 4.37 中文文档(六十九)(3)https://developer.aliyun.com/article/1564103