1.不能导入pillow_version
Traceback (most recent call last):
File "D:\code\pythonProject2023\pytorch\MulClass.py", line 3, in <module>
from torchvision import transforms # 图像原始处理的包
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torchvision\__init__.py", line 2, in <module>
from torchvision import datasets
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torchvision\datasets\__init__.py", line 9, in <module>
from .fakedata import FakeData
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torchvision\datasets\fakedata.py", line 3, in <module>
from .. import transforms
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torchvision\transforms\__init__.py", line 1, in <module>
from .transforms import *
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torchvision\transforms\transforms.py", line 17, in <module>
from . import functional as F
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torchvision\transforms\functional.py", line 5, in <module>
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (D:\install\anaconda\envs\pytorch\lib\site-packages\PIL\__init__.py)
原因:pillow版本过高
解决:修改模块文件(https://blog.csdn.net/BBJG_001/article/details/104369234)
from PIL import Image, ImageOps, ImageEnhance, __version__
在Pycharm中修改时会眺出警告,确认就能修改了
但是只有这样还是不够的,因为在下面的程序中用到的还是PILLOW_VERSION这个变量,然后我又做了这样一个操作
PILLOW_VERSION=__version__
注意这一句要放在所有用到PILLOW_VERSION变量的语句之前,我是把这句紧跟在了了所有导入操作之后
2.该张量含有多个(1个以上不含1个)boolean值,是不明确的,即无法比较
Traceback (most recent call last):
File "D:\code\pythonProject2023\pytorch\MulClass.py", line 82, in <module>
train(epoch)
File "D:\code\pythonProject2023\pytorch\MulClass.py", line 59, in train
loss = criterion(outputs, target)
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 911, in __init__
super(CrossEntropyLoss, self).__init__(weight, size_average, reduce, reduction)
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 19, in __init__
super(_WeightedLoss, self).__init__(size_average, reduce, reduction)
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 12, in __init__
self.reduction = _Reduction.legacy_get_string(size_average, reduce)
File "D:\install\anaconda\envs\pytorch\lib\site-packages\torch\nn\_reduction.py", line 36, in legacy_get_string
if size_average and reduce:
RuntimeError: bool value of Tensor with more than one value is ambiguous
原因:loss函数申明没有加括号
修改:criterion = torch.nn.CrossEntropyLoss()
3.整数型没有属性view
AttributeError: ‘int’ object has no attribute ‘view’
原因:不确定
修改:将测试从
for data in enumerate(train_loader, 0):
改为
for data in test_loader: