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



886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File 'lib/informers/pipelines.rb', line 886

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