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

Method test_specific_sample

ML/tests/test_model.py:100–116  ·  view source on GitHub ↗
(self, index)

Source from the content-addressed store, hash-verified

98 print(f"Accuracy: {accuracy:.1%} ({correct}/{num_samples})")
99
100 def test_specific_sample(self, index):
101 if index < 0 or index >= len(self.dataset):
102 print(f"Error: Index must be between 0 and {len(self.dataset)-1}")
103 return
104
105 image, label = self.dataset[index]
106 pred_class, confidence, top5_idx, top5_prob = self.predict_image(image)
107
108 print(f"\nSample #{index}")
109 print("-" * 60)
110 print(f"True Label: {self.classes[label]}")
111 print(f"Predicted: {self.classes[pred_class]}")
112 print(f"Confidence: {confidence:.2%}")
113 print(f"Status: {'✓ Correct' if pred_class == label else '✗ Wrong'}")
114 print("\nTop-5 Predictions:")
115 for i, (idx, prob) in enumerate(zip(top5_idx, top5_prob), 1):
116 print(f" {i}. {self.classes[idx]:15s} {prob:.2%}")
117
118 def test_class_accuracy(self):
119 print("\nCalculating per-class accuracy...")

Callers 1

interactive_modeMethod · 0.95

Calls 1

predict_imageMethod · 0.95

Tested by

no test coverage detected