Here is an implementation:
  
      github.com
  
  
    jimmysue/xvision/blob/main/xvision/ops/extract_glimpse.py#L14 7

from typing import Union, Tuple

"""
tf.image.extract_glimpse(
    input, size, offsets, centered=True, normalized=True, noise='uniform',
    name=None
)
"""


def extract_glimpse(input: torch.Tensor, size: Tuple[int, int], offsets, centered=True, normalized=True, mode='bilinear'):
    # similar usage with ft.image.extract_glimpse:
    #   https://www.tensorflow.org/api_docs/python/tf/image/extract_glimpse
    # input: [B, C, H, W]
    # size:  [int, int]  specified the size of glimpse, height comes first
    # offsets: [B, 2]
    W, H = input.size(-1), input.size(-2)

    if normalized and centered:
        offsets = (offsets + 1) * offsets.new_tensor([W/2, H/2])
    elif normalized: