Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import tensorflow as tf
|
2 |
from tensorflow.keras.models import Model
|
3 |
from keras.models import load_model
|
4 |
-
import gradio as gr
|
|
|
|
|
5 |
import numpy as np
|
6 |
model = load_model('Densenet.h5')
|
7 |
model.load_weights("pretrained_model.h5")
|
@@ -18,13 +20,11 @@ def custom_decode_predictions(predictions, class_lables):
|
|
18 |
return decoded_predictions
|
19 |
|
20 |
def classify_image(img):
|
21 |
-
img_array =
|
22 |
-
img_array = np.expand_dims(img_array, axis=0)
|
23 |
img_array = preprocess_input(img_array)
|
24 |
-
|
25 |
-
|
26 |
-
predictions1 = model.predict(img_array)
|
27 |
-
decoded_predictions = custom_decode_predictions(predictions1, class_names)
|
28 |
return decoded_predictions
|
29 |
|
30 |
# Gradio interface
|
|
|
1 |
import tensorflow as tf
|
2 |
from tensorflow.keras.models import Model
|
3 |
from keras.models import load_model
|
4 |
+
import gradio as gr
|
5 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
6 |
+
from tensorflow.keras.applications.densenet import preprocess_input, decode_predictions
|
7 |
import numpy as np
|
8 |
model = load_model('Densenet.h5')
|
9 |
model.load_weights("pretrained_model.h5")
|
|
|
20 |
return decoded_predictions
|
21 |
|
22 |
def classify_image(img):
|
23 |
+
img_array = img_to_array(img)
|
24 |
+
img_array = np.expand_dims(img_array, axis=0))
|
25 |
img_array = preprocess_input(img_array)
|
26 |
+
predictions = model.predict(img_array)
|
27 |
+
decoded_predictions = custom_decode_predictions(predictions, class_names)
|
|
|
|
|
28 |
return decoded_predictions
|
29 |
|
30 |
# Gradio interface
|