sharktide commited on
Commit
2c821be
·
1 Parent(s): 3cd3365

Delete predict.py

Browse files
Files changed (1) hide show
  1. predict.py +0 -87
predict.py DELETED
@@ -1,87 +0,0 @@
1
- import os
2
- import keyboard
3
- import cv2
4
- import numpy as np
5
- import time
6
- print("program started!")
7
- print("Turning off OneDNN operations")
8
- os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' #Turns off OneDNN operations, which is just something that is automatically turned on to make cpu usage lower. However, as this model is prettly light, we don't need this.
9
-
10
-
11
-
12
-
13
- CLASSES = ['Glass', 'Metal', 'Paperboard', 'Plastic-Polystyrene', 'Plastic-Regular']
14
- import tensorflow as tf
15
-
16
- ensemble1 = tf.keras.models.load_model("recyclebot.keras")
17
- ensemble2 = tf.keras.models.load_model("72-75.keras")
18
-
19
-
20
-
21
-
22
-
23
- # Show the model architecture
24
- ensemble1.summary()
25
- ensemble2.summary()
26
-
27
-
28
- index = 1
29
-
30
- while True:
31
-
32
-
33
- check = 0
34
-
35
-
36
-
37
- test_image = cv2.resize(cv2.imread(input(f'''Path to image #{index} -- Please Replace Backslashes (\\) with forwardslashes (/) please!
38
- -->''')), (240, 240))
39
-
40
- test_image = np.array(test_image).reshape(-1, 240, 240, 3)
41
-
42
- print(test_image.shape)
43
-
44
- # Assign weights to each model
45
- weight_1 = 0.70
46
- weight_2 = 0.30
47
-
48
-
49
- # Get predictions (probabilities)
50
- preds_1 = ensemble1.predict(test_image)
51
- preds_2 = ensemble2.predict(test_image)
52
-
53
-
54
-
55
- # Weighted average of probabilities
56
- final_preds = (weight_1 * preds_1 + weight_2 * preds_2)
57
- print(CLASSES)
58
- print(final_preds)
59
-
60
- print()
61
-
62
-
63
- # Get the class with the highest weighted average probability
64
- final_class = (CLASSES[np.argmax(final_preds)])
65
- print(final_class)
66
-
67
-
68
- print(f''' Click space to go on.''')
69
- while check == 0:
70
-
71
- if keyboard.is_pressed(' '):
72
- event = keyboard.read_event(suppress=True)
73
- print('--------------------------------------------------')
74
- check = 1
75
-
76
-
77
-
78
- print(f'''
79
-
80
-
81
-
82
-
83
-
84
- ''')
85
-
86
-
87
- index = (index + 1)