Class: Transformers::ImageFeatureExtractionPipeline
- Inherits:
-
Pipeline
- Object
- Pipeline
- Transformers::ImageFeatureExtractionPipeline
show all
- Defined in:
- lib/transformers/pipelines/image_feature_extraction.rb
Instance Method Summary
collapse
Methods inherited from Pipeline
#call, #check_model_type, #get_iterator, #initialize, #torch_dtype
Instance Method Details
#_forward(model_inputs) ⇒ Object
31
32
33
34
|
# File 'lib/transformers/pipelines/image_feature_extraction.rb', line 31
def _forward(model_inputs)
model_outputs = @model.(**model_inputs)
model_outputs
end
|
#_sanitize_parameters(image_processor_kwargs: nil, return_tensors: nil, pool: nil, **kwargs) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/transformers/pipelines/image_feature_extraction.rb', line 3
def _sanitize_parameters(image_processor_kwargs: nil, return_tensors: nil, pool: nil, **kwargs)
preprocess_params = image_processor_kwargs.nil? ? {} : image_processor_kwargs
postprocess_params = {}
if !pool.nil?
postprocess_params[:pool] = pool
end
if !return_tensors.nil?
postprocess_params[:return_tensors] = return_tensors
end
if kwargs.include?(:timeout)
preprocess_params[:timeout] = kwargs[:timeout]
end
[preprocess_params, {}, postprocess_params]
end
|
#postprocess(model_outputs, pool: nil, return_tensors: false) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/transformers/pipelines/image_feature_extraction.rb', line 36
def postprocess(model_outputs, pool: nil, return_tensors: false)
pool = !pool.nil? ? pool : false
if pool
raise Todo
else
outputs = model_outputs[0]
end
if return_tensors
return outputs
end
if @framework == "pt"
outputs.to_a
else
raise Todo
end
end
|
#preprocess(image, timeout: nil, **image_processor_kwargs) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/transformers/pipelines/image_feature_extraction.rb', line 21
def preprocess(image, timeout: nil, **image_processor_kwargs)
image = ImageUtils.load_image(image, timeout: timeout)
model_inputs = @image_processor.(image, return_tensors: @framework, **image_processor_kwargs)
if @framework == "pt"
end
model_inputs
end
|