我正在按照此链接使用 PyTorch(使用 CIFAR-10 数据集)学习图像分类。
我试图理解给定Conv2d代码的输入和输出参数:
import torch.nn as nn
import torch.nn.functional as F
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 3.8。我有以下清单:
[['Bangalore', 116.0], ['Mumbai', 132.0], ['Kolkata', 234.0]]
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个节点并添加到successors列表中,如下所示:
successors = [<__main__.Node object at 0x7f89582eb7c0>, <__main__.Node object at 0x7f89582eb790>, <__main__.Node object at 0x7f89582eb7f0>]
Run Code Online (Sandbox Code Playgroud)
我创建了一个边缘列表并添加每个后继节点。之后根据距离值对其进行排序。我收到错误 -'<' not supported between instances of 'node' and 'node'
for succ_node in successors:
fringe.append(succ_node)
fringe.sort() <- Error Here
Run Code Online (Sandbox Code Playgroud)
这是我的节点类:
class Node:
def __init__(self, parent, name, g):
self.parent = parent
self.name = name
self.g = g
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?