Blazer007 commited on
Commit
18fda7f
·
1 Parent(s): 2a5464b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -21,34 +21,43 @@ class_names = [
21
  ]
22
 
23
  examples = [
24
- ['./aeroplane.png'],
25
- ['./horse.png']
 
 
 
26
  ]
27
 
28
  IMG_SIZE = 72
29
 
30
- def infer(input_image):
31
- print('#$$$$$$$$$$$$$$$$$$$$$$$$$ IN INFER $$$$$$$$$$$$$$$$$$$$$$$')
32
- # image_tensor = read_image(input_image)
33
- image_tensor = tf.convert_to_tensor(input_image)
34
- image_tensor.set_shape([None, None, 3])
35
- image_tensor = tf.image.resize(image_tensor, (IMG_SIZE, IMG_SIZE))
36
- print(image_tensor.shape)
 
37
  predictions = student_model.predict(np.expand_dims((image_tensor), axis=0))
38
- print(predictions)
39
  predictions = np.squeeze(predictions)
40
- print(predictions)
41
- predictions = np.argmax(predictions) # , axis=2
42
- print(predictions)
43
  predicted_label = class_names[predictions.item()]
44
- print(predictions.item())
45
- print(predicted_label)
46
  return str(predicted_label)
 
 
 
 
 
 
47
 
48
  input = gr.inputs.Image(shape=(IMG_SIZE, IMG_SIZE))
49
- output = [gr.outputs.Label()]
50
- title = "Image Classification using "
51
- description = "Upload an image or select from examples to classify it.<br>The allowed classes are - Airplane, Automobile, Bird, Cat, Deer, Dog, Frog, Horse, Ship, Truck.<br><p><b>Space author: Vivek Rai</b> <br><b> Keras example author: Sayak Paul </b></p>"
 
 
 
 
52
 
53
  gr_interface = gr.Interface(
54
  infer,
 
21
  ]
22
 
23
  examples = [
24
+ ['./aeroplane.png'],
25
+ ['./dog.png'],
26
+ ['./horse.png'],
27
+ ['./ship.png'],
28
+ ['./truck.png']
29
  ]
30
 
31
  IMG_SIZE = 72
32
 
33
+ def teacher_model_output(image_tensor):
34
+ predictions = teacher_model.predict(np.expand_dims((image_tensor), axis=0))
35
+ predictions = np.squeeze(predictions)
36
+ predictions = np.argmax(predictions)
37
+ predicted_label = class_names[predictions.item()]
38
+ return str(predicted_label)
39
+
40
+ def student_model_output(image_tensor):
41
  predictions = student_model.predict(np.expand_dims((image_tensor), axis=0))
 
42
  predictions = np.squeeze(predictions)
43
+ predictions = np.argmax(predictions)
 
 
44
  predicted_label = class_names[predictions.item()]
 
 
45
  return str(predicted_label)
46
+
47
+ def infer(input_image):
48
+ image_tensor = tf.convert_to_tensor(input_image)
49
+ image_tensor.set_shape([None, None, 3])
50
+ image_tensor = tf.image.resize(image_tensor, (IMG_SIZE, IMG_SIZE))
51
+ return teacher_model_output(image_tensor), student_model_output(image_tensor)
52
 
53
  input = gr.inputs.Image(shape=(IMG_SIZE, IMG_SIZE))
54
+ output = [gr.outputs.Label(label = "Teacher Model Output"), gr.outputs.Label(label = "Student Model Output")]
55
+
56
+ title = "Image Classification using Consistency training with supervision"
57
+ description = "Upload an image or select from examples to classify it.<br>The allowed classes are - Airplane, Automobile, Bird, Cat, Deer, Dog, Frog, Horse, Ship, Truck.<br><p><b>Teacher Model Repo - </b> <br><b> Student Model Repo - </b></p>"
58
+
59
+
60
+ article = "<div style='text-align: center;'><a href='https://twitter.com/_Blazer_007' target='_blank'>Space by Vivek Rai</a><br><a href='https://keras.io/examples/vision/consistency_training/' target='_blank'>Keras example by Sayak Paul</a></div>"
61
 
62
  gr_interface = gr.Interface(
63
  infer,