Sa-m commited on
Commit
4900bb0
·
verified ·
1 Parent(s): 57ac805

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -9,7 +9,7 @@ import numpy as np
9
 
10
  # labels= {'Burger King': 0, 'KFC': 1,'McDonalds': 2,'Other': 3,'Starbucks': 4,'Subway': 5}
11
  HEIGHT,WIDTH=224,224
12
-
13
  model=load_model('Models/best_model1.h5')
14
 
15
  # def classify_image(inp):
@@ -25,20 +25,31 @@ model=load_model('Models/best_model1.h5')
25
  # result[labels[predicted_class_indices[i]]]= float(predicted_class_indices[i])
26
  # return result
27
 
28
- def classify_image(inp):
29
- np.random.seed(143)
30
- labels = {'Cat': 0, 'Dog': 1}
31
- NUM_CLASSES = 2
32
- #inp = inp.reshape((-1, HEIGHT, WIDTH, 3))
33
- #inp = tf.keras.applications.nasnet.preprocess_input(inp)
34
- prediction = model.predict(inp)
35
- predicted_class_indices = np.argmax(prediction, axis=1)
 
 
36
 
37
- label_order = ["Cat","Dog"]
 
 
 
 
 
 
 
 
38
 
39
- result = {label: float(f"{prediction[0][labels[label]]:.6f}") for label in label_order}
 
40
 
41
- return result
42
 
43
 
44
  image = gr.Image(height=HEIGHT,width=WIDTH,label='Input')
 
9
 
10
  # labels= {'Burger King': 0, 'KFC': 1,'McDonalds': 2,'Other': 3,'Starbucks': 4,'Subway': 5}
11
  HEIGHT,WIDTH=224,224
12
+ IMG_SIZE=224
13
  model=load_model('Models/best_model1.h5')
14
 
15
  # def classify_image(inp):
 
25
  # result[labels[predicted_class_indices[i]]]= float(predicted_class_indices[i])
26
  # return result
27
 
28
+ # def classify_image(inp):
29
+ # np.random.seed(143)
30
+ # labels = {'Cat': 0, 'Dog': 1}
31
+ # NUM_CLASSES = 2
32
+ # #inp = inp.reshape((-1, HEIGHT, WIDTH, 3))
33
+ # #inp = tf.keras.applications.nasnet.preprocess_input(inp)
34
+ # prediction = model.predict(inp)
35
+ # predicted_class_indices = np.argmax(prediction, axis=1)
36
+
37
+ # label_order = ["Cat","Dog"]
38
 
39
+ # result = {label: float(f"{prediction[0][labels[label]]:.6f}") for label in label_order}
40
+
41
+ # return result
42
+
43
+ def classify_image(inp):
44
+ inp = inp.reshape((-1, IMG_SIZE, IMG_SIZE, 3))
45
+ inp = tf.keras.applications.vgg16.preprocess_input(inp)
46
+ prediction = model.predict(inp).flatten()
47
+ return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)}
48
 
49
+ # image = gr.inputs.Image(shape=(IMG_SIZE, IMG_SIZE))
50
+ # label = gr.outputs.Label(num_top_classes=2)
51
 
52
+ # gr.Interface(fn=classify_image, inputs=image, outputs=label, title='Cats Vs Dogs',height=600, width=1200,examples=ex,theme='peach').launch(debug=True)
53
 
54
 
55
  image = gr.Image(height=HEIGHT,width=WIDTH,label='Input')