(data_file, image_path, batchsize=128, maxlabellength=10, imagesize=(32, 280))
| 78 | return r_n |
| 79 | |
| 80 | def gen(data_file, image_path, batchsize=128, maxlabellength=10, imagesize=(32, 280)): |
| 81 | image_label = readfile(data_file) |
| 82 | _imagefile = [i for i, j in image_label.items()] |
| 83 | x = np.zeros((batchsize, imagesize[0], imagesize[1], 1), dtype=np.float) |
| 84 | labels = np.ones([batchsize, maxlabellength]) * 10000 |
| 85 | input_length = np.zeros([batchsize, 1]) |
| 86 | label_length = np.zeros([batchsize, 1]) |
| 87 | |
| 88 | r_n = random_uniform_num(len(_imagefile)) |
| 89 | _imagefile = np.array(_imagefile) |
| 90 | while 1: |
| 91 | shufimagefile = _imagefile[r_n.get(batchsize)] |
| 92 | for i, j in enumerate(shufimagefile): |
| 93 | try: |
| 94 | img1 = Image.open(os.path.join(image_path, j)).convert('L') |
| 95 | except: |
| 96 | continue |
| 97 | img = np.array(img1, 'f') / 255.0 - 0.5 |
| 98 | |
| 99 | x[i] = np.expand_dims(img, axis=2) |
| 100 | # print('imag:shape', img.shape) |
| 101 | str = image_label[j] |
| 102 | label_length[i] = len(str) |
| 103 | |
| 104 | if(len(str) <= 0): |
| 105 | print("len < 0", j) |
| 106 | input_length[i] = imagesize[1] // 8 |
| 107 | labels[i, :len(str)] = [int(k) - 1 for k in str] |
| 108 | |
| 109 | inputs = {'the_input': x, |
| 110 | 'the_labels': labels, |
| 111 | 'input_length': input_length, |
| 112 | 'label_length': label_length, |
| 113 | } |
| 114 | outputs = {'ctc': np.zeros([batchsize])} |
| 115 | yield (inputs, outputs) |
| 116 | |
| 117 | def ctc_lambda_func(args): |
| 118 | y_pred, labels, input_length, label_length = args |
no test coverage detected