【发布时间】:2022-08-04 05:21:44
【问题描述】:
我一直在编写代码来训练和测试图像数据集。但是我在每个实例中都会收到此错误输出 = 模型(图像)
class ConvNeuralNet(nn.Module):
# Determine what layers and their order in CNN object
def __init__(self, num_classes):
super(ConvNeuralNet, self).__init__()
self.conv_layer1 = nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3)
self.conv_layer2 = nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3)
self.max_pool1 = nn.MaxPool2d(kernel_size = 2, stride = 2)
self.conv_layer3 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3)
self.conv_layer4 = nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3)
self.max_pool2 = nn.MaxPool2d(kernel_size = 2, stride = 2)
self.fc1 = nn.Linear(1600, 128)
self.relu1 = nn.ReLU()
self.fc2 = nn.Linear(128, num_classes)
for i, (images, labels) in enumerate(train_loader):
# Move tensors to the configured device
device = torch.device(\'cpu\')
images = images.to(device)
labels = labels.to(device)
# Forward pass
outputs = model(images)
loss = criterion(outputs, labels)
# Backward and optimize
optimizer.zero_grad()
loss.backward()
optimizer.step()
print(\'Epoch [{}/{}], Loss: {:.4f}\'.format(epoch+1, num_epochs, loss.item()))
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _forward_unimplemented(self, *input) 199 registered hooks while the latter silently ignores them. 200 \"\"\" --> 201 raise NotImplementedError 202 203
未实现错误: 我已经检查过没有缩进错误,所以我不明白这里出了什么问题。
标签: python deep-learning pytorch