Created
September 13, 2018 16:27
-
-
Save mahasak/5ccc7cc3ce9f1d1c01e2144c6b44c7fb to your computer and use it in GitHub Desktop.
pytorch vision image prediction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Resize the input image nad preprocess it. | |
| image = T.Resize(target_size=(224, 224))(image) | |
| image = T.ToTensor()(image) | |
| # Convert to Torch.Tensor and normalize. | |
| image = T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])(image) | |
| with torch.no_grad(): | |
| image = torch.autograd.Variable(image[None]) | |
| # Get prediction results | |
| preds = F.softmax(model(image), dim=1) | |
| # Prepare first k items, from preditions result | |
| results = torch.topk(preds.cpu().data, k=4, dim=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment