timm 文件
模型
並獲得增強的文件體驗
開始使用
模型
timm.create_model
< 原始碼 >( model_name: str pretrained: bool = False pretrained_cfg: typing.Union[str, typing.Dict[str, typing.Any], timm.models._pretrained.PretrainedCfg, NoneType] = None pretrained_cfg_overlay: typing.Optional[typing.Dict[str, typing.Any]] = None checkpoint_path: typing.Union[str, pathlib.Path, NoneType] = None cache_dir: typing.Union[str, pathlib.Path, NoneType] = None scriptable: typing.Optional[bool] = None exportable: typing.Optional[bool] = None no_jit: typing.Optional[bool] = None **kwargs: typing.Any )
引數
- model_name — 要例項化的模型名稱。
- pretrained — 如果設定為 True,則載入預訓練的 ImageNet-1k 權重。
- pretrained_cfg — 傳入一個外部的 pretrained_cfg 用於模型。
- pretrained_cfg_overlay — 用這些鍵值對替換基礎 pretrained_cfg 中的值。
- checkpoint_path — 模型初始化*後*要載入的檢查點路徑。
- cache_dir — 覆蓋 Hugging Face Hub 和 Torch 檢查點的模型快取目錄。
- scriptable — 設定層配置,使模型可進行 jit 指令碼化(目前並非所有模型都支援)。
- exportable — 設定層配置,使模型可追蹤/可匯出為 ONNX 格式(尚未完全實現/遵循)。
- no_jit — 設定層配置,使模型不使用 jit 指令碼化層(目前僅限啟用層)。
建立一個模型。
查詢模型的入口函式,並傳遞相關引數以建立一個新模型。
提示:**kwargs 將透過入口函式傳遞給 `timm.models.build_model_with_cfg()`,然後傳遞給模型類的 `__init__()`。在傳遞之前,值為 None 的 kwargs 會被刪減。
關鍵字引數:drop_rate (float): 訓練時分類器的 dropout 率。drop_path_rate (float): 訓練時隨機深度的 drop rate。global_pool (str): 分類器的全域性池化型別。
示例
>>> from timm import create_model
>>> # Create a MobileNetV3-Large model with no pretrained weights.
>>> model = create_model('mobilenetv3_large_100')
>>> # Create a MobileNetV3-Large model with pretrained weights.
>>> model = create_model('mobilenetv3_large_100', pretrained=True)
>>> model.num_classes
1000
>>> # Create a MobileNetV3-Large model with pretrained weights and a new head with 10 classes.
>>> model = create_model('mobilenetv3_large_100', pretrained=True, num_classes=10)
>>> model.num_classes
10
>>> # Create a Dinov2 small model with pretrained weights and save weights in a custom directory.
>>> model = create_model('vit_small_patch14_dinov2.lvd142m', pretrained=True, cache_dir="/data/my-models")
>>> # Data will be stored at */data/my-models/models--timm--vit_small_patch14_dinov2.lvd142m/*
timm.list_models
< 原始碼 >( filter: typing.Union[str, typing.List[str]] = '' module: typing.Union[str, typing.List[str]] = '' pretrained: bool = False exclude_filters: typing.Union[str, typing.List[str]] = '' name_matches_cfg: bool = False include_tags: typing.Optional[bool] = None )
引數
- filter - 適用於 fnmatch 的萬用字元過濾字串 —
- module - 將模型選擇限制在特定子模組(例如 ‘vision_transformer’) —
- pretrained - 如果為 True,則僅包含具有有效預訓練權重的模型 —
- exclude_filters - 在使用 filter 包含模型後,用於排除模型的萬用字元過濾器 —
- name_matches_cfg - 僅包含模型名稱與 default_cfg 名稱匹配的模型(排除一些別名)—
- include_tags - 在模型名稱中包含預訓練標籤(model.tag)。如果為 None,則預設為 — 當 pretrained=True 時設定為 True,否則為 False(預設:None)
返回可用模型名稱列表,按字母順序排序
示例:model_list(‘gluon_resnet*’) — 返回所有以 ‘gluon_resnet’ 開頭的模型 model_list(‘*resnext*’, ‘resnet’) — 返回 ‘resnet’ 模組中所有包含 ‘resnext’ 的模型