Class: Transformers::BaseImageProcessor

Inherits:
ImageProcessingMixin show all
Defined in:
lib/transformers/image_processing_utils.rb

Direct Known Subclasses

Vit::ViTImageProcessor

Instance Method Summary collapse

Methods inherited from ImageProcessingMixin

from_dict, from_pretrained, get_image_processor_dict

Constructor Details

#initialize(**kwargs) ⇒ BaseImageProcessor

Returns a new instance of BaseImageProcessor.



17
18
19
# File 'lib/transformers/image_processing_utils.rb', line 17

def initialize(**kwargs)
  super(**kwargs)
end

Instance Method Details

#call(images, **kwargs) ⇒ Object



21
22
23
# File 'lib/transformers/image_processing_utils.rb', line 21

def call(images, **kwargs)
  preprocess(images, **kwargs)
end

#normalize(image, mean, std, data_format: nil, input_data_format: nil, **kwargs) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/transformers/image_processing_utils.rb', line 39

def normalize(
  image,
  mean,
  std,
  data_format: nil,
  input_data_format: nil,
  **kwargs
)
  ImageTransforms.normalize(
    image, mean, std, data_format: data_format, input_data_format: input_data_format, **kwargs
  )
end

#preprocess(images, **kwargs) ⇒ Object

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/transformers/image_processing_utils.rb', line 25

def preprocess(images, **kwargs)
  raise NotImplementedError, "Each image processor must implement its own preprocess method"
end

#rescale(image, scale, data_format: nil, input_data_format: nil, **kwargs) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/transformers/image_processing_utils.rb', line 29

def rescale(
  image,
  scale,
  data_format: nil,
  input_data_format: nil,
  **kwargs
)
  ImageTransforms.rescale(image, scale, data_format: data_format, input_data_format: input_data_format, **kwargs)
end