Pretrained models for Pytorch
raw JSON → 0.7.4 verified Mon Apr 27 auth: no python maintenance
A library providing pretrained models for PyTorch, including architectures like ResNet, DenseNet, Inception, and more. Version 0.7.4 is the latest release, though the project is in maintenance mode with infrequent updates. It is commonly used for transfer learning and feature extraction, but users should prefer torchvision's model zoo for active support.
pip install pretrainedmodels Common errors
error AttributeError: module 'torch' has no attribute 'irfft' ↓
cause PyTorch 1.9 removed deprecated torch.irfft; used by some models.
fix
Use an older PyTorch version (<=1.8) or avoid models that use irfft (e.g., pnasnet).
error ImportError: cannot import name 'TransformImage' from 'pretrainedmodels.utils' ↓
cause Missing torchvision dependency or incorrect import path.
fix
Install torchvision: pip install torchvision, then from pretrainedmodels import utils.
error RuntimeError: CUDA error: out of memory ↓
cause Model too large for GPU memory or batch size too big.
fix
Reduce batch size, use model.half() for half precision, or switch to CPU.
error SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ↓
cause SSL issues when downloading pretrained weights from the internet.
fix
Set environment variable CURL_CA_BUNDLE to a valid cert bundle or use pretrainedmodels.models.__dict__['model_name'](pretrained=False) to skip download.
Warnings
deprecated pretrainedmodels is in maintenance mode; many models are outdated and may not work with newer PyTorch versions. Prefer torchvision's model zoo or timm. ↓
fix Switch to torchvision.models or the timm library.
gotcha The pretrained='imagenet' argument may fail silently if checkpoint not found. Always verify the model downloads correctly. ↓
fix Check network connectivity or manually download pretrained weights from the official repository.
gotcha Model input sizes vary; not all models accept 224x224 images. Use utils.TransformImage to get the correct preprocessing. ↓
fix Always use pretrainedmodels.utils.TransformImage(model) to get the right transforms.
breaking PyTorch 1.9+ may cause compatibility issues with older model definitions. You may see AttributeError: module 'torch' has no attribute 'irfft'. ↓
fix Use torchvision or timm instead. Or pin PyTorch to 1.8.x.
Imports
- pretrainedmodels wrong
from pretrainedmodels import ...correctimport pretrainedmodels - models
from pretrainedmodels import models
Quickstart
import torch
import pretrainedmodels
model = pretrainedmodels.__dict__['resnet101'](pretrained='imagenet')
model.eval()
print(model)
# Example inference
from pretrainedmodels import utils
import torchvision.transforms as transforms
tf = utils.TransformImage(model)
input_tensor = torch.randn(1, 3, 224, 224)
out = model(input_tensor)
print(out.shape)