code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def forward(
self,
input_values: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.LongTensor] = None,
decoder_input_values: Optional[torch.FloatTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTens... |
input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Float values of input raw speech waveform. Values can be obtained by loading a *.flac* or *.wav* audio file
into an array of type `List[float]` or a `numpy.ndarray`, *e.g.* via the soundfile library (*pip insta... | forward | python | huggingface/transformers | src/transformers/models/speecht5/modeling_speecht5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speecht5/modeling_speecht5.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
decoder_pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
*model_args,
**kwargs,
) -> FlaxPreTrainedModel:
r"""
In... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
Params:
encoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*):
Information necessary to initiate the encoder. Can be either:
... | from_encoder_decoder_pretrained | python | huggingface/transformers | src/transformers/models/speech_encoder_decoder/modeling_flax_speech_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_encoder_decoder/modeling_flax_speech_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: Optional[str] = None,
decoder_pretrained_model_name_or_path: Optional[str] = None,
*model_args,
**kwargs,
) -> PreTrainedModel:
r"""
Instantiate an encoder and a decoder from one ... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
the model, you need to first set it back in training mode... | from_encoder_decoder_pretrained | python | huggingface/transformers | src/transformers/models/speech_encoder_decoder/modeling_speech_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_encoder_decoder/modeling_speech_encoder_decoder.py | Apache-2.0 |
def __call__(
self,
raw_speech: Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]],
padding: Union[bool, str, PaddingStrategy] = False,
max_length: Optional[int] = None,
truncation: bool = False,
pad_to_multiple_of: Optional[int] = None,
return_te... |
Main method to featurize and prepare for the model one or several sequence(s).
Args:
raw_speech (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
... | __call__ | python | huggingface/transformers | src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_to_text/feature_extraction_speech_to_text.py | Apache-2.0 |
def forward(
self,
input_ids=None,
attention_mask=None,
encoder_hidden_states=None,
encoder_attention_mask=None,
head_mask=None,
cross_attn_head_mask=None,
past_key_values=None,
inputs_embeds=None,
use_cache=None,
output_attentions=... |
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`Speech2TextTokenizer`]. See [... | forward | python | huggingface/transformers | src/transformers/models/speech_to_text/modeling_speech_to_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_to_text/modeling_speech_to_text.py | Apache-2.0 |
def forward(
self,
input_features: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
input_features (`torch.FloatTensor` of shape `(batch_size, sequence_length, feature_size)`):
Float values of fbank features extracted from the raw speech waveform. Raw speech waveform can be obtained
by loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `num... | forward | python | huggingface/transformers | src/transformers/models/speech_to_text/modeling_speech_to_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_to_text/modeling_speech_to_text.py | Apache-2.0 |
def forward(
self,
input_features: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
input_features (`torch.FloatTensor` of shape `(batch_size, sequence_length, feature_size)`):
Float values of fbank features extracted from the raw speech waveform. Raw speech waveform can be obtained
by loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `num... | forward | python | huggingface/transformers | src/transformers/models/speech_to_text/modeling_speech_to_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_to_text/modeling_speech_to_text.py | Apache-2.0 |
def call(
self,
input_ids=None,
inputs_embeds=None,
attention_mask=None,
encoder_hidden_states=None,
encoder_attention_mask=None,
head_mask=None,
cross_attn_head_mask=None,
past_key_values=None,
use_cache=None,
output_attentions=Non... |
Args:
input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`Speech2TextTokenizer`]. See [`PreTra... | call | python | huggingface/transformers | src/transformers/models/speech_to_text/modeling_tf_speech_to_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_to_text/modeling_tf_speech_to_text.py | Apache-2.0 |
def __call__(self, *args, **kwargs):
"""
When used in normal mode, this method forwards all its arguments to Speech2TextFeatureExtractor's
[`~Speech2TextFeatureExtractor.__call__`] and returns its output. If used in the context
[`~Speech2TextProcessor.as_target_processor`] this method fo... |
When used in normal mode, this method forwards all its arguments to Speech2TextFeatureExtractor's
[`~Speech2TextFeatureExtractor.__call__`] and returns its output. If used in the context
[`~Speech2TextProcessor.as_target_processor`] this method forwards all its arguments to Speech2TextTokenizer... | __call__ | python | huggingface/transformers | src/transformers/models/speech_to_text/processing_speech_to_text.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/speech_to_text/processing_speech_to_text.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
token_type_ids (`torch.LongTensor` of shape `batch_size, sequence_length`, *optional*):
Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
1]`:
- 0 corresponds to a *sentence A* token,
- 1 corresponds to a *se... | forward | python | huggingface/transformers | src/transformers/models/splinter/modeling_splinter.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/splinter/modeling_splinter.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
token_type_ids (`torch.LongTensor` of shape `batch_size, sequence_length`, *optional*):
Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
1]`:
- 0 corresponds to a *sentence A* token,
- 1 corresponds to a *se... | forward | python | huggingface/transformers | src/transformers/models/splinter/modeling_splinter.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/splinter/modeling_splinter.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_questions, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/splinter/modeling_splinter.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/splinter/modeling_splinter.py | Apache-2.0 |
def tokenize(self, text):
"""
Tokenizes a piece of text into its word pieces. This uses a greedy longest-match-first algorithm to perform
tokenization using the given vocabulary.
For example, `input = "unaffable"` will return as output `["un", "##aff", "##able"]`.
Args:
... |
Tokenizes a piece of text into its word pieces. This uses a greedy longest-match-first algorithm to perform
tokenization using the given vocabulary.
For example, `input = "unaffable"` will return as output `["un", "##aff", "##able"]`.
Args:
text: A single token or whitespace... | tokenize | python | huggingface/transformers | src/transformers/models/splinter/tokenization_splinter.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/splinter/tokenization_splinter.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optiona... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/squeezebert/modeling_squeezebert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/squeezebert/modeling_squeezebert.py | Apache-2.0 |
def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A SqueezeBERT sequence
pair mask has the following format... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A SqueezeBERT sequence
pair mask has the following format:
```
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
```
If `token_ids_1` is... | create_token_type_ids_from_sequences | python | huggingface/transformers | src/transformers/models/squeezebert/tokenization_squeezebert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/squeezebert/tokenization_squeezebert.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_value: Optional[Tuple[torch.Tensor]] = None,
output_attentions: Optional[bool] = False,
use_cache: Optional[boo... |
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values... | forward | python | huggingface/transformers | src/transformers/models/stablelm/modeling_stablelm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/stablelm/modeling_stablelm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/starcoder2/modeling_starcoder2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/starcoder2/modeling_starcoder2.py | Apache-2.0 |
def convert_to_grayscale(
image: ImageInput,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
) -> ImageInput:
"""
Converts an image to grayscale format using the NTSC formula. Only support numpy and PIL Image. TODO support torch
and tensorflow grayscale conversion
This functio... |
Converts an image to grayscale format using the NTSC formula. Only support numpy and PIL Image. TODO support torch
and tensorflow grayscale conversion
This function is supposed to return a 1-channel image, but it returns a 3-channel image with the same value in each
channel, because of an issue that i... | convert_to_grayscale | python | huggingface/transformers | src/transformers/models/superglue/image_processing_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/image_processing_superglue.py | Apache-2.0 |
def _is_valid_image(image):
"""images is a PIL Image or a 3D array."""
return is_pil_image(image) or (
is_valid_image(image) and get_image_type(image) != ImageType.PIL and len(image.shape) == 3
) | images is a PIL Image or a 3D array. | _is_valid_image | python | huggingface/transformers | src/transformers/models/superglue/image_processing_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/image_processing_superglue.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
):
"""
Resize an image.
Args:
image ... |
Resize an image.
Args:
image (`np.ndarray`):
Image to resize.
size (`Dict[str, int]`):
Dictionary of the form `{"height": int, "width": int}`, specifying the size of the output image.
data_format (`ChannelDimension` or `str`, *optiona... | resize | python | huggingface/transformers | src/transformers/models/superglue/image_processing_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/image_processing_superglue.py | Apache-2.0 |
def preprocess(
self,
images,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None,
do_grayscale: Optional[bool] = None,
... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image pairs to preprocess. Expects either a list of 2 images or a list of list of 2 images list with
pixel values ranging from 0 to 255. If passing in images with pixel values between 0 and... | preprocess | python | huggingface/transformers | src/transformers/models/superglue/image_processing_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/image_processing_superglue.py | Apache-2.0 |
def post_process_keypoint_matching(
self,
outputs: "KeypointMatchingOutput",
target_sizes: Union[TensorType, List[Tuple]],
threshold: float = 0.0,
) -> List[Dict[str, torch.Tensor]]:
"""
Converts the raw output of [`KeypointMatchingOutput`] into lists of keypoints, sc... |
Converts the raw output of [`KeypointMatchingOutput`] into lists of keypoints, scores and descriptors
with coordinates absolute to the original image sizes.
Args:
outputs ([`KeypointMatchingOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor`... | post_process_keypoint_matching | python | huggingface/transformers | src/transformers/models/superglue/image_processing_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/image_processing_superglue.py | Apache-2.0 |
def normalize_keypoints(keypoints: torch.Tensor, height: int, width: int) -> torch.Tensor:
"""
Normalize keypoints locations based on image image_shape
Args:
keypoints (`torch.Tensor` of shape `(batch_size, num_keypoints, 2)`):
Keypoints locations in (x, y) format.
height (`int`... |
Normalize keypoints locations based on image image_shape
Args:
keypoints (`torch.Tensor` of shape `(batch_size, num_keypoints, 2)`):
Keypoints locations in (x, y) format.
height (`int`):
Image height.
width (`int`):
Image width.
Returns:
... | normalize_keypoints | python | huggingface/transformers | src/transformers/models/superglue/modeling_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/modeling_superglue.py | Apache-2.0 |
def log_sinkhorn_iterations(
log_cost_matrix: torch.Tensor,
log_source_distribution: torch.Tensor,
log_target_distribution: torch.Tensor,
num_iterations: int,
) -> torch.Tensor:
"""
Perform Sinkhorn Normalization in Log-space for stability
Args:
log_cost_matrix (`torch.Tensor` of sh... |
Perform Sinkhorn Normalization in Log-space for stability
Args:
log_cost_matrix (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`):
Logarithm of the cost matrix.
log_source_distribution (`torch.Tensor` of shape `(batch_size, num_rows)`):
Logarithm of the so... | log_sinkhorn_iterations | python | huggingface/transformers | src/transformers/models/superglue/modeling_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/modeling_superglue.py | Apache-2.0 |
def log_optimal_transport(scores: torch.Tensor, reg_param: torch.Tensor, iterations: int) -> torch.Tensor:
"""
Perform Differentiable Optimal Transport in Log-space for stability
Args:
scores: (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`):
Cost matrix.
reg_para... |
Perform Differentiable Optimal Transport in Log-space for stability
Args:
scores: (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`):
Cost matrix.
reg_param: (`torch.Tensor` of shape `(batch_size, 1, 1)`):
Regularization parameter.
iterations: (`int... | log_optimal_transport | python | huggingface/transformers | src/transformers/models/superglue/modeling_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/modeling_superglue.py | Apache-2.0 |
def _match_image_pair(
self,
keypoints: torch.Tensor,
descriptors: torch.Tensor,
scores: torch.Tensor,
height: int,
width: int,
mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = No... |
Perform keypoint matching between two images.
Args:
keypoints (`torch.Tensor` of shape `(batch_size, 2, num_keypoints, 2)`):
Keypoints detected in the pair of image.
descriptors (`torch.Tensor` of shape `(batch_size, 2, descriptor_dim, num_keypoints)`):
... | _match_image_pair | python | huggingface/transformers | src/transformers/models/superglue/modeling_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/modeling_superglue.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, KeypointMatchingOutput]:
... |
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoModel
>>> import torch
>>> from PIL import Image
>>> import requests
>>> url = "https://github.com/magicleap/SuperGluePretrainedNetwork/blob/master/assets/phototourism_sample_images/london... | forward | python | huggingface/transformers | src/transformers/models/superglue/modeling_superglue.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superglue/modeling_superglue.py | Apache-2.0 |
def convert_superpoint_checkpoint(checkpoint_url, pytorch_dump_folder_path, save_model, push_to_hub, test_mode=False):
"""
Copy/paste/tweak model's weights to our SuperPoint structure.
"""
print("Downloading original model from checkpoint...")
config = get_superpoint_config()
# load original s... |
Copy/paste/tweak model's weights to our SuperPoint structure.
| convert_superpoint_checkpoint | python | huggingface/transformers | src/transformers/models/superpoint/convert_superpoint_to_pytorch.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/convert_superpoint_to_pytorch.py | Apache-2.0 |
def preprocess(
self,
images,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None,
do_grayscale: Optional[bool] = None,
return_tensors: Optional[Union[str, Tenso... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
... | preprocess | python | huggingface/transformers | src/transformers/models/superpoint/image_processing_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/image_processing_superpoint.py | Apache-2.0 |
def post_process_keypoint_detection(
self, outputs: "SuperPointKeypointDescriptionOutput", target_sizes: Union[TensorType, List[Tuple]]
) -> List[Dict[str, "torch.Tensor"]]:
"""
Converts the raw output of [`SuperPointForKeypointDetection`] into lists of keypoints, scores and descriptors
... |
Converts the raw output of [`SuperPointForKeypointDetection`] into lists of keypoints, scores and descriptors
with coordinates absolute to the original image sizes.
Args:
outputs ([`SuperPointKeypointDescriptionOutput`]):
Raw outputs of the model containing keypoint... | post_process_keypoint_detection | python | huggingface/transformers | src/transformers/models/superpoint/image_processing_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/image_processing_superpoint.py | Apache-2.0 |
def remove_keypoints_from_borders(
keypoints: torch.Tensor, scores: torch.Tensor, border: int, height: int, width: int
) -> Tuple[torch.Tensor, torch.Tensor]:
"""Removes keypoints (and their associated scores) that are too close to the border"""
mask_h = (keypoints[:, 0] >= border) & (keypoints[:, 0] < (hei... | Removes keypoints (and their associated scores) that are too close to the border | remove_keypoints_from_borders | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def top_k_keypoints(keypoints: torch.Tensor, scores: torch.Tensor, k: int) -> Tuple[torch.Tensor, torch.Tensor]:
"""Keeps the k keypoints with highest score"""
if k >= len(keypoints):
return keypoints, scores
scores, indices = torch.topk(scores, k, dim=0)
return keypoints[indices], scores | Keeps the k keypoints with highest score | top_k_keypoints | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def simple_nms(scores: torch.Tensor, nms_radius: int) -> torch.Tensor:
"""Applies non-maximum suppression on scores"""
if nms_radius < 0:
raise ValueError("Expected positive values for nms_radius")
def max_pool(x):
return nn.functional.max_pool2d(x, kernel_size=nms_radius * 2 + 1, stride=1,... | Applies non-maximum suppression on scores | simple_nms | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def _get_pixel_scores(self, encoded: torch.Tensor) -> torch.Tensor:
"""Based on the encoder output, compute the scores for each pixel of the image"""
scores = self.relu(self.conv_score_a(encoded))
scores = self.conv_score_b(scores)
scores = nn.functional.softmax(scores, 1)[:, :-1]
... | Based on the encoder output, compute the scores for each pixel of the image | _get_pixel_scores | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def _extract_keypoints(self, scores: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Based on their scores, extract the pixels that represent the keypoints that will be used for descriptors computation.
The keypoints are in the form of relative (x, y) coordinates.
"""
_, ... |
Based on their scores, extract the pixels that represent the keypoints that will be used for descriptors computation.
The keypoints are in the form of relative (x, y) coordinates.
| _extract_keypoints | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def forward(self, encoded: torch.Tensor, keypoints: torch.Tensor) -> torch.Tensor:
"""Based on the encoder output and the keypoints, compute the descriptors for each keypoint"""
descriptors = self.conv_descriptor_b(self.relu(self.conv_descriptor_a(encoded)))
descriptors = nn.functional.normalize... | Based on the encoder output and the keypoints, compute the descriptors for each keypoint | forward | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
labels: Optional[torch.LongTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, SuperPointKeypointDescriptionOutput]:
r"""
Examples:
```p... |
Examples:
```python
>>> from transformers import AutoImageProcessor, SuperPointForKeypointDetection
>>> import torch
>>> from PIL import Image
>>> import requests
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(... | forward | python | huggingface/transformers | src/transformers/models/superpoint/modeling_superpoint.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/superpoint/modeling_superpoint.py | Apache-2.0 |
def __init__(self, config, add_pooling_layer=True, use_mask_token=False):
r"""
add_pooling_layer (`bool`, *optional*, defaults to `True`):
Whether or not to apply pooling layer.
use_mask_token (`bool`, *optional*, defaults to `False`):
Whether or not to create and apply m... |
add_pooling_layer (`bool`, *optional*, defaults to `True`):
Whether or not to apply pooling layer.
use_mask_token (`bool`, *optional*, defaults to `False`):
Whether or not to create and apply mask tokens in the embedding layer.
| __init__ | python | huggingface/transformers | src/transformers/models/swin/modeling_swin.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/swin/modeling_swin.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
interpola... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Examples:
```python
>>> from transformers import AutoImageProcessor, SwinForMaskedImageModeling
>>> impo... | forward | python | huggingface/transformers | src/transformers/models/swin/modeling_swin.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/swin/modeling_swin.py | Apache-2.0 |
def pad(self, images: "torch.Tensor", size: int) -> "torch.Tensor":
"""
Pad an image to make the height and width divisible by `size`.
Args:
images (`torch.Tensor`):
Images to pad.
size (`int`):
The size to make the height and width divisi... |
Pad an image to make the height and width divisible by `size`.
Args:
images (`torch.Tensor`):
Images to pad.
size (`int`):
The size to make the height and width divisible by.
Returns:
`torch.Tensor`: The padded images.
... | pad | python | huggingface/transformers | src/transformers/models/swin2sr/image_processing_swin2sr_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/swin2sr/image_processing_swin2sr_fast.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optio... |
Example:
```python
>>> import torch
>>> import numpy as np
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoImageProcessor, Swin2SRForImageSuperResolution
>>> processor = AutoImageProcessor.from_pretrained("caidas/sw... | forward | python | huggingface/transformers | src/transformers/models/swin2sr/modeling_swin2sr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/swin2sr/modeling_swin2sr.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
interpola... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Examples:
```python
>>> from transformers import AutoImageProcessor, Swinv2ForMaskedImageModeling
>>> im... | forward | python | huggingface/transformers | src/transformers/models/swinv2/modeling_swinv2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/swinv2/modeling_swinv2.py | Apache-2.0 |
def forward(
self,
pixel_values: Tensor,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import Auto... |
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import requests
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, ... | forward | python | huggingface/transformers | src/transformers/models/swinv2/modeling_swinv2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/swinv2/modeling_swinv2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = N... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. SWITCH_TRANSFORMERS is a model with relative position
embeddings so you should be able to pad the inputs on both the right and the left.
Indices can ... | forward | python | huggingface/transformers | src/transformers/models/switch_transformers/modeling_switch_transformers.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/switch_transformers/modeling_switch_transformers.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. SWITCH_TRANSFORMERS is a model with relative position
embeddings so you should be able to pad the inputs on both the right and the left.
Indices can ... | forward | python | huggingface/transformers | src/transformers/models/switch_transformers/modeling_switch_transformers.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/switch_transformers/modeling_switch_transformers.py | Apache-2.0 |
def load_t5x_weights_in_t5(model, config, t5x_checkpoint_path, is_encoder_only):
"""Replaces the params in model with the T5X converted params."""
variables = checkpoints.load_t5x_checkpoint(t5x_checkpoint_path)
converted = convert_t5x_to_pytorch(
variables,
num_layers=config.num_layers,
... | Replaces the params in model with the T5X converted params. | load_t5x_weights_in_t5 | python | huggingface/transformers | src/transformers/models/t5/convert_t5x_checkpoint_to_pytorch.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/convert_t5x_checkpoint_to_pytorch.py | Apache-2.0 |
def encode(
self,
input_ids: jnp.ndarray,
attention_mask: Optional[jnp.ndarray] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
train: bool = False,
params: Optional[dict] =... |
Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxT5ForConditionalGeneration
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = FlaxT5ForConditionalGeneration.from_pretrained("google-t5/t5-small")
>>> tex... | encode | python | huggingface/transformers | src/transformers/models/t5/modeling_flax_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_flax_t5.py | Apache-2.0 |
def decode(
self,
decoder_input_ids,
encoder_outputs,
encoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
past_key_values: Optional[dict] = None,
output_attentions: Optional[bool] = None,
output_hidde... |
Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxT5ForConditionalGeneration
>>> import jax.numpy as jnp
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = FlaxT5ForConditionalGeneration.from_pretrained("g... | decode | python | huggingface/transformers | src/transformers/models/t5/modeling_flax_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_flax_t5.py | Apache-2.0 |
def decode(
self,
decoder_input_ids,
encoder_outputs,
encoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
past_key_values: Optional[dict] = None,
output_attentions: Optional[bool] = None,
output_hidde... |
Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxT5ForConditionalGeneration
>>> import jax.numpy as jnp
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = FlaxT5ForConditionalGeneration.from_pretrained("g... | decode | python | huggingface/transformers | src/transformers/models/t5/modeling_flax_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_flax_t5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = N... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
should be able to pad the inputs on both the right and the left.
Indices can be obtained using... | forward | python | huggingface/transformers | src/transformers/models/t5/modeling_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.FloatTensor] = N... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
should be able to pad the inputs on both the right and the left.
Indices can be obtained using... | forward | python | huggingface/transformers | src/transformers/models/t5/modeling_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
should be able to pad the inputs on both the right and the left.
Indices can be obtained using... | forward | python | huggingface/transformers | src/transformers/models/t5/modeling_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
should be able to pad the inputs on both the right and the left.
Indices can be obtained using... | forward | python | huggingface/transformers | src/transformers/models/t5/modeling_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_attentions: Optional[b... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
should be able to pad the inputs on both the right and the left.
Indices can be obtained using... | forward | python | huggingface/transformers | src/transformers/models/t5/modeling_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_t5.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None... |
Returns:
Examples:
```python
>>> from transformers import AutoTokenizer, TFT5Model
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = TFT5Model.from_pretrained("google-t5/t5-small")
>>> input_ids = tokenizer(
... "Stud... | call | python | huggingface/transformers | src/transformers/models/t5/modeling_tf_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_tf_t5.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None... |
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the cross entropy classification loss. Indices should be in `[0, ...,
config.vocab_size - 1]`.
Returns:
Examples:
```python
>>> from transformers import Aut... | call | python | huggingface/transformers | src/transformers/models/t5/modeling_tf_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_tf_t5.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None,
inputs_embeds: np.ndarray | tf.Tensor | None = None,
output_attentions: Optional[bool] = None,
output_... |
Returns:
Examples:
```python
>>> from transformers import AutoTokenizer, TFT5EncoderModel
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = TFT5EncoderModel.from_pretrained("google-t5/t5-small")
>>> input_ids = tokenizer(
... | call | python | huggingface/transformers | src/transformers/models/t5/modeling_tf_t5.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/t5/modeling_tf_t5.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.FloatTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/table_transformer/modeling_table_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/table_transformer/modeling_table_transformer.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
pixel_mask: Optional[torch.FloatTensor] = None,
decoder_attention_mask: Optional[torch.FloatTensor] = None,
encoder_outputs: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
... |
decoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, num_queries)`, *optional*):
Not used by default. Can be used to mask object queries.
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
Optionally, instead of p... | forward | python | huggingface/transformers | src/transformers/models/table_transformer/modeling_table_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/table_transformer/modeling_table_transformer.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
... |
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
class for more info.
[What are token type IDs?](../glossary#token-type-ids)
... | forward | python | huggingface/transformers | src/transformers/models/tapas/modeling_tapas.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tapas/modeling_tapas.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
... |
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
class for more info.
[What are token type IDs?](../glossary#token-type-ids)
... | forward | python | huggingface/transformers | src/transformers/models/tapas/modeling_tapas.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tapas/modeling_tapas.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
... |
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
class for more info.
[What are token type IDs?](../glossary#token-type-ids)
... | forward | python | huggingface/transformers | src/transformers/models/tapas/modeling_tapas.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tapas/modeling_tapas.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
... |
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 7)`, *optional*):
Token indices that encode tabular structure. Indices can be obtained using [`AutoTokenizer`]. See this
class for more info.
[What are token type IDs?](../glossary#token-type-ids)
... | forward | python | huggingface/transformers | src/transformers/models/tapas/modeling_tapas.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tapas/modeling_tapas.py | Apache-2.0 |
def _get_truncated_table_rows(
self,
query_tokens: List[str],
tokenized_table: TokenizedTable,
num_rows: int,
num_columns: int,
max_length: int,
truncation_strategy: Union[str, TapasTruncationStrategy],
) -> Tuple[int, int]:
"""
Truncates a seq... |
Truncates a sequence pair in-place following the strategy.
Args:
query_tokens (`List[str]`):
List of strings corresponding to the tokenized query.
tokenized_table (`TokenizedTable`):
Tokenized table
num_rows (`int`):
T... | _get_truncated_table_rows | python | huggingface/transformers | src/transformers/models/tapas/tokenization_tapas.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tapas/tokenization_tapas.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
resample: PILImageResampling = PILImageResampling.BILINEAR,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> ... |
Resize an image. The shortest edge of the image is resized to size["shortest_edge"] , with the longest edge
resized to keep the input aspect ratio. Both the height and width are resized to be divisible by 32.
Args:
image (`np.ndarray`):
Image to resize.
... | resize | python | huggingface/transformers | src/transformers/models/textnet/image_processing_textnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/textnet/image_processing_textnet.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
size_divisor: Optional[int] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[int] = No... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
... | preprocess | python | huggingface/transformers | src/transformers/models/textnet/image_processing_textnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/textnet/image_processing_textnet.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> ImageClassifierOutputWithNoAttention:
r"""
labels (`torch.Long... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.n... | forward | python | huggingface/transformers | src/transformers/models/textnet/modeling_textnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/textnet/modeling_textnet.py | Apache-2.0 |
def forward(
self, pixel_values: Tensor, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None
) -> Union[Tuple[Tuple], BackboneOutput]:
r"""
Examples:
```python
>>> import torch
>>> import requests
>>> from PIL import Image
... |
Examples:
```python
>>> import torch
>>> import requests
>>> from PIL import Image
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, ... | forward | python | huggingface/transformers | src/transformers/models/textnet/modeling_textnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/textnet/modeling_textnet.py | Apache-2.0 |
def get_nested_attr(obj, key):
"""Recursively retrieves an attribute from an object, handling list/tuple indexing if present."""
parts = key.split(".")
for part in parts:
match = re.match(r"(.*)\[(\d+)\]", part) # Handle list indexing like `layers[0]`
if match:
attr_name, index ... | Recursively retrieves an attribute from an object, handling list/tuple indexing if present. | get_nested_attr | python | huggingface/transformers | src/transformers/models/timesfm/convert_timesfm_orignal_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/convert_timesfm_orignal_to_hf.py | Apache-2.0 |
def forward(self, seq_length=None, position=None):
"""Generates a Tensor of sinusoids with different frequencies.
Args:
seq_length: an optional Python int defining the output sequence length.
if the `position` argument is specified.
position: [B, seq_length], optio... | Generates a Tensor of sinusoids with different frequencies.
Args:
seq_length: an optional Python int defining the output sequence length.
if the `position` argument is specified.
position: [B, seq_length], optional position for each token in the
sequence, onl... | forward | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def forward(
self,
past_values: torch.Tensor,
past_values_padding: torch.LongTensor,
freq: torch.Tensor,
output_attentions: bool = False,
output_hidden_states: bool = False,
) -> TimesFmOutput:
r"""
past_values_padding (`torch.LongTensor` of shape `(ba... |
past_values_padding (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
The padding indicator of the time series.
past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Past values of the time series that serves as input to the model.
freq... | forward | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def _prepare_4d_attention_mask(
attention_mask: Optional[torch.Tensor],
sequence_length: int,
dtype: torch.dtype,
device: torch.device,
is_causal: bool = True,
) -> Optional[torch.Tensor]:
"""
Creates 4D attention mask and combines causal and padding masks if ... |
Creates 4D attention mask and combines causal and padding masks if needed.
Args:
attention_mask: Optional tensor of shape (batch_size, seq_length) containing padding mask
sequence_length: Length of the sequence
dtype: Data type of the mask
device: Device... | _prepare_4d_attention_mask | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def _timesfm_masked_mean_std(inputs: torch.Tensor, padding: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
"""Calculates mean and standard deviation of `inputs` across axis 1.
It excludes values where `padding` is 1.
Args:
inputs: A PyTorch tensor of shape [b, n, p].
... | Calculates mean and standard deviation of `inputs` across axis 1.
It excludes values where `padding` is 1.
Args:
inputs: A PyTorch tensor of shape [b, n, p].
padding: A PyTorch tensor of shape [b, n, p] with values 0 or 1.
Returns:
A tuple containing the me... | _timesfm_masked_mean_std | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def _timesfm_shift_padded_seq(mask: torch.Tensor, seq: torch.Tensor) -> torch.Tensor:
"""Shifts rows of seq based on the first 0 in each row of the mask.
Args:
mask: mask tensor of shape [B, N]
seq: seq tensor of shape [B, N, P]
Returns:
The shifted sequence... | Shifts rows of seq based on the first 0 in each row of the mask.
Args:
mask: mask tensor of shape [B, N]
seq: seq tensor of shape [B, N, P]
Returns:
The shifted sequence.
| _timesfm_shift_padded_seq | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def _preprocess(
self, inputs: Sequence[torch.Tensor], freq: Sequence[int]
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""Formats and pads raw inputs to feed into the model.
This function both pads each time series to match the context length, and
pads the inputs to meet t... | Formats and pads raw inputs to feed into the model.
This function both pads each time series to match the context length, and
pads the inputs to meet the SPMD shape requirement.
Args:
inputs: A list of 1d Tensors. Each Tensor is the context time series of
a single forecas... | _preprocess | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def forward(
self,
past_values: Sequence[torch.Tensor],
freq: Optional[Sequence[Union[torch.Tensor, int]]] = None,
window_size: Optional[int] = None,
future_values: Optional[torch.Tensor] = None,
forecast_context_len: Optional[int] = None,
return_forecast_on_conte... |
window_size (`int`, *optional*):
Window size of trend + residual decomposition. If None then we do not do decomposition.
future_values (`torch.Tensor`, *optional*):
Optional future time series values to be used for loss computation.
forecast_context_len (`int`, *optional... | forward | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def _timesfm_moving_average(arr: torch.Tensor, window_size: int) -> list[torch.Tensor]:
"""Calculates the moving average using PyTorch's convolution function."""
# Pad with zeros to handle initial window positions
arr_padded = F.pad(arr, (window_size - 1, 0), "constant", 0)
# Create a co... | Calculates the moving average using PyTorch's convolution function. | _timesfm_moving_average | python | huggingface/transformers | src/transformers/models/timesfm/modeling_timesfm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesfm/modeling_timesfm.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple[torch.FloatTensor], BaseModelOutput]:
r"""
Examples:
```pyt... |
Examples:
```python
>>> import av
>>> import numpy as np
>>> from transformers import AutoImageProcessor, TimesformerModel
>>> from huggingface_hub import hf_hub_download
>>> np.random.seed(0)
>>> def read_video_pyav(container, indices):
... ... | forward | python | huggingface/transformers | src/transformers/models/timesformer/modeling_timesformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesformer/modeling_timesformer.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, ImageClassifierOutput]:
... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.n... | forward | python | huggingface/transformers | src/transformers/models/timesformer/modeling_timesformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timesformer/modeling_timesformer.py | Apache-2.0 |
def forward(
self,
past_values: torch.Tensor,
past_time_features: torch.Tensor,
past_observed_mask: torch.Tensor,
static_categorical_features: Optional[torch.Tensor] = None,
static_real_features: Optional[torch.Tensor] = None,
future_values: Optional[torch.Tensor]... |
past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)` or `(batch_size, sequence_length, input_size)`):
Past values of the time series, that serve as context in order to predict the future. The sequence size of
this tensor must be larger than the `context_length` of t... | forward | python | huggingface/transformers | src/transformers/models/time_series_transformer/modeling_time_series_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/time_series_transformer/modeling_time_series_transformer.py | Apache-2.0 |
def forward(
self,
past_values: torch.Tensor,
past_time_features: torch.Tensor,
past_observed_mask: torch.Tensor,
static_categorical_features: Optional[torch.Tensor] = None,
static_real_features: Optional[torch.Tensor] = None,
future_values: Optional[torch.Tensor]... |
past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)` or `(batch_size, sequence_length, input_size)`):
Past values of the time series, that serve as context in order to predict the future. The sequence size of
this tensor must be larger than the `context_length` of t... | forward | python | huggingface/transformers | src/transformers/models/time_series_transformer/modeling_time_series_transformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/time_series_transformer/modeling_time_series_transformer.py | Apache-2.0 |
def get_image_processor_dict(
cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
"""
Get the image processor dict for the model.
"""
image_processor_filename = kwargs.pop("image_processor_filename", "config.json")... |
Get the image processor dict for the model.
| get_image_processor_dict | python | huggingface/transformers | src/transformers/models/timm_wrapper/image_processing_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/image_processing_timm_wrapper.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
return_tensors: Optional[Union[str, TensorType]] = "pt",
) -> BatchFeature:
"""
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image to preprocess. Expects a single or batch o... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
Image to preprocess. Expects a single or batch of images
return_tensors (`str` or `TensorType`, *optional*):
The type of tensors to return.
| preprocess | python | huggingface/transformers | src/transformers/models/timm_wrapper/image_processing_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/image_processing_timm_wrapper.py | Apache-2.0 |
def _fix_state_dict_key_on_load(key) -> Tuple[str, bool]:
"""
Overrides original method that renames `gamma` and `beta` to `weight` and `bias`.
We don't want this behavior for timm wrapped models. Instead, this method adds a
"timm_model." prefix to enable loading official timm Hub checkp... |
Overrides original method that renames `gamma` and `beta` to `weight` and `bias`.
We don't want this behavior for timm wrapped models. Instead, this method adds a
"timm_model." prefix to enable loading official timm Hub checkpoints.
| _fix_state_dict_key_on_load | python | huggingface/transformers | src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | Apache-2.0 |
def load_state_dict(self, state_dict, *args, **kwargs):
"""
Override original method to fix state_dict keys on load for cases when weights are loaded
without using the `from_pretrained` method (e.g., in Trainer to resume from checkpoint).
"""
state_dict = {self._fix_state_dict_ke... |
Override original method to fix state_dict keys on load for cases when weights are loaded
without using the `from_pretrained` method (e.g., in Trainer to resume from checkpoint).
| load_state_dict | python | huggingface/transformers | src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | Apache-2.0 |
def _init_weights(self, module):
"""
Initialize weights function to properly initialize Linear layer weights.
Since model architectures may vary, we assume only the classifier requires
initialization, while all other weights should be loaded from the checkpoint.
"""
if is... |
Initialize weights function to properly initialize Linear layer weights.
Since model architectures may vary, we assume only the classifier requires
initialization, while all other weights should be loaded from the checkpoint.
| _init_weights | python | huggingface/transformers | src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[Union[bool, List[int]]] = None,
return_dict: Optional[bool] = None,
do_pooling: Optional[bool] = None,
**kwargs,
) -> Union[TimmWrapper... |
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. Not compatible with timm wrapped models.
output_hidden_states (`bool`, *optional*):
Whether or not to return the hidden states of all layers. Not compatible with timm... | forward | python | huggingface/transformers | src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[Union[bool, List[int]]] = None,
return_dict: Optional[bool] = None,
**kwargs,
) -> Union[Ima... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.n... | forward | python | huggingface/transformers | src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/timm_wrapper/modeling_timm_wrapper.py | Apache-2.0 |
def forward(
self,
input_ids=None,
attention_mask=None,
encoder_hidden_states=None,
encoder_attention_mask=None,
head_mask=None,
cross_attn_head_mask=None,
past_key_values=None,
inputs_embeds=None,
use_cache=None,
output_attentions=... |
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTra... | forward | python | huggingface/transformers | src/transformers/models/trocr/modeling_trocr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/trocr/modeling_trocr.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
encoder_hidden_states: Optional[torch.FloatTensor] = None,
encoder_attention_mask: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
Mask to nullify selected heads of the cross-attention modules. Mask values selected in `[0, 1]`:
- 1 indicates the head is **not masked**,
- 0 indicates the head is **mas... | forward | python | huggingface/transformers | src/transformers/models/trocr/modeling_trocr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/trocr/modeling_trocr.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,
audio=None,
videos=None,
**kwargs: Unpack[TrOCRProcessorKwargs],
) -> BatchFeature:
"""
When used in normal mode,... |
When used in normal mode, this method forwards all its arguments to AutoImageProcessor's
[`~AutoImageProcessor.__call__`] and returns its output. If used in the context
[`~TrOCRProcessor.as_target_processor`] this method forwards all its arguments to TrOCRTokenizer's
[`~TrOCRTokenizer._... | __call__ | python | huggingface/transformers | src/transformers/models/trocr/processing_trocr.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/trocr/processing_trocr.py | Apache-2.0 |
def resize(
self,
image: np.ndarray,
size: Dict[str, int],
resample: PILImageResampling = PILImageResampling.BILINEAR,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> ... |
Resize an image.
Args:
image (`np.ndarray`):
Image to resize.
size (`Dict[str, int]`):
Size of the output image. If `size` is of the form `{"height": h, "width": w}`, the output image will
have the size `(h, w)`. If `size` is of t... | resize | python | huggingface/transformers | src/transformers/models/tvp/image_processing_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/image_processing_tvp.py | Apache-2.0 |
def pad_image(
self,
image: np.ndarray,
pad_size: Optional[Dict[str, int]] = None,
constant_values: Union[float, Iterable[float]] = 0,
pad_mode: PaddingMode = PaddingMode.CONSTANT,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Opti... |
Pad an image with zeros to the given size.
Args:
image (`np.ndarray`):
Image to pad.
pad_size (`Dict[str, int]`)
Size of the output image with pad.
constant_values (`Union[float, Iterable[float]]`)
The fill value to us... | pad_image | python | huggingface/transformers | src/transformers/models/tvp/image_processing_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/image_processing_tvp.py | Apache-2.0 |
def preprocess(
self,
videos: Union[ImageInput, List[ImageInput], List[List[ImageInput]]],
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_center_crop: Optional[bool] = None,
crop_size: Optional[Dict... |
Preprocess an image or batch of images.
Args:
videos (`ImageInput` or `List[ImageInput]` or `List[List[ImageInput]]`):
Frames to preprocess.
do_resize (`bool`, *optional*, defaults to `self.do_resize`):
Whether to resize the image.
si... | preprocess | python | huggingface/transformers | src/transformers/models/tvp/image_processing_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/image_processing_tvp.py | Apache-2.0 |
def loss_distance(self, start_time, end_time, candidates_start_time, candidates_end_time, duration):
"""
Measure the distance of mid points.
"""
mid_candidates = torch.div(torch.add(candidates_start_time, candidates_end_time), 2.0)
mid_groundtruth = torch.div(torch.add(start_time... |
Measure the distance of mid points.
| loss_distance | python | huggingface/transformers | src/transformers/models/tvp/modeling_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/modeling_tvp.py | Apache-2.0 |
def forward(self, logits, labels):
"""
This performs the loss computation.
Args:
logits (`torch.FloatTensor`):
The output logits of head module.
labels (`List[torch.FloatTensor]`):
List of tensors ([start, end, duration]), which contains s... |
This performs the loss computation.
Args:
logits (`torch.FloatTensor`):
The output logits of head module.
labels (`List[torch.FloatTensor]`):
List of tensors ([start, end, duration]), which contains start time, end time of the video corresponding... | forward | python | huggingface/transformers | src/transformers/models/tvp/modeling_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/modeling_tvp.py | Apache-2.0 |
def interpolate_pos_encoding(self, embedding: torch.Tensor, height: int, width: int) -> torch.Tensor:
"""
This method allows to interpolate the pre-trained pad weights , to be able to use the model on collection of high
resolution images (high resolution videos).
"""
h0 = w0 = 1... |
This method allows to interpolate the pre-trained pad weights , to be able to use the model on collection of high
resolution images (high resolution videos).
| interpolate_pos_encoding | python | huggingface/transformers | src/transformers/models/tvp/modeling_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/modeling_tvp.py | Apache-2.0 |
def add_2d_positional_embeddings(self, grid, interpolate_pos_encoding: bool = False):
"""
Args:
grid: (batch_size, height, width, hidden_dim)
interpolate_pos_encoding: (`bool`, *optional*, defaults to `False`):
Whether to interpolate the pre-trained position encod... |
Args:
grid: (batch_size, height, width, hidden_dim)
interpolate_pos_encoding: (`bool`, *optional*, defaults to `False`):
Whether to interpolate the pre-trained position encodings.
Returns:
grid + col_position_embeddings.view(*col_shape): (batch_size, ... | add_2d_positional_embeddings | python | huggingface/transformers | src/transformers/models/tvp/modeling_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/modeling_tvp.py | Apache-2.0 |
def forward(self, grid, interpolate_pos_encoding: bool = False):
"""
Args:
grid: Array of shape (batch_size, num_frames, height, width, num_channels).
It contains processed frames extracted from videos, and is generated by Tvp image preprocessor. Note,
num_fra... |
Args:
grid: Array of shape (batch_size, num_frames, height, width, num_channels).
It contains processed frames extracted from videos, and is generated by Tvp image preprocessor. Note,
num_frames can be 1
interpolate_pos_encoding: (bool, *optional*, defaul... | forward | python | huggingface/transformers | src/transformers/models/tvp/modeling_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/modeling_tvp.py | Apache-2.0 |
def interpolate_pad_encoding(self, prompt: torch.Tensor, height: int, width: int) -> torch.Tensor:
"""
This method allows to interpolate the pre-trained pad weights, to be able to use the model on collection of high
resolution images (high resolution videos).
"""
# creates scal... |
This method allows to interpolate the pre-trained pad weights, to be able to use the model on collection of high
resolution images (high resolution videos).
| interpolate_pad_encoding | python | huggingface/transformers | src/transformers/models/tvp/modeling_tvp.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/tvp/modeling_tvp.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.