Class: Informers::DepthEstimationPipeline

Inherits:
Pipeline
  • Object
show all
Defined in:
lib/informers/pipelines.rb

Instance Method Summary collapse

Methods inherited from Pipeline

#initialize

Constructor Details

This class inherits a constructor from Informers::Pipeline

Instance Method Details

#call(images) ⇒ Object



1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
# File 'lib/informers/pipelines.rb', line 1015

def call(images)
  prepared_images = prepare_images(images)

  inputs = @processor.(prepared_images)
  predicted_depth = @model.(inputs)[0]

  to_return = []
  prepared_images.length.times do |i|
    prediction = Utils.interpolate(predicted_depth[i], prepared_images[i].size.reverse, "bilinear", false)
    max_prediction = Utils.max(prediction.flatten)[0]
    formatted =
      prediction.map do |v|
        v.map do |v2|
          v2.map do |v3|
            (v3 * 255 / max_prediction).round
          end
        end
      end
    to_return << {
      predicted_depth: predicted_depth[i],
      depth: Utils::RawImage.from_array(formatted).image
    }
  end
  to_return.length > 1 ? to_return : to_return[0]
end