Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
satrio142 committed May 29, 2024
1 parent 93fd41c commit b019c06
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b019c06

Please sign in to comment.