-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
59 lines (45 loc) · 1.72 KB
/
testing.py
File metadata and controls
59 lines (45 loc) · 1.72 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
from interface import Interface
from app import RaspberryPIManagement
from camera import Camera
from model import Model
import time
### Run Unit Test cases sequentially
## This creates the interface and shows it on screen.
interface = Interface(None)
## This starts the loading panel.
interface.display_loading_layout()
time.sleep(3)
## This shows a dummy classification result
interface.display_classification_results({'General':False,'Metal':0.98,'Plastic':0.05,'Paper':0.01})
## This creates a camera object
camera = Camera(None)
## This starts the live-stream preview
camera.stream()
time.sleep(3)
## This stops teh live-stream preview
camera.stop_stream()
## This creates a model object, and gives it the path to the store tflite model:
model = Model(model_filepath=r'./model/tf_lite_model.tflite')
## images to test for:
images = [('paper_image.jpg',['Paper']),('metal_plastic.jpg',['Metal','Plastic'])]
def getMaxCategory(dict):
if dict['General']==True:
return 'General'
else:
max_value = max(dict.values()) # maximum value
if dict['Metal'] == max_value:
return 'Metal'
elif dict['Paper'] == max_value:
return 'Paper'
else:
return 'Plastic'
## For each test image:
for img_path,cat in images:
## This asks the model to predict the category of the image
model.predict_img_file(img_path,enable_saving=True)
## Assert that the category with the maximum predicted category is in the test case allowed categories:
assert getMaxCategory(model.predictions) in cat
### Integrated Testing: (Only run this on the RaspberryPI system)
rpi = RaspberryPIManagement()
### Start the classification process
rpi.interface.call_classify_and_loading()