AutoModelForImageClassification
Last updated
Last updated
( *args**kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a image classification head) when created with the class method or the class method.
This class cannot be instantiated directly using __init__()
(throws an error).
from_config
( **kwargs )
Parameters
config () — The model class to instantiate is selected based on the configuration class:
configuration class: (BEiT model)
configuration class: (BiT model)
configuration class: (ConvNeXT model)
configuration class: (ConvNeXTV2 model)
configuration class: (CvT model)
configuration class: (Data2VecVision model)
configuration class: or (DeiT model)
configuration class: (DiNAT model)
configuration class: (DINOv2 model)
configuration class: or (EfficientFormer model)
configuration class: (EfficientNet model)
configuration class: (FocalNet model)
configuration class: (ImageGPT model)
configuration class: or (LeViT model)
configuration class: (MobileNetV1 model)
configuration class: (MobileNetV2 model)
configuration class: (MobileViT model)
configuration class: (MobileViTV2 model)
configuration class: (NAT model)
configuration class: or or (Perceiver model)
configuration class: (PoolFormer model)
configuration class: (PVT model)
configuration class: (RegNet model)
configuration class: (ResNet model)
configuration class: (SegFormer model)
configuration class: (SwiftFormer model)
configuration class: (Swin Transformer model)
configuration class: (Swin Transformer V2 model)
configuration class: (VAN model)
configuration class: (ViT model)
configuration class: (ViT Hybrid model)
configuration class: (ViTMSN model)
Instantiates one of the model classes of the library (with a image classification head) from a configuration.
Examples:
Copied
from_pretrained
( *model_args**kwargs )
Parameters
pretrained_model_name_or_path (str
or os.PathLike
) — Can be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like bert-base-uncased
, or namespaced under a user or organization name, like dbmdz/bert-base-german-cased
.
A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) — Will be passed along to the underlying model __init__()
method.
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model is loaded by supplying a local directory as pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.
cache_dir (str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
from_tf (bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument).
force_download (bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
resume_download (bool
, optional, defaults to False
) — Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.
proxies (Dict[str, str]
, optional) — A dictionary of proxy servers to use by protocol or endpoint, e.g., {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}
. The proxies are used on each request.
output_loading_info(bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.
local_files_only(bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model).
revision (str
, optional, defaults to "main"
) — The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision
can be any identifier allowed by git.
trust_remote_code (bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine.
code_revision (str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision
can be any identifier allowed by git.
kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
If a configuration is provided with config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)
Instantiate one of the model classes of the library (with a image classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
The model is set in evaluation mode by default using model.eval()
(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode with model.train()
Examples:
Copied
Note: Loading a model from its configuration file does not load the model weights. It only affects the model’s configuration. Use to load the model weights.
A path to a directory containing model weights saved using , e.g., ./my_model_directory/
.
config (, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model was saved using and is reloaded by supplying the save directory.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using and is not a simpler option.
If a configuration is not provided, kwargs
will be first passed to the configuration class initialization function (). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.
beit — (BEiT model)
bit — (BiT model)
convnext — (ConvNeXT model)
convnextv2 — (ConvNeXTV2 model)
cvt — (CvT model)
data2vec-vision — (Data2VecVision model)
deit — or (DeiT model)
dinat — (DiNAT model)
dinov2 — (DINOv2 model)
efficientformer — or (EfficientFormer model)
efficientnet — (EfficientNet model)
focalnet — (FocalNet model)
imagegpt — (ImageGPT model)
levit — or (LeViT model)
mobilenet_v1 — (MobileNetV1 model)
mobilenet_v2 — (MobileNetV2 model)
mobilevit — (MobileViT model)
mobilevitv2 — (MobileViTV2 model)
nat — (NAT model)
perceiver — or or (Perceiver model)
poolformer — (PoolFormer model)
pvt — (PVT model)
regnet — (RegNet model)
resnet — (ResNet model)
segformer — (SegFormer model)
swiftformer — (SwiftFormer model)
swin — (Swin Transformer model)
swinv2 — (Swin Transformer V2 model)
van — (VAN model)
vit — (ViT model)
vit_hybrid — (ViT Hybrid model)
vit_msn — (ViTMSN model)