code: def apply_tf_padding(
      features: torch.Tensor, conv_layer: nn.Conv2d
  ) -> torch.Tensor:
      """
      Apply TensorFlow-style "SAME" padding to a convolution layer. See the notes at:
      https://www.tensorflow.org/api_docs/python/tf/nn#notes_on_padding_2
      """
      in_height, in_width = features.shape[-2:]
      stride_height, stride_width = conv_layer.stride
      kernel_height, kernel_width = conv_layer.kernel_size
  
      if in_height % stride_height == 0:
          pad_along_height = max(kernel_height - stride_height, 0)
      else:
          pad_along_height = max(
              kernel_height - (in_height % stride_height), 0
          )
  
      if in_width % stride_width == 0:
          pad_along_width = max(kernel_width - stride_width, 0)
      else:
          pad_along_width = max(
              kernel_width - (in_width % stride_width), 0
          )
  
      pad_left = pad_along_width // 2
      pad_right = pad_along_width - pad_left
      pad_top = pad_along_height // 2
      pad_bottom = pad_along_height - pad_top
  
      padding = (pad_left, pad_right, pad_top, pad_bottom)
      return nn.functional.pad(features, padding, "constant", 0.0)
  
imports: from typing import Optional, Union
  import torch
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttention
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_mobilenet_v1 import MobileNetV1Config
label_desc: Use image node_id 3 for calling a global function with example usage: apply_tf_padding(features, conv_layer) and returns: nn