Model.eval() Error -- 'bool' object is not callable

I am getting getting the following error when I try to evaluate my model after training:

In SegModel: False ------Epoch 51 | Step 71 | Train Loss 0.1662866771221161 | Validation Loss 0.48616326600313187 -----------
model loaded
Traceback (most recent call last):
File “”, line 61, in model.eval() File “/data/sbanerjee/anaconda_env/SV/lib/python3.7/site-packages/torch/nn/modules/”, line 1009, in eval return self.train(False)
File “/data/sbanerjee/anaconda_env/SV/lib/python3.7/site-packages/torch/nn/modules/”, line 998, in train module.train(mode)
TypeError: ‘bool’ object is not callable

Here’s my code snippet:

model = SegModel(train=False)
if torch.cuda.device_count() > 1:
model = nn.DataParallel(model)

load_path = ‘path/to/saved/model/model_best_0816.pth.tar’
checkpoint = torch.load(load_path)
epoch = checkpoint[‘epoch’]
train_step = checkpoint[‘train step’]
train_loss = checkpoint[‘train_loss’]
val_loss = checkpoint[‘val_loss’]
print ("------Epoch {} | Step {} | Train Loss {} | Validation Loss {} -----------".format(epoch, train_step, train_loss, val_loss))
print (“model loaded”)

Any help would be greatly appreciated

1 Like

It looks like you have replaced the internal self.train() method inside your model with a bool value:

class MyModel(nn.Module):
    def __init__(self, train):
        super(MyModel, self).__init__() = nn.BatchNorm2d(3)
        self.train = train

    def forward(self, x):
        x =
        return x

Note that self.train() is defined as a method in all nn.Modules, so you should use another name. :wink:


Oh okay, thanks a ton :slight_smile: