Spaces:
Runtime error
Runtime error
xcurvnubaim
commited on
Commit
·
fba92a9
1
Parent(s):
890b83b
fix: fix img reshape
Browse files
main.py
CHANGED
@@ -14,8 +14,7 @@ with open("labels.txt") as f:
|
|
14 |
|
15 |
def classify_image(img):
|
16 |
# Resize the input image to the expected shape (224, 224)
|
17 |
-
|
18 |
-
img_array = np.array(img_resized)
|
19 |
img_array = img_array.reshape((-1, 224, 224, 3))
|
20 |
img_array = tf.keras.applications.efficientnet.preprocess_input(img_array)
|
21 |
prediction = model.predict(img_array).flatten()
|
@@ -23,8 +22,7 @@ def classify_image(img):
|
|
23 |
return confidences
|
24 |
|
25 |
@app.post("/predict")
|
26 |
-
async def predict(file:
|
27 |
-
|
28 |
-
img = Image.open(BytesIO(contents))
|
29 |
confidences = classify_image(img)
|
30 |
return confidences
|
|
|
14 |
|
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()
|
|
|
22 |
return confidences
|
23 |
|
24 |
@app.post("/predict")
|
25 |
+
async def predict(file: bytes = File(...)):
|
26 |
+
img = Image.open(BytesIO(file))
|
|
|
27 |
confidences = classify_image(img)
|
28 |
return confidences
|