1
canxun OP wuhu
|
2
coderluan 2021-11-26 11:47:42 +08:00
# 从测试集里面拿出几张图片
images,labels = next(iter(test_loader)) 改成 images=cv2.imread("2.jpg") |
3
canxun OP @coderluan File "d:/pycode/.vscode/Untitled-1.py", line 107, in <module>
imshow(images) File "d:/pycode/.vscode/Untitled-1.py", line 51, in imshow img = torchvision.utils.make_grid(images) File "C:\ruanjian\python\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context return func(*args, **kwargs) File "C:\ruanjian\python\lib\site-packages\torchvision\utils.py", line 46, in make_grid raise TypeError(f'tensor or list of tensors expected, got {type(tensor)}') TypeError: tensor or list of tensors expected, got <class 'NoneType'> |
4
canxun OP 11
|
5
imn1 2021-12-05 13:40:27 +08:00
你要将
test_loader = torch.utils.data.DataLoader( datasets.MNIST(root = 'data', train = False, download = True, transform = tsfrm), batch_size = BATCH_SIZE, shuffle = True) 这句改成函数,参数就是里面的'data',并返回 test_loader 这句 是从 data 目录获取文件的,如果你要改成单文件,就要看手册 torch.utils.data.DataLoader 是否提供这个功能 不提供的话,你就需要把指定文件扔进某个目录,并把目录路径传给 root 这个位置 |