Sa-m commited on
Commit
3039e58
1 Parent(s): 0cfd3a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -11
app.py CHANGED
@@ -14,18 +14,35 @@ NUM_CLASSES=6
14
 
15
  model=load_model('best_model.h5')
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def classify_image(inp):
18
- np.random.seed(143)
19
- inp = inp.reshape((-1, HEIGHT,WIDTH, 3))
20
- inp = tf.keras.applications.nasnet.preprocess_input(inp)
21
- prediction = model.predict(inp)
22
- #label = dict((v,k) for k,v in labels.items())
23
- predicted_class_indices=np.argmax(prediction,axis=1)
24
- result = {}
25
- for i in range(len(predicted_class_indices)):
26
- if predicted_class_indices[i] < NUM_CLASSES:
27
- result[labels[predicted_class_indices[i]]]= float(predicted_class_indices[i])
28
- return result
 
 
 
29
 
30
 
31
 
 
14
 
15
  model=load_model('best_model.h5')
16
 
17
+ # def classify_image(inp):
18
+ # np.random.seed(143)
19
+ # inp = inp.reshape((-1, HEIGHT,WIDTH, 3))
20
+ # inp = tf.keras.applications.nasnet.preprocess_input(inp)
21
+ # prediction = model.predict(inp)
22
+ # ###label = dict((v,k) for k,v in labels.items())
23
+ # predicted_class_indices=np.argmax(prediction,axis=1)
24
+ # result = {}
25
+ # for i in range(len(predicted_class_indices)):
26
+ # if predicted_class_indices[i] < NUM_CLASSES:
27
+ # result[labels[predicted_class_indices[i]]]= float(predicted_class_indices[i])
28
+ # return result
29
+
30
+
31
  def classify_image(inp):
32
+ np.random.seed(143)
33
+ inp = inp.reshape((-1, HEIGHT, WIDTH, 3))
34
+ inp = tf.keras.applications.nasnet.preprocess_input(inp)
35
+ prediction = model.predict(inp)
36
+ predicted_class_indices = np.argmax(prediction, axis=1)
37
+ result = {}
38
+ for i in range(len(predicted_class_indices)):
39
+ if predicted_class_indices[i] < NUM_CLASSES:
40
+ try:
41
+ label = labels[predicted_class_indices[i]]
42
+ result[label] = float(predicted_class_indices[i])
43
+ except KeyError:
44
+ print(f"KeyError: Label not found for index {predicted_class_indices[i]}")
45
+ return result
46
 
47
 
48