Class: Informers::Swin2SRImageProcessor

Inherits:
ImageFeatureExtractor show all
Defined in:
lib/informers/processors.rb

Instance Method Summary collapse

Methods inherited from ImageFeatureExtractor

#call, #get_resize_output_image_size, #initialize, #preprocess, #rescale, #resize, #thumbnail

Methods inherited from FeatureExtractor

#initialize

Constructor Details

This class inherits a constructor from Informers::ImageFeatureExtractor

Instance Method Details

#pad_image(pixel_data, img_dims, pad_size, **options) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/informers/processors.rb', line 368

def pad_image(pixel_data, img_dims, pad_size, **options)
  # NOTE: In this case, `padSize` represents the size of the sliding window for the local attention.
  # In other words, the image is padded so that its width and height are multiples of `padSize`.
  image_height, image_width, _image_channels = img_dims

  super(
    pixel_data,
    img_dims,
    {
      # NOTE: For Swin2SR models, the original python implementation adds padding even when the image's width/height is already
      # a multiple of `pad_size`. However, this is most likely a bug (PR: https://github.com/mv-lab/swin2sr/pull/19).
      # For this reason, we only add padding when the image's width/height is not a multiple of `pad_size`.
      width: image_width + (pad_size - image_width % pad_size) % pad_size,
      height: image_height + (pad_size - image_height % pad_size) % pad_size
    },
    mode: "symmetric",
    center: false,
    constant_values: -1,
    **options
  )
end