qmjnh commited on
Commit
492846e
·
verified ·
1 Parent(s): 4a6f1c8

revert back to keras 2

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -1,26 +1,27 @@
1
  import gradio as gr
2
  import numpy as np
3
  import tensorflow as tf
4
- import keras
5
 
6
  def softmax(vector):
7
  e = np.exp(vector)
8
  return e / e.sum()
9
 
10
 
11
- def image_to_output(input_img):
12
- # Preprocess the image as before
13
- img2 = tf.image.resize(tf.cast([input_img], tf.float32)/255., [224, 224])
14
-
15
- # Run inference
16
- output = infer(tf.constant(img2))
17
 
18
- print(output)
19
-
20
- # Process the output
21
- prediction = output['output_0'].numpy().flatten()
 
22
  prediction = softmax(prediction)
 
23
  confidences = {labels[i]: float(prediction[i]) for i in range(102)}
 
 
24
  return confidences
25
 
26
  # Download the model checkpoint
@@ -47,10 +48,8 @@ for item in [
47
 
48
 
49
  # Load the SavedModel
50
- loaded = tf.saved_model.load(pretrained_repo)
51
 
52
- # Get the inference function
53
- infer = loaded.signatures["serving_default"]
54
 
55
  # Read the labels
56
  with open('flower_names.txt') as f:
 
1
  import gradio as gr
2
  import numpy as np
3
  import tensorflow as tf
 
4
 
5
  def softmax(vector):
6
  e = np.exp(vector)
7
  return e / e.sum()
8
 
9
 
10
+ def image_to_output (input_img):
11
+ gr_img = []
12
+ gr_img.append(input_img)
13
+ img2 = tf.image.resize(tf.cast(gr_img, tf.float32)/255. , [224, 224])
 
 
14
 
15
+ # print(img2)
16
+
17
+ x_test = np.asarray(img2)
18
+
19
+ prediction = model2.predict(x_test,batch_size=1).flatten()
20
  prediction = softmax(prediction)
21
+
22
  confidences = {labels[i]: float(prediction[i]) for i in range(102)}
23
+ # confidences = {labels[i]:float(top[i]) for i in range(num_predictions)}
24
+
25
  return confidences
26
 
27
  # Download the model checkpoint
 
48
 
49
 
50
  # Load the SavedModel
51
+ model2=tf.keras.models.load_model(pretrained_repo)
52
 
 
 
53
 
54
  # Read the labels
55
  with open('flower_names.txt') as f: