Spaces:
Runtime error
Runtime error
suvadityamuk
commited on
Commit
•
b6498e7
1
Parent(s):
123ba67
tested done
Browse filesSigned-off-by: Suvaditya Mukherjee <[email protected]>
app.py
CHANGED
@@ -4,9 +4,6 @@ from tensorflow import keras
|
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
|
7 |
-
# To force inference using CPU only
|
8 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
9 |
-
|
10 |
# Model definition
|
11 |
|
12 |
image_input = keras.Input(shape=(None, None, 3))
|
@@ -34,12 +31,12 @@ model = keras.Model(inputs=image_input, outputs=model_output)
|
|
34 |
|
35 |
|
36 |
def inference(image: tf.Tensor):
|
37 |
-
|
38 |
-
tensor = tf.expand_dims(tensor, axis=0)
|
39 |
y = model(image).numpy()
|
40 |
preds = keras.applications.imagenet_utils.decode_predictions(y, top=5)
|
41 |
result = {i[1]: str(i[2]) for i in preds[0]}
|
42 |
result = {k: v for k, v in sorted(result.items(), key=lambda item: item[1])}
|
|
|
43 |
return result
|
44 |
|
45 |
def greet(name):
|
|
|
4 |
from PIL import Image
|
5 |
import os
|
6 |
|
|
|
|
|
|
|
7 |
# Model definition
|
8 |
|
9 |
image_input = keras.Input(shape=(None, None, 3))
|
|
|
31 |
|
32 |
|
33 |
def inference(image: tf.Tensor):
|
34 |
+
image = tf.expand_dims(image, axis=0)
|
|
|
35 |
y = model(image).numpy()
|
36 |
preds = keras.applications.imagenet_utils.decode_predictions(y, top=5)
|
37 |
result = {i[1]: str(i[2]) for i in preds[0]}
|
38 |
result = {k: v for k, v in sorted(result.items(), key=lambda item: item[1])}
|
39 |
+
result = sorted(result.items(), key=lambda x: x[1], reverse=True)
|
40 |
return result
|
41 |
|
42 |
def greet(name):
|