import torch
from torch import nn
import torchvision
from torch.nn import Flatten, Conv2d, MaxPool2d, Linear, Sequential
from Pytorch.nn_cov2d import DataLoader
dataset=torchvision.datasets.CIFAR10("../dataset",train=False,transform=torchvision.transforms.ToTensor()
,download=True)
dataloader=DataLoader(dataset,batch_size=1)
class Tudui(nn.Module):
def __init__(self):
super(Tudui, self).__init__()
self.model1=Sequential(
Conv2d(3,32,5,padding=2),
MaxPool2d(2),
Conv2d(32, 32, 5, padding=2),
MaxPool2d(2),
Conv2d(32, 64, 5, padding=2),
MaxPool2d(2),
Flatten(),
Linear(1024, 64),
Linear(64, 10)
)
def forward(self,x):
x=self.model1(x)
return x
Loss=nn.CrossEntropyLoss()
tudui=Tudui()
for data in dataloader:
imgs,target=data
outputs=tudui(imgs)
result_loss=Loss(outputs,target)
print(result_loss)
错误信息为:Traceback (most recent call last):
File "D:\pythonlearning\Pytorch\nn_lossfunctionnetwork.py", line 9, in <module>
dataloader=DataLoader(dataset,batch_size=1)
TypeError: 'DataLoader' object is not callable
这个是哪里出现了问题