text stringlengths 31 243k | type stringclasses 1
value | start int64 36 275k | end int64 286 280k | depth int64 0 1 | filepath stringlengths 85 188 | parent_class stringclasses 3
values | class_index int64 0 10.8k |
|---|---|---|---|---|---|---|---|
class DeformableDetrMultiscaleDeformableAttention(nn.Module):
"""
Multiscale deformable attention as proposed in Deformable DETR.
"""
def __init__(self, config: DeformableDetrConfig, num_heads: int, n_points: int):
super().__init__()
kernel_loaded = MultiScaleDeformableAttention is not... | class_definition | 30,904 | 36,593 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,800 |
class DeformableDetrMultiheadAttention(nn.Module):
"""
Multi-headed attention from 'Attention Is All You Need' paper.
Here, we add position embeddings to the queries and keys (as explained in the Deformable DETR paper).
"""
def __init__(
self,
embed_dim: int,
num_heads: int... | class_definition | 36,596 | 41,901 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,801 |
class DeformableDetrEncoderLayer(nn.Module):
def __init__(self, config: DeformableDetrConfig):
super().__init__()
self.embed_dim = config.d_model
self.self_attn = DeformableDetrMultiscaleDeformableAttention(
config, num_heads=config.encoder_attention_heads, n_points=config.encode... | class_definition | 41,904 | 45,736 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,802 |
class DeformableDetrDecoderLayer(nn.Module):
def __init__(self, config: DeformableDetrConfig):
super().__init__()
self.embed_dim = config.d_model
# self-attention
self.self_attn = DeformableDetrMultiheadAttention(
embed_dim=self.embed_dim,
num_heads=config.de... | class_definition | 45,739 | 50,591 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,803 |
class DeformableDetrPreTrainedModel(PreTrainedModel):
config_class = DeformableDetrConfig
base_model_prefix = "model"
main_input_name = "pixel_values"
supports_gradient_checkpointing = True
_no_split_modules = [r"DeformableDetrConvEncoder", r"DeformableDetrEncoderLayer", r"DeformableDetrDecoderLayer... | class_definition | 50,594 | 53,355 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,804 |
class DeformableDetrEncoder(DeformableDetrPreTrainedModel):
"""
Transformer encoder consisting of *config.encoder_layers* deformable attention layers. Each layer is a
[`DeformableDetrEncoderLayer`].
The encoder updates the flattened multi-scale feature maps through multiple deformable attention layers.... | class_definition | 56,724 | 63,800 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,805 |
class DeformableDetrDecoder(DeformableDetrPreTrainedModel):
"""
Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`DeformableDetrDecoderLayer`].
The decoder updates the query embeddings through multiple self-attention and cross-attention layers.
Some tweaks for Deforma... | class_definition | 63,803 | 72,767 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,806 |
class DeformableDetrModel(DeformableDetrPreTrainedModel):
def __init__(self, config: DeformableDetrConfig):
super().__init__(config)
# Create backbone + positional encoding
backbone = DeformableDetrConvEncoder(config)
position_embeddings = build_position_encoding(config)
sel... | class_definition | 73,010 | 90,340 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,807 |
class DeformableDetrMLPPredictionHead(nn.Module):
"""
Very simple multi-layer perceptron (MLP, also called FFN), used to predict the normalized center coordinates,
height and width of a bounding box w.r.t. an image.
Copied from https://github.com/facebookresearch/detr/blob/master/models/detr.py
""... | class_definition | 90,418 | 91,201 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,808 |
class DeformableDetrForObjectDetection(DeformableDetrPreTrainedModel):
# When using clones, all layers > 0 will be clones, but layer 0 *is* required
_tied_weights_keys = [r"bbox_embed\.[1-9]\d*", r"class_embed\.[1-9]\d*"]
# We can't initialize the model on meta device as some weights are modified during the... | class_definition | 91,442 | 100,585 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modeling_deformable_detr.py | null | 6,809 |
class DeformableDetrImageProcessor(BaseImageProcessor):
r"""
Constructs a Deformable DETR image processor.
Args:
format (`str`, *optional*, defaults to `"coco_detection"`):
Data format of the annotations. One of "coco_detection" or "coco_panoptic".
do_resize (`bool`, *optional*,... | class_definition | 30,153 | 73,186 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/image_processing_deformable_detr.py | null | 6,810 |
class DeformableDetrImageProcessorFast(DetrImageProcessorFast):
def post_process(self, outputs, target_sizes):
"""
Converts the raw output of [`DeformableDetrForObjectDetection`] into final bounding boxes in (top_left_x,
top_left_y, bottom_right_x, bottom_right_y) format. Only supports PyTor... | class_definition | 348 | 6,536 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/modular_deformable_detr.py | null | 6,811 |
class DeformableDetrConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`DeformableDetrModel`]. It is used to instantiate
a Deformable DETR model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defa... | class_definition | 909 | 14,533 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/configuration_deformable_detr.py | null | 6,812 |
class DeformableDetrImageProcessorFast(BaseImageProcessorFast):
r"""
Constructs a fast DeformableDetr image processor.
Args:
format (`str`, *optional*, defaults to `AnnotationFormat.COCO_DETECTION`):
Data format of the annotations. One of "coco_detection" or "coco_panoptic".
do_... | class_definition | 9,941 | 49,099 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/deformable_detr/image_processing_deformable_detr_fast.py | null | 6,813 |
class AlignVisionModelOutput(ModelOutput):
"""
Base class for vision model's outputs that also contains image embeddings of the pooling of the last hidden states.
Args:
image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_pro... | class_definition | 9,147 | 10,430 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,814 |
class AlignTextModelOutput(ModelOutput):
"""
Base class for text model's outputs that also contains a pooling of the last hidden states.
Args:
text_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_projection=True`):
... | class_definition | 10,444 | 12,190 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,815 |
class AlignOutput(ModelOutput):
"""
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `return_loss` is `True`):
Contrastive loss for image-text similarity.
logits_per_image:(`torch.FloatTensor` of shape `(image_batch_size, text_batch_size)`):
The ... | class_definition | 12,204 | 14,058 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,816 |
class AlignVisionEmbeddings(nn.Module):
r"""
A module that corresponds to the stem module of the original work.
"""
def __init__(self, config: AlignVisionConfig):
super().__init__()
self.out_dim = round_filters(config, 32)
self.padding = nn.ZeroPad2d(padding=(0, 1, 0, 1))
... | class_definition | 16,083 | 16,989 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,817 |
class AlignVisionDepthwiseConv2d(nn.Conv2d):
def __init__(
self,
in_channels,
depth_multiplier=1,
kernel_size=3,
stride=1,
padding=0,
dilation=1,
bias=True,
padding_mode="zeros",
):
out_channels = in_channels * depth_multiplier
... | class_definition | 17,120 | 17,765 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,818 |
class AlignVisionExpansionLayer(nn.Module):
r"""
This corresponds to the expansion phase of each block in the original implementation.
"""
def __init__(self, config: AlignVisionConfig, in_dim: int, out_dim: int, stride: int):
super().__init__()
self.expand_conv = nn.Conv2d(
... | class_definition | 17,895 | 18,790 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,819 |
class AlignVisionDepthwiseLayer(nn.Module):
r"""
This corresponds to the depthwise convolution phase of each block in the original implementation.
"""
def __init__(
self,
config: AlignVisionConfig,
in_dim: int,
stride: int,
kernel_size: int,
adjust_paddin... | class_definition | 18,920 | 20,274 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,820 |
class AlignVisionSqueezeExciteLayer(nn.Module):
r"""
This corresponds to the Squeeze and Excitement phase of each block in the original implementation.
"""
def __init__(self, config: AlignVisionConfig, in_dim: int, expand_dim: int, expand: bool = False):
super().__init__()
self.dim = ex... | class_definition | 20,408 | 21,781 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,821 |
class AlignVisionFinalBlockLayer(nn.Module):
r"""
This corresponds to the final phase of each block in the original implementation.
"""
def __init__(
self, config: AlignVisionConfig, in_dim: int, out_dim: int, stride: int, drop_rate: float, id_skip: bool
):
super().__init__()
... | class_definition | 21,784 | 22,934 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,822 |
class AlignVisionBlock(nn.Module):
r"""
This corresponds to the block module of original the EfficientNet vision encoder implementation.
Args:
config ([`AlignVisionConfig`]):
Model configuration class.
in_dim (`int`):
Number of input channels.
out_dim (`int`)... | class_definition | 22,937 | 25,970 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,823 |
class AlignVisionEncoder(nn.Module):
r"""
Forward propogates the embeddings through each vision encoder (EfficientNet) block.
Args:
config ([`AlignVisionConfig`]):
Model configuration class.
"""
def __init__(self, config: AlignVisionConfig):
super().__init__()
s... | class_definition | 25,973 | 28,697 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,824 |
class AlignTextEmbeddings(nn.Module):
"""Construct the embeddings from word, position and token_type embeddings."""
def __init__(self, config):
super().__init__()
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
self.position_em... | class_definition | 28,789 | 31,967 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,825 |
class AlignTextSelfAttention(nn.Module):
def __init__(self, config, position_embedding_type=None):
super().__init__()
if config.hidden_size % config.num_attention_heads != 0 and not hasattr(config, "embedding_size"):
raise ValueError(
f"The hidden size ({config.hidden_siz... | class_definition | 32,062 | 39,414 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,826 |
class AlignTextSelfOutput(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
... | class_definition | 39,506 | 40,117 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,827 |
class AlignTextAttention(nn.Module):
def __init__(self, config, position_embedding_type=None):
super().__init__()
self.self = ALIGN_TEXT_SELF_ATTENTION_CLASSES[config._attn_implementation](
config, position_embedding_type=position_embedding_type
)
self.output = AlignTextS... | class_definition | 40,304 | 42,442 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,828 |
class AlignTextIntermediate(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.intermediate_size)
if isinstance(config.hidden_act, str):
self.intermediate_act_fn = ACT2FN[config.hidden_act]
else:
self.i... | class_definition | 42,536 | 43,106 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,829 |
class AlignTextOutput(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
... | class_definition | 43,194 | 43,807 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,830 |
class AlignTextLayer(nn.Module):
def __init__(self, config):
super().__init__()
self.chunk_size_feed_forward = config.chunk_size_feed_forward
self.seq_len_dim = 1
self.attention = AlignTextAttention(config)
self.is_decoder = config.is_decoder
self.add_cross_attention ... | class_definition | 43,894 | 47,826 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,831 |
class AlignTextEncoder(nn.Module):
def __init__(self, config):
super().__init__()
self.config = config
self.layer = nn.ModuleList([AlignTextLayer(config) for _ in range(config.num_hidden_layers)])
self.gradient_checkpointing = False
def forward(
self,
hidden_stat... | class_definition | 47,915 | 51,715 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,832 |
class AlignTextPooler(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
self.activation = nn.Tanh()
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
# We "pool" the model by simply taking the ... | class_definition | 51,805 | 52,369 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,833 |
class AlignPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = AlignConfig
base_model_prefix = "align"
supports_gradient_checkpointing = True
def _init_weights(... | class_definition | 52,372 | 53,554 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,834 |
class AlignTextModel(AlignPreTrainedModel):
config_class = AlignTextConfig
_no_split_modules = ["AlignTextEmbeddings"]
def __init__(self, config: AlignTextConfig, add_pooling_layer: bool = True):
super().__init__(config)
self.config = config
self.embeddings = AlignTextEmbeddings(co... | class_definition | 53,685 | 59,148 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,835 |
class AlignVisionModel(AlignPreTrainedModel):
config_class = AlignVisionConfig
main_input_name = "pixel_values"
supports_gradient_checkpointing = False
def __init__(self, config: AlignVisionConfig):
super().__init__(config)
self.config = config
self.embeddings = AlignVisionEmbed... | class_definition | 59,281 | 62,599 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,836 |
class AlignModel(AlignPreTrainedModel):
config_class = AlignConfig
def __init__(self, config: AlignConfig):
super().__init__(config)
if not isinstance(config.text_config, AlignTextConfig):
raise TypeError(
"config.text_config is expected to be of type AlignTextConfi... | class_definition | 62,647 | 71,882 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/modeling_align.py | null | 6,837 |
class AlignTextConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`AlignTextModel`]. It is used to instantiate a
ALIGN text encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yie... | class_definition | 851 | 6,482 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/configuration_align.py | null | 6,838 |
class AlignVisionConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`AlignVisionModel`]. It is used to instantiate a
ALIGN vision encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults wi... | class_definition | 6,485 | 12,670 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/configuration_align.py | null | 6,839 |
class AlignConfig(PretrainedConfig):
r"""
[`AlignConfig`] is the configuration class to store the configuration of a [`AlignModel`]. It is used to
instantiate a ALIGN model according to the specified arguments, defining the text model and vision model configs.
Instantiating a configuration with the defa... | class_definition | 12,673 | 16,469 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/configuration_align.py | null | 6,840 |
class AlignProcessorKwargs(ProcessingKwargs, total=False):
# see processing_utils.ProcessingKwargs documentation for usage.
_defaults = {
"text_kwargs": {
"padding": "max_length",
"max_length": 64,
},
} | class_definition | 914 | 1,168 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/processing_align.py | null | 6,841 |
class AlignProcessor(ProcessorMixin):
r"""
Constructs an ALIGN processor which wraps [`EfficientNetImageProcessor`] and
[`BertTokenizer`]/[`BertTokenizerFast`] into a single processor that interits both the image processor and
tokenizer functionalities. See the [`~AlignProcessor.__call__`] and [`~OwlViT... | class_definition | 1,171 | 7,279 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/align/processing_align.py | null | 6,842 |
class ViTImageProcessor(BaseImageProcessor):
r"""
Constructs a ViT image processor.
Args:
do_resize (`bool`, *optional*, defaults to `True`):
Whether to resize the image's (height, width) dimensions to the specified `(size["height"],
size["width"])`. Can be overridden by the... | class_definition | 1,321 | 14,321 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/image_processing_vit.py | null | 6,843 |
class ViTEmbeddings(nn.Module):
"""
Construct the CLS token, position and patch embeddings. Optionally, also the mask token.
"""
def __init__(self, config: ViTConfig, use_mask_token: bool = False) -> None:
super().__init__()
self.cls_token = nn.Parameter(torch.randn(1, 1, config.hidden... | class_definition | 1,783 | 5,623 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,844 |
class ViTPatchEmbeddings(nn.Module):
"""
This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial
`hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a
Transformer.
"""
def __init__(self, config):
... | class_definition | 5,626 | 7,576 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,845 |
class ViTSelfAttention(nn.Module):
def __init__(self, config: ViTConfig) -> None:
super().__init__()
if config.hidden_size % config.num_attention_heads != 0 and not hasattr(config, "embedding_size"):
raise ValueError(
f"The hidden size {config.hidden_size,} is not a multi... | class_definition | 7,579 | 10,419 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,846 |
class ViTSdpaSelfAttention(ViTSelfAttention):
def __init__(self, config: ViTConfig) -> None:
super().__init__(config)
self.attention_probs_dropout_prob = config.attention_probs_dropout_prob
def forward(
self,
hidden_states: torch.FloatTensor,
head_mask: Optional[torch.Te... | class_definition | 10,422 | 12,460 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,847 |
class ViTSelfOutput(nn.Module):
"""
The residual connection is defined in ViTLayer instead of here (as is the case with other models), due to the
layernorm applied before each block.
"""
def __init__(self, config: ViTConfig) -> None:
super().__init__()
self.dense = nn.Linear(config.... | class_definition | 12,463 | 13,106 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,848 |
class ViTAttention(nn.Module):
def __init__(self, config: ViTConfig) -> None:
super().__init__()
self.attention = ViTSelfAttention(config)
self.output = ViTSelfOutput(config)
self.pruned_heads = set()
def prune_heads(self, heads: Set[int]) -> None:
if len(heads) == 0:
... | class_definition | 13,109 | 14,786 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,849 |
class ViTSdpaAttention(ViTAttention):
def __init__(self, config: ViTConfig) -> None:
super().__init__(config)
self.attention = ViTSdpaSelfAttention(config) | class_definition | 14,789 | 14,964 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,850 |
class ViTIntermediate(nn.Module):
def __init__(self, config: ViTConfig) -> None:
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.intermediate_size)
if isinstance(config.hidden_act, str):
self.intermediate_act_fn = ACT2FN[config.hidden_act]
else:
... | class_definition | 14,967 | 15,551 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,851 |
class ViTOutput(nn.Module):
def __init__(self, config: ViTConfig) -> None:
super().__init__()
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
def forward(self, hidden_states: torch.Tensor, input_tensor: torch.Ten... | class_definition | 15,554 | 16,081 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,852 |
class ViTLayer(nn.Module):
"""This corresponds to the Block class in the timm implementation."""
def __init__(self, config: ViTConfig) -> None:
super().__init__()
self.chunk_size_feed_forward = config.chunk_size_feed_forward
self.seq_len_dim = 1
self.attention = VIT_ATTENTION_CL... | class_definition | 16,171 | 17,885 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,853 |
class ViTEncoder(nn.Module):
def __init__(self, config: ViTConfig) -> None:
super().__init__()
self.config = config
self.layer = nn.ModuleList([ViTLayer(config) for _ in range(config.num_hidden_layers)])
self.gradient_checkpointing = False
def forward(
self,
hidd... | class_definition | 17,888 | 19,809 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,854 |
class ViTPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = ViTConfig
base_model_prefix = "vit"
main_input_name = "pixel_values"
supports_gradient_checkpointing... | class_definition | 19,812 | 21,498 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,855 |
class ViTModel(ViTPreTrainedModel):
def __init__(self, config: ViTConfig, add_pooling_layer: bool = True, use_mask_token: bool = False):
super().__init__(config)
self.config = config
self.embeddings = ViTEmbeddings(config, use_mask_token=use_mask_token)
self.encoder = ViTEncoder(con... | class_definition | 23,522 | 27,753 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,856 |
class ViTPooler(nn.Module):
def __init__(self, config: ViTConfig):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
self.activation = nn.Tanh()
def forward(self, hidden_states):
# We "pool" the model by simply taking the hidden state correspondin... | class_definition | 27,756 | 28,295 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,857 |
class ViTForMaskedImageModeling(ViTPreTrainedModel):
def __init__(self, config: ViTConfig) -> None:
super().__init__(config)
self.vit = ViTModel(config, add_pooling_layer=False, use_mask_token=True)
self.decoder = nn.Sequential(
nn.Conv2d(
in_channels=config.hid... | class_definition | 28,702 | 33,751 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,858 |
class ViTForImageClassification(ViTPreTrainedModel):
def __init__(self, config: ViTConfig) -> None:
super().__init__(config)
self.num_labels = config.num_labels
self.vit = ViTModel(config, add_pooling_layer=False)
# Classifier head
self.classifier = nn.Linear(config.hidden_... | class_definition | 34,296 | 37,976 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_vit.py | null | 6,859 |
class FlaxViTPatchEmbeddings(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
image_size = self.config.image_size
patch_size = self.config.patch_size
num_patches = (image_size // patch_size) * (image_size // patch_size)
... | class_definition | 4,190 | 5,459 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,860 |
class FlaxViTEmbeddings(nn.Module):
"""Construct the CLS token, position and patch embeddings."""
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.cls_token = self.param(
"cls_token",
jax.nn.initializers.variance_sca... | class_definition | 5,462 | 6,873 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,861 |
class FlaxViTSelfAttention(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
if self.config.hidden_size % self.config.num_attention_heads != 0:
raise ValueError(
"`config.hidden_size`: {self.config.hidden_size} ... | class_definition | 6,876 | 9,702 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,862 |
class FlaxViTSelfOutput(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.dense = nn.Dense(
self.config.hidden_size,
kernel_init=jax.nn.initializers.variance_scaling(
self.config.initializer_ran... | class_definition | 9,705 | 10,429 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,863 |
class FlaxViTAttention(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32
def setup(self):
self.attention = FlaxViTSelfAttention(self.config, dtype=self.dtype)
self.output = FlaxViTSelfOutput(self.config, dtype=self.dtype)
def __call__(self, hidden_states, deterministic=True,... | class_definition | 10,432 | 11,169 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,864 |
class FlaxViTIntermediate(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.dense = nn.Dense(
self.config.intermediate_size,
kernel_init=jax.nn.initializers.variance_scaling(
self.config.initial... | class_definition | 11,172 | 11,821 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,865 |
class FlaxViTOutput(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.dense = nn.Dense(
self.config.hidden_size,
kernel_init=jax.nn.initializers.variance_scaling(
self.config.initializer_range**... | class_definition | 11,824 | 12,605 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,866 |
class FlaxViTLayer(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.attention = FlaxViTAttention(self.config, dtype=self.dtype)
self.intermediate = FlaxViTIntermediate(self.config, dtype=self.dtype)
self.output = Flax... | class_definition | 12,608 | 14,080 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,867 |
class FlaxViTLayerCollection(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.layers = [
FlaxViTLayer(self.config, name=str(i), dtype=self.dtype) for i in range(self.config.num_hidden_layers)
]
def __call__(
... | class_definition | 14,083 | 15,477 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,868 |
class FlaxViTEncoder(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.layer = FlaxViTLayerCollection(self.config, dtype=self.dtype)
def __call__(
self,
hidden_states,
deterministic: bool = True,
o... | class_definition | 15,480 | 16,162 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,869 |
class FlaxViTPooler(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
def setup(self):
self.dense = nn.Dense(
self.config.hidden_size,
kernel_init=jax.nn.initializers.variance_scaling(
self.config.initializer_range**... | class_definition | 16,165 | 16,755 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,870 |
class FlaxViTPreTrainedModel(FlaxPreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = ViTConfig
base_model_prefix = "vit"
main_input_name = "pixel_values"
module_class: nn.Module... | class_definition | 16,758 | 19,667 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,871 |
class FlaxViTModule(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32 # the dtype of the computation
add_pooling_layer: bool = True
def setup(self):
self.embeddings = FlaxViTEmbeddings(self.config, dtype=self.dtype)
self.encoder = FlaxViTEncoder(self.config, dtype=self.dtype... | class_definition | 19,670 | 21,356 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,872 |
class FlaxViTModel(FlaxViTPreTrainedModel):
module_class = FlaxViTModule | class_definition | 21,510 | 21,586 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,873 |
class FlaxViTForImageClassificationModule(nn.Module):
config: ViTConfig
dtype: jnp.dtype = jnp.float32
def setup(self):
self.vit = FlaxViTModule(config=self.config, dtype=self.dtype, add_pooling_layer=False)
self.classifier = nn.Dense(
self.config.num_labels,
dtype=s... | class_definition | 22,458 | 23,859 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,874 |
class FlaxViTForImageClassification(FlaxViTPreTrainedModel):
module_class = FlaxViTForImageClassificationModule | class_definition | 24,088 | 24,203 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_flax_vit.py | null | 6,875 |
class TFViTEmbeddings(keras.layers.Layer):
"""
Construct the CLS token, position and patch embeddings.
"""
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.patch_embeddings = TFViTPatchEmbeddings(config, name="patch_embeddings")
self.dropout = k... | class_definition | 1,739 | 5,298 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,876 |
class TFViTPatchEmbeddings(keras.layers.Layer):
"""
This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial
`hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a
Transformer.
"""
def __init__(self, c... | class_definition | 5,456 | 8,701 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,877 |
class TFViTSelfAttention(keras.layers.Layer):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
if config.hidden_size % config.num_attention_heads != 0:
raise ValueError(
f"The hidden size ({config.hidden_size}) is not a multiple of the number "... | class_definition | 8,704 | 13,156 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,878 |
class TFViTSelfOutput(keras.layers.Layer):
"""
The residual connection is defined in TFViTLayer instead of here (as is the case with other models), due to the
layernorm applied before each block.
"""
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.d... | class_definition | 13,159 | 14,290 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,879 |
class TFViTAttention(keras.layers.Layer):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.self_attention = TFViTSelfAttention(config, name="attention")
self.dense_output = TFViTSelfOutput(config, name="output")
def prune_heads(self, heads):
rais... | class_definition | 14,293 | 15,687 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,880 |
class TFViTIntermediate(keras.layers.Layer):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.intermediate_size, kernel_initializer=get_initializer(config.initializer_range), name="dense"
)
if isin... | class_definition | 15,690 | 16,710 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,881 |
class TFViTOutput(keras.layers.Layer):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.hidden_size, kernel_initializer=get_initializer(config.initializer_range), name="dense"
)
self.dropout = keras... | class_definition | 16,713 | 17,725 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,882 |
class TFViTLayer(keras.layers.Layer):
"""This corresponds to the Block class in the timm implementation."""
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.attention = TFViTAttention(config, name="attention")
self.intermediate = TFViTIntermediate(config... | class_definition | 17,728 | 20,539 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,883 |
class TFViTEncoder(keras.layers.Layer):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.layer = [TFViTLayer(config, name=f"layer_._{i}") for i in range(config.num_hidden_layers)]
def call(
self,
hidden_states: tf.Tensor,
head_mask: tf.Te... | class_definition | 20,542 | 22,412 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,884 |
class TFViTMainLayer(keras.layers.Layer):
config_class = ViTConfig
def __init__(self, config: ViTConfig, add_pooling_layer: bool = True, **kwargs):
super().__init__(**kwargs)
self.config = config
self.embeddings = TFViTEmbeddings(config, name="embeddings")
self.encoder = TFViT... | class_definition | 22,435 | 26,188 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,885 |
class TFViTPreTrainedModel(TFPreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = ViTConfig
base_model_prefix = "vit"
main_input_name = "pixel_values" | class_definition | 26,191 | 26,479 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,886 |
class TFViTModel(TFViTPreTrainedModel):
def __init__(self, config: ViTConfig, *inputs, add_pooling_layer=True, **kwargs):
super().__init__(config, *inputs, **kwargs)
self.vit = TFViTMainLayer(config, add_pooling_layer=add_pooling_layer, name="vit")
@unpack_inputs
@add_start_docstrings_to_m... | class_definition | 31,042 | 32,689 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,887 |
class TFViTPooler(keras.layers.Layer):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.hidden_size,
kernel_initializer=get_initializer(config.initializer_range),
activation="tanh",
... | class_definition | 32,692 | 33,659 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,888 |
class TFViTForImageClassification(TFViTPreTrainedModel, TFSequenceClassificationLoss):
def __init__(self, config: ViTConfig, *inputs, **kwargs):
super().__init__(config, *inputs, **kwargs)
self.num_labels = config.num_labels
self.vit = TFViTMainLayer(config, add_pooling_layer=False, name="v... | class_definition | 34,204 | 37,325 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/modeling_tf_vit.py | null | 6,889 |
class ViTConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`ViTModel`]. It is used to instantiate an ViT
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configu... | class_definition | 920 | 5,212 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/configuration_vit.py | null | 6,890 |
class ViTOnnxConfig(OnnxConfig):
torch_onnx_minimum_version = version.parse("1.11")
@property
def inputs(self) -> Mapping[str, Mapping[int, str]]:
return OrderedDict(
[
("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
]
)
... | class_definition | 5,215 | 5,611 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/configuration_vit.py | null | 6,891 |
class ViTImageProcessorFast(BaseImageProcessorFast):
r"""
Constructs a ViT image processor.
Args:
do_resize (`bool`, *optional*, defaults to `True`):
Whether to resize the image's (height, width) dimensions to the specified `(size["height"],
size["width"])`. Can be overridde... | class_definition | 1,569 | 13,770 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/image_processing_vit_fast.py | null | 6,892 |
class ViTFeatureExtractor(ViTImageProcessor):
def __init__(self, *args, **kwargs) -> None:
warnings.warn(
"The class ViTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"
" use ViTImageProcessor instead.",
FutureWarning,
)
... | class_definition | 806 | 1,164 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/vit/feature_extraction_vit.py | null | 6,893 |
class SegformerConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`SegformerModel`]. It is used to instantiate an
SegFormer model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield... | class_definition | 939 | 6,885 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/segformer/configuration_segformer.py | null | 6,894 |
class SegformerOnnxConfig(OnnxConfig):
torch_onnx_minimum_version = version.parse("1.11")
@property
def inputs(self) -> Mapping[str, Mapping[int, str]]:
return OrderedDict(
[
("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
]
... | class_definition | 6,888 | 7,364 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/segformer/configuration_segformer.py | null | 6,895 |
class SegformerFeatureExtractor(SegformerImageProcessor):
def __init__(self, *args, **kwargs) -> None:
warnings.warn(
"The class SegformerFeatureExtractor is deprecated and will be removed in version 5 of Transformers."
" Please use SegformerImageProcessor instead.",
Futu... | class_definition | 824 | 1,206 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/segformer/feature_extraction_segformer.py | null | 6,896 |
class SegFormerImageClassifierOutput(ImageClassifierOutput):
"""
Base class for outputs of image classification models.
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
Classification (or regression if config.num_labels==1) loss.
... | class_definition | 1,656 | 3,253 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/segformer/modeling_segformer.py | null | 6,897 |
class SegformerDropPath(nn.Module):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks)."""
def __init__(self, drop_prob: Optional[float] = None) -> None:
super().__init__()
self.drop_prob = drop_prob
def forward(self, hidden_states: torch.Tensor) -> ... | class_definition | 4,514 | 4,997 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/segformer/modeling_segformer.py | null | 6,898 |
class SegformerOverlapPatchEmbeddings(nn.Module):
"""Construct the overlapping patch embeddings."""
def __init__(self, patch_size, stride, num_channels, hidden_size):
super().__init__()
self.proj = nn.Conv2d(
num_channels,
hidden_size,
kernel_size=patch_size,... | class_definition | 5,000 | 5,915 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/segformer/modeling_segformer.py | null | 6,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.