Spaces:
Sleeping
Sleeping
tonyliu404
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -18,8 +18,6 @@ import matplotlib.pyplot as plt
|
|
18 |
from matplotlib.colors import LinearSegmentedColormap
|
19 |
import textwrap
|
20 |
import plotly.graph_objects as go
|
21 |
-
from tensorflow.keras.applications.efficientnet import preprocess_input
|
22 |
-
|
23 |
|
24 |
st.set_page_config(
|
25 |
page_title="Food Chain",
|
@@ -232,17 +230,19 @@ class_names = [
|
|
232 |
|
233 |
def classifyImage(input_image):
|
234 |
input_image = input_image.resize((img_size, img_size))
|
235 |
-
input_array = tf.keras.utils.img_to_array(input_image)
|
236 |
|
237 |
# Add a batch dimension
|
238 |
input_array = tf.expand_dims(input_array, 0) # (1, 224, 224, 3)
|
239 |
-
input_array = preprocess_input(input_array) #TESTING
|
240 |
|
241 |
predictions = model.predict(input_array)[0]
|
242 |
print(f"Predictions: {predictions}")
|
243 |
predictions = tf.nn.softmax(predictions).numpy() #TESTING
|
244 |
print(f"Predictions AFTER SOFTMAX: {predictions}")
|
245 |
-
|
|
|
|
|
|
|
246 |
# Sort predictions to get top 5
|
247 |
top_indices = np.argsort(predictions)[-5:][::-1]
|
248 |
|
|
|
18 |
from matplotlib.colors import LinearSegmentedColormap
|
19 |
import textwrap
|
20 |
import plotly.graph_objects as go
|
|
|
|
|
21 |
|
22 |
st.set_page_config(
|
23 |
page_title="Food Chain",
|
|
|
230 |
|
231 |
def classifyImage(input_image):
|
232 |
input_image = input_image.resize((img_size, img_size))
|
233 |
+
input_array = tf.keras.utils.img_to_array(input_image) / 255.0
|
234 |
|
235 |
# Add a batch dimension
|
236 |
input_array = tf.expand_dims(input_array, 0) # (1, 224, 224, 3)
|
|
|
237 |
|
238 |
predictions = model.predict(input_array)[0]
|
239 |
print(f"Predictions: {predictions}")
|
240 |
predictions = tf.nn.softmax(predictions).numpy() #TESTING
|
241 |
print(f"Predictions AFTER SOFTMAX: {predictions}")
|
242 |
+
|
243 |
+
probability_sum = predictions.sum() * 100
|
244 |
+
print(f"Sum of predictions (as percentages): {probability_sum:.2f}%")
|
245 |
+
|
246 |
# Sort predictions to get top 5
|
247 |
top_indices = np.argsort(predictions)[-5:][::-1]
|
248 |
|