'Tensor' object is not callable

I have an error in this line:

—> 10 output_teacher_batch = teacher_model(data_batch).data().numpy()
TypeError: ‘Tensor’ object is not callable

Does anybody have an idea how to solve this?

def fetch_teacher_outputs(teacher_model, dataloader):
# set teacher_model to evaluation mode
teacher_outputs = []
for i, (data_batch, labels_batch) in enumerate(dataloader):
if torch.cuda.is_available():
data_batch, labels_batch = data_batch.cuda(async=True),
data_batch, labels_batch = Variable(data_batch), Variable(labels_batch)

    **output_teacher_batch = teacher_model(data_batch).data().numpy()**

return teacher_outputs

data is an attribute of the returned tensor object and not a function. Instead of this, you should probably have: output_teacher_batch = teacher_model(data_batch).data.numpy()

1 Like