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)
model.load_state_dict(checkpoint)
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():
model.eval()
if torch.cuda.is_available():
dev = "cuda:0"
else:
dev = "cpu"
device = torch.device(dev)
model.to(device)
img = image.to(device)
output = model(img)['out']
print(output)
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.