Spaces:
Sleeping
Sleeping
File size: 821 Bytes
b9ee29a 1038417 b9ee29a 1038417 b3797b8 1038417 7b908dc 977cc9d 1038417 26b08fd 1038417 977cc9d 1038417 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from PIL import Image
import numpy as np
labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
def preprocess_image(img_path):
img = Image.open(img_path)
img = img.resize((256, 256))
img_array = np.array(img)
return img_array
# Function to classify the garbage
def classify_garbage(img_path, model):
processed_img = preprocess_image(img_path)
prediction = model.predict(processed_img)
class_labels = ["cardboard", "glass", "metal", "paper", "plastic", "trash"]
predicted_class = np.argmax(prediction, axis=1)[0]
classification_result = class_labels[predicted_class]
# Get the confidence (probability) of the predicted class
confidence = prediction[0][predicted_class] * 100 # Convert probability to percentage
return classification_result, confidence |