Reaumur commited on
Commit
dfa1dab
·
verified ·
1 Parent(s): a68ae60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -73,10 +73,17 @@ def prepare_image(img):
73
 
74
  def decode_batch_predictions(pred):
75
  pred_texts = []
 
 
76
  for i in range(pred.shape[0]):
77
- # Ensure you're iterating over each element in the row pred[i]
78
- pred_text = ''.join([characters[int(c)] for c in pred[i] if c not in [-1, 0]]) # Use simple comparison
79
- pred_texts.append(pred_text)
 
 
 
 
 
80
  return pred_texts
81
 
82
 
 
73
 
74
  def decode_batch_predictions(pred):
75
  pred_texts = []
76
+
77
+ # Loop untuk setiap batch (jika ada lebih dari satu batch)
78
  for i in range(pred.shape[0]):
79
+ # Ambil argmax untuk mendapatkan indeks karakter yang diprediksi (yaitu karakter yang paling mungkin)
80
+ pred_indices = np.argmax(pred[i], axis=-1) # Cari indeks dengan probabilitas tertinggi
81
+
82
+ # Sekarang kita memetakan indeks ini ke karakter, mengecualikan nilai yang tidak valid seperti -1 atau 0 (padding)
83
+ pred_text = ''.join([characters[int(c)] for c in pred_indices if c != -1 and c != 0])
84
+
85
+ pred_texts.append(pred_text) # Simpan teks hasil decoding untuk batch yang sedang diproses
86
+
87
  return pred_texts
88
 
89