in sagemaker/src/handwriting_line_recognition.py [0:0]
def transform(image, bbox, label):
'''
This function resizes the input image and converts so that it could be fed into the network.
Furthermore, the label (text) is one-hot encoded.
'''
image = np.expand_dims(image, axis=0).astype(np.float32)
if image[0, 0, 0] > 1:
image = image/255.
image = (image - 0.942532484060557) / 0.15926149044640417
label_encoded = np.zeros(max_seq_len, dtype=np.float32)-1
i = 0
for word in label:
word = word.replace(""", r'"')
word = word.replace("&", r'&')
word = word.replace('";', '\"')
word = word.lower()
for letter in word:
label_encoded[i] = alphabet_dict[letter]
i += 1
return image, label_encoded