Spaces:
Sleeping
Sleeping
revert back to keras 2
Browse files
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 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Run inference
|
| 16 |
-
output = infer(tf.constant(img2))
|
| 17 |
|
| 18 |
-
print(
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 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 |
-
|
| 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:
|