Mikeztrada commited on
Commit
55ba783
·
verified ·
1 Parent(s): 35a942b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -12,14 +12,16 @@ def preprocesar_imagen(image):
12
  image = Image.fromarray(image)
13
  if image.mode in ('RGBA', 'LA'):
14
  image = image.convert('RGB')
15
- image = image.convert('L')
16
  image = image.resize((28, 28), Image.NEAREST)
17
  arr = np.array(image) / 255.0
18
- arr_bin = (arr < 0.5).astype(np.float32) # Binariza: 1 es trazo
 
 
 
19
  arr_bin_4d = arr_bin.reshape(1, 28, 28, 1)
20
- # Para mostrar, invertimos la imagen para que sea negra el trazo (0) y blanco el fondo (1)
21
- img_para_mostrar = 1 - arr_bin
22
- return arr_bin_4d, img_para_mostrar
23
 
24
  def predict(image):
25
  try:
 
12
  image = Image.fromarray(image)
13
  if image.mode in ('RGBA', 'LA'):
14
  image = image.convert('RGB')
15
+ image = image.convert('L') # escala de grises
16
  image = image.resize((28, 28), Image.NEAREST)
17
  arr = np.array(image) / 255.0
18
+
19
+ # Umbral bajo: todo menor o igual a 0.2 será negro (0), lo demás blanco (1)
20
+ arr_bin = np.where(arr <= 0.2, 0.0, 1.0).astype(np.float32)
21
+
22
  arr_bin_4d = arr_bin.reshape(1, 28, 28, 1)
23
+
24
+ return arr_bin_4d, arr_bin
 
25
 
26
  def predict(image):
27
  try: