in src/models/auto/processing_auto.js [44:84]
static async from_pretrained(pretrained_model_name_or_path, options={}) {
// TODO: first check for processor.json
const preprocessorConfig = await getModelJSON(pretrained_model_name_or_path, IMAGE_PROCESSOR_NAME, true, options);
const { image_processor_type, feature_extractor_type, processor_class } = preprocessorConfig;
if (processor_class && AllProcessors[processor_class]) {
return AllProcessors[processor_class].from_pretrained(pretrained_model_name_or_path, options);
}
if (!image_processor_type && !feature_extractor_type) {
throw new Error('No `image_processor_type` or `feature_extractor_type` found in the config.');
}
const components = {};
if (image_processor_type) {
// Some image processors are saved with the "Fast" suffix, so we remove that if present.
const image_processor_class = AllImageProcessors[image_processor_type.replace(/Fast$/, '')];
if (!image_processor_class) {
throw new Error(`Unknown image_processor_type: '${image_processor_type}'.`);
}
components.image_processor = new image_processor_class(preprocessorConfig);
}
if (feature_extractor_type) {
const image_processor_class = AllImageProcessors[feature_extractor_type];
if (image_processor_class) {
// Handle legacy case where image processors were specified as feature extractors
components.image_processor = new image_processor_class(preprocessorConfig);
} else {
const feature_extractor_class = AllFeatureExtractors[feature_extractor_type];
if (!feature_extractor_class) {
throw new Error(`Unknown feature_extractor_type: '${feature_extractor_type}'.`);
}
components.feature_extractor = new feature_extractor_class(preprocessorConfig);
}
}
const config = {};
return new Processor(config, components, null);
}