Class: Clip::ImagePreprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/clip/image_preprocessor.rb

Constant Summary collapse

MEAN =

CLIP’s expected image normalization parameters

Numo::DFloat[*[ 0.48145466, 0.4578275, 0.40821073 ]
STD =

Instance Method Summary collapse

Constructor Details

#initialize(target_size: 224) ⇒ ImagePreprocessor

Returns a new instance of ImagePreprocessor.



10
11
12
# File 'lib/clip/image_preprocessor.rb', line 10

def initialize(target_size: 224)
  @target_size = target_size
end

Instance Method Details

#preprocess(image_path) ⇒ Object

Preprocess the image and return a tensor with shape [batch_size, 3, 224, 224]



15
16
17
18
19
20
# File 'lib/clip/image_preprocessor.rb', line 15

def preprocess(image_path)
  image = load_and_resize(image_path)
  tensor = image_to_tensor(image)
  normalized = normalize(tensor)
  add_batch_dimension(normalized)
end