rocioadlc commited on
Commit
c5eb9a8
·
verified ·
1 Parent(s): 04dce4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -40,6 +40,7 @@ custom_title ="<span style='color: #66814a;'>Green Greta</span>"
40
 
41
 
42
  from huggingface_hub import from_pretrained_keras
 
43
 
44
  import tensorflow as tf
45
  from tensorflow import keras
@@ -53,17 +54,15 @@ class_labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
53
 
54
  # Function to predict image label and score
55
  def predict_image(input):
56
- # Resize the image to the size expected by the model
57
- image = input.resize((244, 224))
58
- # Convert the image to a NumPy array
59
- image_array = tf.keras.preprocessing.image.img_to_array(image)
60
  # Normalize the image
61
- image_array /= 255.0
62
  # Expand the dimensions to create a batch
63
  image_array = tf.expand_dims(image_array, 0)
64
  # Predict using the model
65
- predictions = model1.predict(image_array)
66
-
67
  category_scores = {}
68
  for i, class_label in enumerate(class_labels):
69
  category_scores[class_label] = predictions[0][i].item()
 
40
 
41
 
42
  from huggingface_hub import from_pretrained_keras
43
+ from tensorflow.keras.applications import EfficientNetB0
44
 
45
  import tensorflow as tf
46
  from tensorflow import keras
 
54
 
55
  # Function to predict image label and score
56
  def predict_image(input):
57
+ # Resize the image to the size expected by the model and convert to numpy array
58
+ image_array = tf.keras.preprocessing.image.img_to_array(input.resize((224, 244)))
 
 
59
  # Normalize the image
60
+ image_array = tf.keras.applications.efficientnet.preprocess_input(image_array)
61
  # Expand the dimensions to create a batch
62
  image_array = tf.expand_dims(image_array, 0)
63
  # Predict using the model
64
+ predictions = model_tl.predict(image_array)
65
+ class_labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
66
  category_scores = {}
67
  for i, class_label in enumerate(class_labels):
68
  category_scores[class_label] = predictions[0][i].item()