MCPcopy Index your code
hub / github.com/geekcomputers/Python / predict_image

Method predict_image

ML/tests/test_model.py:59–68  ·  view source on GitHub ↗
(self, image_tensor)

Source from the content-addressed store, hash-verified

57 return model.to(self.device)
58
59 def predict_image(self, image_tensor):
60 with torch.no_grad():
61 image_tensor = image_tensor.unsqueeze(0).to(self.device)
62 outputs = self.model(image_tensor)
63 probabilities = F.softmax(outputs, dim=1)
64 confidence, predicted = torch.max(probabilities, 1)
65
66 top5_prob, top5_idx = torch.topk(probabilities, min(5, len(self.classes)), dim=1)
67
68 return predicted.item(), confidence.item(), top5_idx[0].cpu().numpy(), top5_prob[0].cpu().numpy()
69
70 def test_random_samples(self, num_samples=10):
71 print(f"\nTesting {num_samples} random samples...")

Callers 4

test_random_samplesMethod · 0.95
test_specific_sampleMethod · 0.95
test_class_accuracyMethod · 0.95
test_custom_imageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected