Watson生成的Pythorch结果为:“ValueError:优化器获得空参数列表”

2024-04-25 22:36:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在试验沃森神经网络模型。在

我从内置的演示“MNIST上的单个卷积层”创建了一个模型。我所做的唯一定制就是指定培训数据文件。在

enter image description here

然后,我导出了Pytorch代码,并尝试在本地计算机上运行。在

生成的代码非常可读。相关代码摘录如下:

# Define network architecture
class Net(nn.Module):
    def __init__(self, inp_c):
        super(Net, self).__init__()

    def forward(self, ImageData_4, target):

        Convolution2D_9 = self.Convolution2D_9(ImageData_4)
        ReLU_1 = self.ReLU_1(Convolution2D_9)
        Pooling2D_8 = self.Pooling2D_8(ReLU_1)
        Flatten_2 = Pooling2D_8.view(-1, 10816)
        Dense_3 = self.Dense_3(Flatten_2)
        Softmax_5 = self.Softmax_5(Dense_3)
        Accuracy_6 = torch.topk(Softmax_5, 1)[0]
        CrossEntropyLoss_7 = self.CrossEntropyLoss_7(Softmax_5, target)
        return Softmax_5, Accuracy_6

# Model Initialization
inp_c = 1
model = Net(inp_c)
model.cuda()

# Define optimizer
learning_rate = 0.001000
decay = 0.000000
beta_1 = 0.900000
beta_2 = 0.999000
optim = optim.Adam(
    model.parameters(),
    lr=learning_rate,
    betas=(beta_1, beta_2),
    weight_decay=decay)

我得到了一个错误:

^{pr2}$

optim = optim.Adam()语句上。在

那边有没有沃森的用户/专家来解释这个问题?我基本上是在运行演示。它本不该失败的。在

谢谢!在


Tags: 代码模型selfnetmodeloptimbetadense