forked from pooya-mohammadi/crnn-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_optimum_img_w.py
24 lines (19 loc) · 1.07 KB
/
get_optimum_img_w.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
This code is responsible for getting optimum image width. If labels are long and the img_w is set to a small number, the
ctc-loss returns nan. To avoid this, run the following code to get optimal image width for your dataset.
For an eight-character to ten-character dataset a width of 100px is ok. I shall keep the same ratio for others.
"""
from argparse import ArgumentParser
from dataset import CRNNDataset
parser = ArgumentParser()
parser.add_argument("--data_directory", required=True, type=str, help="path to dataset")
parser.add_argument("--alphabets", required=True, type=str, help="alphabets used in dataset")
def get_optimum_img_w(data_directory, alphabets):
dataset = CRNNDataset(data_directory, alphabets)
max_length = max(dataset.labels_length)
optimal_width = (max_length // 8) * 100
return max_length, optimal_width
if __name__ == '__main__':
args = parser.parse_args()
max_length, optimal_width = get_optimum_img_w(args.data_directory, args.alphabets)
print(f'[INFO] max_length of this dataset is {max_length}, optimal img_w is: {optimal_width}')