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

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

我无法从 torchvision 导入 mobilenet_v3_small。我有以下代码:

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)

我遇到错误:

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

我有以下版本:

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 版本为 3.7

mobilenet_v3_small 在 torchvision 0.8.1 中不可用。如果你想使用它你需要升级到 0.10.0(稳定版)或至少 0.9.0.