pythonpytorchpre-trained-modelmobilenet

AttributeError: module 'torchvision.models' has no attribute 'mobilenet_v3_small'


I am unable to import mobilenet_v3_small from torchvision. I have the below code:

import torch
import torch.nn as nn
import torch.utils.data
from torch.autograd import Variable
import torch.nn.functional as F
import math
import numpy as np
import torchvision.models as models

class feature_extraction(nn.Module):
    def __init__(self):
        super().__init__()
        
        self.mobilenet = models.mobilenet_v3_small(pretrained=True)

I am getting the error:

self.mobilenet = models.mobilenet_v3_small(pretrained=True)
AttributeError: module 'torchvision.models' has no attribute 'mobilenet_v3_small'

I have the below versions:

cudatoolkit               11.0.221             h6bb024c_0
torch                     1.7.0                    pypi_0    pypi
torchaudio                0.7.2                      py37    pytorch
torchvision               0.8.1                    pypi_0    pypi

Python version is 3.7


Solution

  • mobilenet_v3_small is not available in torchvision 0.8.1. If you want to use it you need to upgrade to 0.10.0 (stable version) or at least 0.9.0.