keras-ocr
keras-ocr copied to clipboard
Prediction Confidence
Hi Team,
I am working on a problem which requires to have the confidence value along with the predictions as well. And having looked at the base code, I can't find a way to make it work for me.
This issue is a continuation of the issue#177, can someone help me with this?
Best.
Hi, any progress on this one? We are also very interested in getting the confidence value along with the predictions
HI, nothing yet.
Will be working on this issue later this month. Will update accordingly.
I am outputting the softmax in CTCDecoder, seems to work at giving a basic confidence level.
def CTCDecoder():
def decoder(y_pred):
input_shape = tf.keras.backend.shape(y_pred)
input_length = tf.ones(shape=input_shape[0]) * tf.keras.backend.cast(
input_shape[1], 'float32')
unpadded = tf.keras.backend.ctc_decode(y_pred, input_length)[0][0]
unpadded_shape = tf.keras.backend.shape(unpadded)
padded = tf.pad(unpadded,
paddings=[[0, 0], [0, input_shape[1] - unpadded_shape[1]]],
constant_values=-1)
# Find the max softmax values to use as confidence
softmax = tf.math.top_k(
y_pred[0], k=1, sorted=True, name=None
)[0]
return [padded, softmax]
return tf.keras.layers.Lambda(decoder, name='decode')
I am new with tf helpers so let me know if there is a more straight forward solution.