Generating Training Data
Augmentated Images Generating...
Type 1 finish
Type 2 finish
Type 3 finish
Type 4 finish
Type 5 finish
Augmentated Images Generated
Original Images Generating...
Type 1 finish
Type 2 finish
Type 3 finish
Type 4 finish
Type 5 finish
Original Images Generated
Perspective Images Generating...
Type 1 finish
Type 2 finish
Type 3 finish
Type 4 finish
Type 5 finish
Perspective Images Generated
Done.
Generating Validation Data
Augmentated Images Generating...
Type 1 finish
Type 2 finish
Type 3 finish
Type 4 finish
Type 5 finish
Augmentated Images Generated
Original Images Generating...
Type 1 finish
Type 2 finish
Type 3 finish
Type 4 finish
Type 5 finish
Original Images Generated
Perspective Images Generating...
Type 1 finish
Type 2 finish
Type 3 finish
Type 4 finish
Type 5 finish
Perspective Images Generated
Done.
CHAR_VECTOR ="adefghjknqrstwABCDEFGHIJKLMNOPZ0123456789"letters = [letter for letter in CHAR_VECTOR]num_classes =len(letters) +1img_w, img_h =128, 64# Network parametersbatch_size =128val_batch_size =16downsample_factor =4max_text_len =9K.set_learning_phase(0)
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
fig, axes = plt.subplots(nrows =4, ncols =2, figsize = (16, 16))plt.setp(axes.flat, xticks = [], yticks = [])inp, out = datagen.__getitem__(0)c =1for i, ax inenumerate(axes.flat): ax.imshow(inp['the_input'][c].reshape(img_w, img_h).T) ax.set_xlabel(labels_to_text(inp['the_labels'][c])) c +=1plt.show()
Network Architecture
# # Loss and train functions, network architecturedef ctc_lambda_func(args): y_pred, labels, input_length, label_length = args# the 2 is critical here since the first couple outputs of the RNN# tend to be garbage: y_pred = y_pred[:, 2:, :]return K.ctc_batch_cost(labels, y_pred, input_length, label_length)
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:793: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.
def decode_label(out):# out : (1, 32, 42) out_best =list(np.argmax(out[0, 2:], axis=1)) # get max index -> len = 32 out_best = [k for k, g in itertools.groupby(out_best)] # remove overlap value outstr =''for i in out_best:if i <len(letters): outstr += letters[i]return outstr
def label_to_hangul(label): # eng -> hangul region = label[0] two_num = label[1:3] hangul = label[3:5] four_num = label[5:]try: region = Region[region] if region !='Z'else''except:passtry: hangul = Hangul[hangul]except:passreturn region + two_num + hangul + four_num
model = get_Model(training =False)model.load_weights('CuDNNLSTM+BN5--29--0.211--0.319.hdf5')
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4479: The name tf.truncated_normal is deprecated. Please use tf.random.truncated_normal instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:190: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:197: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:2041: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py:1354: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
inp, out = valid_datagen.__getitem__(0)images = inp['the_input']images.shape