在用于执行随机梯度下降的函数中,我在所有批次和批次中的所有输入-输出对上都有这个循环:
train_points_loader = DataLoader(train_points, batch_size=64, shuffle=True, num_workers=1)
for batch, (X, y) in enumerate(train_points_loader):
o.zero_grad() # setting gradient to zeros
pred = model(X) # get predictions through forward pass
loss = l(pred, y) # compute the loss
loss.backward() # backward propagation
o.step() # update the gradient to new gradients
我正在使用以下 pytorch 模型:
model = nn.Sequential(
nn.Flatten(),
nn.Linear(input_size, hidden_layers[0]),
nn.ReLU(),
nn.Linear(hidden_layers[0], hidden_layers[1]),
nn.ReLU(),
nn.Linear(hidden_layers[1], output_size)
)
当我运行函数内部的循环时,错误是:
<ipython-input-24-a177ccf6125b> in train_loop(train_data_loader,
model, epochs, learning_rate, optimizer, loss)
21 running_accuracy = 0.
22 # loop over all batches and over all input-output pair within a
batch
---> 23 for batch, (X, y) in enumerate(train_data_loader):
24
25 o.zero_grad() # setting gradient to zeros
ValueError: too many values to unpack (expected 2)
谢谢您的回答