xcurvnubaim commited on
Commit
765c987
·
1 Parent(s): 1f96cd2

fix: fix png file

Browse files
Files changed (1) hide show
  1. main.py +3 -3
main.py CHANGED
@@ -15,14 +15,14 @@ with open("labels.txt") as f:
15
  def classify_image(img):
16
  # Resize the input image to the expected shape (224, 224)
17
  img_array = np.asarray(img.resize((224, 224)))[..., :3]
18
- img_array = img_array.reshape((-1, 224, 224, 3))
19
  img_array = tf.keras.applications.efficientnet.preprocess_input(img_array)
20
  prediction = model.predict(img_array).flatten()
21
  confidences = {labels[i]: float(prediction[i]) for i in range(90)}
22
  # Sort the confidences dictionary by value and get the top 3 items
23
- top_3_confidences = dict(sorted(confidences.items(), key=lambda item: item[1], reverse=True)[:3])
24
 
25
- return top_3_confidences
26
 
27
  @app.post("/predict")
28
  async def predict(file: bytes = File(...)):
 
15
  def classify_image(img):
16
  # Resize the input image to the expected shape (224, 224)
17
  img_array = np.asarray(img.resize((224, 224)))[..., :3]
18
+ img_array = img_array.reshape((1, 224, 224, 3)) # Add batch dimension
19
  img_array = tf.keras.applications.efficientnet.preprocess_input(img_array)
20
  prediction = model.predict(img_array).flatten()
21
  confidences = {labels[i]: float(prediction[i]) for i in range(90)}
22
  # Sort the confidences dictionary by value and get the top 3 items
23
+ # top_3_confidences = dict(sorted(confidences.items(), key=lambda item: item[1], reverse=True)[:3])
24
 
25
+ return confidences
26
 
27
  @app.post("/predict")
28
  async def predict(file: bytes = File(...)):