导入错误:无法从'torch._six'导入名称'int_classes'(/usr/local/lib/python3.7/dist-packages/torch/_six.py)



我正在研究用于图像分割的医疗保健图像数据集。更具体地说,是使用PyTorch进行脊髓灰质分割"。当我尝试安装库最初使用以下代码:

!Pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-linux_x86_64.whl

!Pip3 install torchvision

!PIP安装medicaltorch

!Pip3 install numpy==1.14.1

显示了一些错误,要求满足如下:

1日截图

2日截图

然后导入库:

from collections import defaultdict
import time
import os
import numpy as np
from tqdm import tqdm
from medicaltorch import datasets as mt_datasets
from medicaltorch import models as mt_models
from medicaltorch import transforms as mt_transforms
from medicaltorch import losses as mt_losses
from medicaltorch import metrics as mt_metrics
from medicaltorch import filters as mt_filters
import torch
from torchvision import transforms
from torch.utils.data import DataLoader
from torch import autograd, optim
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torchvision.utils as vutils
cudnn.benchmark = True
import matplotlib.pyplot as plt
%matplotlib inline

这个导入会抛出如下错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-80b8c583d1fe> in <module>()
20 
21 
---> 22 from medicaltorch import datasets as mt_datasets
23 from medicaltorch import models as mt_models
24 from medicaltorch import transforms as mt_transforms
/usr/local/lib/python3.7/dist-packages/medicaltorch/datasets.py in <module>()
11 from torch.utils.data import Dataset
12 import torch
---> 13 from torch._six import string_classes, int_classes
14 
15 from PIL import Image
ImportError: cannot import name 'int_classes' from 'torch._six' (/usr/local/lib/python3.7/dist-packages/torch/_six.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
有人能帮我解决这个问题吗?

在pytorch 1.9中去掉了torch._six中的int_classes变量。facebookresearch/TimeSformer # 47请使用以下代码。

from torch._six import string_classes
int_classes = (bool, int)

查看来源:https://github.com/visionml/pytracking/issues/272

相关内容

  • 没有找到相关文章

最新更新