-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_batch_classification.py
More file actions
108 lines (88 loc) · 3.6 KB
/
Copy pathtest_batch_classification.py
File metadata and controls
108 lines (88 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
Test script for batch classification endpoint
"""
import requests
import time
import json
from pathlib import Path
def test_batch_classification():
"""Test the batch classification endpoint"""
# Test images (using the same test images we have)
test_images = [
"infectedcell.png",
"uninfectedcell.png"
]
# Check if test images exist
for img in test_images:
if not Path(img).exists():
print(f"❌ Test image {img} not found")
return
print("🧪 Testing Batch Classification Endpoint")
print("=" * 50)
# Test 1: Basic batch classification
print("\n1. Testing basic batch classification...")
try:
files = []
for img in test_images:
with open(img, 'rb') as f:
files.append(('files', (img, f.read(), 'image/png')))
response = requests.post(
'http://localhost:8000/classify/batch',
files=files,
params={'use_infected_labels': False}
)
if response.status_code == 200:
data = response.json()
print(f"✅ Success! Processed {data['total_images']} images")
print(f" Total time: {data['total_processing_time']:.3f}s")
print(f" Average time per image: {data['total_processing_time']/data['total_images']:.3f}s")
# Show individual results
print("\n Individual Results:")
for result in data['results']:
print(f" - {result['filename']}: {result['prediction']} ({result['confidence']*100:.1f}%)")
else:
print(f"❌ Error: {response.status_code} - {response.text}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
# Test 2: Batch classification with infected labels
print("\n2. Testing batch classification with infected labels...")
try:
files = []
for img in test_images:
with open(img, 'rb') as f:
files.append(('files', (img, f.read(), 'image/png')))
response = requests.post(
'http://localhost:8000/classify/batch',
files=files,
params={'use_infected_labels': True}
)
if response.status_code == 200:
data = response.json()
print(f"✅ Success! Processed {data['total_images']} images")
print(f" Label type: {data['label_type']}")
# Show individual results
print("\n Individual Results:")
for result in data['results']:
print(f" - {result['filename']}: {result['prediction']} ({result['confidence']*100:.1f}%)")
else:
print(f"❌ Error: {response.status_code} - {response.text}")
except Exception as e:
print(f"❌ Exception: {str(e)}")
# Test 3: Health check
print("\n3. Testing health endpoint...")
try:
response = requests.get('http://localhost:8000/health')
if response.status_code == 200:
data = response.json()
print(f"✅ Health check passed")
print(f" Model loaded: {data['model_loaded']}")
print(f" Status: {data['status']}")
else:
print(f"❌ Health check failed: {response.status_code}")
except Exception as e:
print(f"❌ Health check exception: {str(e)}")
print("\n" + "=" * 50)
print("🎉 Batch classification tests completed!")
if __name__ == "__main__":
test_batch_classification()