TypeError: __call__() missing 1 required positional argument: 'target'

Hi @dusty_nv ,

With reference to the mentioned topic here, we are trying to create PyTorch test script for doing inference.

The custom segmentation prediction test.py implementation is:

def test():
    model = segmentation.__dict__['fcn_resnet50'](num_classes=3, aux_loss=False, pretrained=args.pretrained) 
    device = torch.device('cpu')
    checkpoint = torch.load('model_best.pth', map_location=device)
    image = Image.open('test.jpg')
    trf = T.Compose([T.Resize((320, 320)), T.ToTensor(), T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])     
    image = trf(image).unsqueeze(0)
    with torch.no_grad():  
        if torch.cuda.is_available():
            dev = "cuda:0" 
            dev = "cpu"
        device = torch.device(dev)

        img = image.to(device)
        output = model(img)['out']

However, when running the above test.py for inference on an image, we are getting TypeError: __call__() missing 1 required positional argument: 'target' error

As per our understanding, the model is not being loaded in eval mode even though we have used model.eval() for doing prediction.

Can you please confirm the reason for this error?

Please let me know if you need more information.

Hi @nishantshrivastav23, unfortunately I’m not entirely sure why the error is caused, sorry about that - it may be worth pointing out that this code originally came from the torchvision reference examples, so you may find more info there.

One difference I did notice though, is that the checkpoint state dict gets loaded like model.load_state_dict(checkpoint['model'])


Does that make a difference for you?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.