I am trying to go through the Pytorch for Deep Learning course. While I am implementing a module and try to train it I get this problem:
TypeError Traceback (most recent call last)
<ipython-input-25-5e18d2675f50> in <module>
----> 1 history1 = fit(5, 0.001, model_1, train_loader, val_loader)
<ipython-input-21-ed68bbaee875> in fit(epochs, lr, model, train_loader, val_loader, opt_func)
8 for images,_ in train_loader:
9 print(images.dtype)
---> 10 loss = model_1.training(images)
11 print(loss.dtype)
12 loss.backward()
TypeError: 'bool' object is not callable
And here is my original fit() function code:
def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD):
optimizer = opt_func(model_1.parameters(), lr)
epoch_result = [] #record epoch wise results
for epoch in range (epochs):
#trainging phase
for images,_ in train_loader:
print(images.dtype)
loss = model_1.training(images)
print(loss.dtype)
loss.backward()
optimizer.step()
optimizer.zero_grad()
#validation phase
result = evaluate(model_1, val_loader)
model_1.epoch_end(epoch, result)
epoch_result.append(result)
return epoch_result
Can anyone explain to me what is the cause of the problem? I don’t understand why suddenly there is a boolean object and actually which object is the error referring to. Thank you in advance~