(self, image_path)
| 147 | print(f"Overall Accuracy: {100.0 * overall_correct / overall_total:.2f}% ({overall_correct}/{overall_total})") |
| 148 | |
| 149 | def test_custom_image(self, image_path): |
| 150 | if not os.path.exists(image_path): |
| 151 | print(f"Error: Image not found at {image_path}") |
| 152 | return |
| 153 | |
| 154 | try: |
| 155 | image = Image.open(image_path).convert('RGB') |
| 156 | |
| 157 | transform = transforms.Compose([ |
| 158 | transforms.Resize((self.image_size, self.image_size)), |
| 159 | transforms.ToTensor(), |
| 160 | ]) |
| 161 | |
| 162 | image_tensor = transform(image) |
| 163 | pred_class, confidence, top5_idx, top5_prob = self.predict_image(image_tensor) |
| 164 | |
| 165 | print(f"\nCustom Image: {image_path}") |
| 166 | print("-" * 60) |
| 167 | print(f"Predicted: {self.classes[pred_class]}") |
| 168 | print(f"Confidence: {confidence:.2%}") |
| 169 | print("\nTop-5 Predictions:") |
| 170 | for i, (idx, prob) in enumerate(zip(top5_idx, top5_prob), 1): |
| 171 | print(f" {i}. {self.classes[idx]:15s} {prob:.2%}") |
| 172 | |
| 173 | except Exception as e: |
| 174 | print(f"Error loading image: {e}") |
| 175 | |
| 176 | def interactive_mode(self): |
| 177 | print("\n" + "=" * 60) |
no test coverage detected