-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Exploring use of kwargs for timm model and transforms creation #35819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I though this could also be neat to wire through in the image classification example script, though not quite sure how to add the args to HfArgumentParser, would be least obtrusive if a --model-kwargs and --preprocessor-kwargs could be added that'd pass through lists of key-value pairs as kwargs to the AutoModel and AutoImageProcessor... |
Not sure who else would have opinions re the example scripts, this could allow all the advanced timm augmentations, and also enabling of some model regularization like stochastic depth (e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating! Can you please add test cases?
} | ||
|
||
# Merge kwargs that should be passed through to timm transform factory into image_processor_dict | ||
for k in _DATA_ARG_KEYS + tuple(inspect.signature(timm.data.create_transform).parameters.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to have a variable for tuple(inspect.signature(timm.data.create_transform).parameters.keys())
, easier to read and debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qubvel changed that code a little in last commit
* default to train input size (less surprising) * add properties to mimic .size .crop_size .image_mean .image_std attributes in many Transformers image preproc (works with autotrain now) * try to make key check / inspect code more clear
I added properties to the image processor so use cases where people were read image_processor.size, image_processor.image_mean, etc will work. autotrain relied on this and now it works with timm models. |
Great! Can you please add some test cases to |
I'll get to this eventually, I wanted to explore the use cases a bit more with some notebooks, train runs and see if any other changes are worthwhile. |
What does this PR do?
Allow kwargs to be passed through to timm create_model and create_transforms fns via the TimmWrapperModel and TimmWrapperImageProcessor classes respectively.
Current exploring use and not ready to finalize. Would like to allow flexibility to configure model and transforms at runtime for added flexibility.
Examples:
Allow dynamic image size for vits
model = AutoModelForImageClassification.from_pretrained("timm/vit_base_patch16_224.augreg2_in21k_ft_in1k", dynamic_img_size=True)
Change image size of pre-processor
Customize image transforms, this will enable auto_augment and rand-erasing in train transforms and use the train resolution instead of test target size for eval transform