From b019c06b4bf45a0f054df86527c6d8d9cfd29531 Mon Sep 17 00:00:00 2001 From: satrio142 <106372451+satrio142@users.noreply.github.com> Date: Wed, 29 May 2024 19:32:31 +0700 Subject: [PATCH] Update app.py --- app.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 13886bc..e304fde 100644 --- a/app.py +++ b/app.py @@ -39,20 +39,14 @@ async def predict_image(img: UploadFile, response: Response): image = np.expand_dims(image, axis=0) # Predict the class of the image - arr = model.predict(image) - - arr = model.predict(image, batch_size=10) - - # Mengambil indeks kelas dengan nilai probabilitas tertinggi - predicted_class_index = np.argmax(arr) - - # Daftar label yang sesuai dengan kelas - class_labels = [ - 'Fresh Apples', 'Fresh Banana', 'Fresh Cucumber', - 'Fresh Oranges', - 'Rotten Apples', 'Rotten Banana', 'Rotten Cucumber', - 'Rotten Oranges' - ] + prediction = model.predict([img_array, np.zeros((1, 150, 150, 3))])[0] + confidence = np.max(prediction) + print(f"Predictions: {prediction}, Confidence: {confidence}") # Debugging output + predicted_class_index = np.argmax(prediction) + if predicted_class_index >= len(class_labels) or confidence < confidence_threshold: + return "Cannot be predicted", confidence + predicted_label = class_labels[predicted_class_index] + return predicted_label, confidence # Menentukan label predicted_label = class_labels[predicted_class_index]