keras-ocr icon indicating copy to clipboard operation
keras-ocr copied to clipboard

Prediction Confidence

Open D3nii opened this issue 2 years ago • 3 comments

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.

D3nii avatar Apr 06 '22 08:04 D3nii

Hi, any progress on this one? We are also very interested in getting the confidence value along with the predictions

raduslmn avatar May 30 '22 12:05 raduslmn

HI, nothing yet.

Will be working on this issue later this month. Will update accordingly.

D3nii avatar May 30 '22 20:05 D3nii

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.

AnthonyDipilato avatar Jul 05 '22 16:07 AnthonyDipilato