Class: Informers::DonutFeatureExtractor
- Inherits:
-
ImageFeatureExtractor
- Object
- FeatureExtractor
- ImageFeatureExtractor
- Informers::DonutFeatureExtractor
- Defined in:
- lib/informers/processors.rb
Instance Attribute Summary
Attributes inherited from FeatureExtractor
Instance Method Summary collapse
Methods inherited from ImageFeatureExtractor
#call, #get_resize_output_image_size, #initialize, #preprocess, #rescale, #resize, #thumbnail
Methods inherited from FeatureExtractor
Constructor Details
This class inherits a constructor from Informers::ImageFeatureExtractor
Instance Method Details
#pad_image(pixel_data, img_dims, pad_size, **options) ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/informers/processors.rb', line 394 def pad_image(pixel_data, img_dims, pad_size, **) _image_height, _image_width, image_channels = img_dims image_mean = @image_mean if !image_mean.is_a?(Array) image_mean = new Array(image_channels, image_mean) end image_std = @image_std if !image_std.is_a?(Array) image_std = new Array(image_channels, image_std) end constant_values = image_mean.map.with_index { |x, i| -x / image_std[i] } super( pixel_data, img_dims, pad_size, center: true, # Since normalization is done after padding, we need to use certain constant values to ensure the same behaviour is observed. # For more information, see https://github.com/huggingface/transformers/blob/main/src/transformers/models/donut/image_processing_donut.py#L433-L451 constant_values: constant_values, ** ) end |