Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,14 +55,19 @@ def split_board_into_squares(board_img):
|
|
| 55 |
return squares
|
| 56 |
|
| 57 |
def predict_board(squares):
|
| 58 |
-
|
| 59 |
for square in squares:
|
| 60 |
img = cv2.resize(square, (64, 64))
|
| 61 |
-
img = tf.keras.applications.efficientnet.preprocess_input(
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
predictions.append({
|
| 67 |
"class": CLASS_NAMES[class_idx],
|
| 68 |
"confidence": float(confidence)
|
|
|
|
| 55 |
return squares
|
| 56 |
|
| 57 |
def predict_board(squares):
|
| 58 |
+
batch = []
|
| 59 |
for square in squares:
|
| 60 |
img = cv2.resize(square, (64, 64))
|
| 61 |
+
img = tf.keras.applications.efficientnet.preprocess_input(
|
| 62 |
+
img.astype(np.float32)
|
| 63 |
+
)
|
| 64 |
+
batch.append(img)
|
| 65 |
+
batch = np.array(batch)
|
| 66 |
+
preds = model.predict(batch, verbose=0)
|
| 67 |
+
predictions = []
|
| 68 |
+
for i in range(len(preds)):
|
| 69 |
+
class_idx = np.argmax(preds[i])
|
| 70 |
+
confidence = np.max(preds[i])
|
| 71 |
predictions.append({
|
| 72 |
"class": CLASS_NAMES[class_idx],
|
| 73 |
"confidence": float(confidence)
|