Class: Informers::AutoProcessor

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

Constant Summary collapse

FEATURE_EXTRACTOR_CLASS_MAPPING =
{
  "ViTFeatureExtractor" => ViTFeatureExtractor,
  "OwlViTFeatureExtractor" => OwlViTFeatureExtractor,
  "CLIPFeatureExtractor" => CLIPFeatureExtractor,
  "DPTFeatureExtractor" => DPTFeatureExtractor,
  "DetrFeatureExtractor" => DetrFeatureExtractor,
  "Swin2SRImageProcessor" => Swin2SRImageProcessor,
  "DonutFeatureExtractor" => DonutFeatureExtractor
}
PROCESSOR_CLASS_MAPPING =
{}

Class Method Summary collapse

Class Method Details

.from_pretrained(pretrained_model_name_or_path, progress_callback: nil, config: nil, cache_dir: nil, local_files_only: false, revision: "main", **kwargs) ⇒ Object



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
# File 'lib/informers/processors.rb', line 756

def self.from_pretrained(
  pretrained_model_name_or_path,
  progress_callback: nil,
  config: nil,
  cache_dir: nil,
  local_files_only: false,
  revision: "main",
  **kwargs
)
  preprocessor_config = config || Utils::Hub::get_model_json(pretrained_model_name_or_path, "preprocessor_config.json", true,
    progress_callback:,
    config:,
    cache_dir:,
    local_files_only:,
    revision:
  )

  # Determine feature extractor class
  # TODO: Ensure backwards compatibility with old configs
  key = preprocessor_config["feature_extractor_type"] || preprocessor_config["image_processor_type"]
  feature_extractor_class = FEATURE_EXTRACTOR_CLASS_MAPPING[key]

  if !feature_extractor_class
    if preprocessor_config["size"]
      # Assume ImageFeatureExtractor
      warn "Feature extractor type #{key.inspect} not found, assuming ImageFeatureExtractor due to size parameter in config."
      feature_extractor_class = ImageFeatureExtractor
    else
      raise Error, "Unknown Feature Extractor type: #{key}"
    end
  end

  # If no associated processor class, use default
  processor_class = PROCESSOR_CLASS_MAPPING[preprocessor_config["processor_class"]] || Processor

  # Instantiate processor and feature extractor
  feature_extractor = feature_extractor_class.new(preprocessor_config)
  processor_class.new(feature_extractor)
end