Error finding processor's image class. Loading based on pattern matching with feature extractor

Not sure where this warning is coming from or how to address it. Using the DONUT model. Full message below

Could not find image processor class in the image processor config or the model config. Loading based on pattern matching with the model's feature extractor configuration.
/opt/miniconda3/envs/donut/lib/python3.10/site-packages/transformers/models/donut/processing_donut.py:186: FutureWarning: `feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.
3 Likes

Same here, would love to know the answer

3 Likes

I am using TrOCRProcessor and giving the same message
Could not find image processor class in the image processor config or the model config. Loading based on pattern matching with the model's feature extractor configuration.

Getting the same error using Swin Transformers

2 Likes

Getting the same error while using facebook/detr-resnet-50.
Was anyone able to solve it?

I think this has something to do with processor. While saving the model weights you are supposed to save the config related files as well. so don’t forget to do this:

processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-printed")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-printed")

# do some config changes...
# train or whatever

processor.save_pretrained('test')
model.save_pretrained('test')

and then load it from test. I guess you won’t see this line then.

cc @amyeroberts

Was able to suppress the warning using transformers.utils.logging.set_verbosity_error()
Not sure how to actually the solve the issue so that warning isn’t generated in the first place.

Hi everyone, thanks for reporting about this.

The message:

Could not find image processor class in the image processor config or the model config. Loading based on pattern matching with the model's feature extractor configuration.

is being shown, because the image processor to load is being inferred from a config which specifies a feature extractor. Feature extractors are now deprecated for vision models. For example, this swin configuration specifies ViTFeatureExtractor. The warning is there as there isn’t a guarantee the correct image processor class will be loaded.

The inference of the image processor from the feature extractor name is done, as this allows for a smooth deprecation cycle of the feature extractors, where older configs can be used without breaking changes.

We realise that the warning message can be both concerning and overly aggressive. Its visibility was in part to make explicit the deprecation and encourage the update of custom checkpoint configurations. We’re trying to find the right balance between warning now loudly vs. more silent but possibly unexpected behaviour later. For many public configs it’s not something an individual user would be able to update at the moment, and so downgrading to logger.info might be a suitable option. Please do share if you have alternative suggestions e.g. alternative warning message to make it clearer.

4 Likes

What is the recommendation to update the config.json file to avoid such a warning? I would tend to agree with your point that using public models takes away the user’s control subdue the warning. Info might be more appropriate.

As mentioned HERE using a different version of transformers==4.28.0 helped for Swin Transformers,

1 Like

I don’t know if this helps you anymore bc. time has passed on. But - if you’d like to update custom model preprocessor_config.json - files to the latest expected image_processor - object notation, then you can simply replace the “feature_extractor_type” by “image_processor_type” in the respective config-file. For your example (DONUT), the new preprocessor_config.json would now read as: “image_processor_type”: “DonutImageProcessor” at the line previously filled with the “feature_extractor_type” – description.
HTH!