| 23 | |
| 24 | @tick_execution_time |
| 25 | def handler(): |
| 26 | preprocess = transforms.Compose([ |
| 27 | transforms.Resize(256), |
| 28 | transforms.CenterCrop(224), |
| 29 | transforms.ToTensor(), |
| 30 | transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), |
| 31 | ]) |
| 32 | input_tensor = preprocess(input_image) |
| 33 | input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model |
| 34 | output = model(input_batch) |
| 35 | _, index = torch.max(output, 1) |
| 36 | # The output has unnormalized scores. To get probabilities, you can run a softmax on it. |
| 37 | prob = torch.nn.functional.softmax(output[0], dim=0) |
| 38 | _, indices = torch.sort(output, descending=True) |
| 39 | |
| 40 | |
| 41 | @mitosis_bench |