pavan1221 commited on
Commit
bf89aa3
·
verified ·
1 Parent(s): 0d05213

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -55,14 +55,19 @@ def split_board_into_squares(board_img):
55
  return squares
56
 
57
  def predict_board(squares):
58
- predictions = []
59
  for square in squares:
60
  img = cv2.resize(square, (64, 64))
61
- img = tf.keras.applications.efficientnet.preprocess_input(img)
62
- img = np.expand_dims(img, axis=0)
63
- pred = model.predict(img, verbose=0)
64
- class_idx = np.argmax(pred)
65
- confidence = np.max(pred)
 
 
 
 
 
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)