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,
  "WhisperFeatureExtractor" => WhisperFeatureExtractor,
  "Wav2Vec2FeatureExtractor" => Wav2Vec2FeatureExtractor,
  "ClapFeatureExtractor" => ClapFeatureExtractor
}
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



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'lib/informers/processors.rb', line 816

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