Abstract image processor arg checks.
What does this PR do?
This refactors existing image processor argument checks that sprawl out on all existing models that have an ImageProcessor.
Lines such as
if do_resize is not None and size is None:
raise ValueError("Size and max_size must be specified if do_resize is True.")
if do_rescale is not None and rescale_factor is None:
raise ValueError("Rescale factor must be specified if do_rescale is True.")
if do_normalize is not None and (image_mean is None or image_std is None):
raise ValueError("Image mean and std must be specified if do_normalize is True.")
can be abstracted away in a validate... function residing in image_utils.
Also, fixing (when it doesn't break BC) some cases where existence of arguments is checked, but the actual preprocess method doesn't seem to call them. bridgetower doesn't pass center_crop from init, chinese_clip does not convert_to_rgb, and so on.
Who can review?
@amyeroberts
Also linked to #28711 as I discovered logic flow issues here, seems fitting to abstract them separately and deal with the actual processing in the main PR. Here I'll try to stick to verifications and fix what's necessary to satisfy existing tests.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
@amyeroberts I think it's ok to take another look at this one now! Improved a few things, didn't add much, will rebase the other refactor off of that one