Puyush commited on
Commit
cb3f175
·
verified ·
1 Parent(s): 29ad85a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -96,6 +96,8 @@ char_to_num = layers.StringLookup(vocabulary=list(characters), mask_token=None)
96
  num_to_char = layers.StringLookup(
97
  vocabulary=char_to_num.get_vocabulary(), mask_token=None, invert=True
98
  )
 
 
99
 
100
  def distortion_free_resize(image, img_size):
101
  w, h = img_size
@@ -127,22 +129,20 @@ def distortion_free_resize(image, img_size):
127
  [0, 0],
128
  ],)
129
  image = tf.transpose(image, perm=[1,0,2])
130
- image = tf.image.resize_with_crop_or_pad(image, target_height=128, target_width=32)
131
  image = tf.image.flip_left_right(image)
132
  return image
133
 
134
- def decode_batch_predictions(input_image):
135
- img_size=(128, 32)
136
  img_byte_array = io.BytesIO()
137
  input_image.save(img_byte_array, format='JPEG') # Change the format as needed
138
  input_image = img_byte_array.getvalue()
 
139
  input_image = tf.io.decode_image(input_image, channels=1, dtype=tf.dtypes.uint8)
140
  input_image = distortion_free_resize(input_image, img_size)
141
  input_image = tf.image.convert_image_dtype(input_image, tf.float32)/255.0
142
 
143
  pred = loaded_model.predict(input_image)
144
  input_len = np.ones(pred.shape[0]) * pred.shape[1]
145
- # Use greedy search. For complex tasks, you can use beam search.
146
  results = keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0][
147
  :, :max_len
148
  ]
 
96
  num_to_char = layers.StringLookup(
97
  vocabulary=char_to_num.get_vocabulary(), mask_token=None, invert=True
98
  )
99
+ image_width = 128
100
+ image_height = 32
101
 
102
  def distortion_free_resize(image, img_size):
103
  w, h = img_size
 
129
  [0, 0],
130
  ],)
131
  image = tf.transpose(image, perm=[1,0,2])
 
132
  image = tf.image.flip_left_right(image)
133
  return image
134
 
135
+ def decode_batch_predictions(input_image, img_size=(image_width, image_height)):
 
136
  img_byte_array = io.BytesIO()
137
  input_image.save(img_byte_array, format='JPEG') # Change the format as needed
138
  input_image = img_byte_array.getvalue()
139
+
140
  input_image = tf.io.decode_image(input_image, channels=1, dtype=tf.dtypes.uint8)
141
  input_image = distortion_free_resize(input_image, img_size)
142
  input_image = tf.image.convert_image_dtype(input_image, tf.float32)/255.0
143
 
144
  pred = loaded_model.predict(input_image)
145
  input_len = np.ones(pred.shape[0]) * pred.shape[1]
 
146
  results = keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0][
147
  :, :max_len
148
  ]