tensorflow.jstensorflowjs-converter

Text Detection using tensorflowjs


I want to do text detection in an image using only tensorfow.js or opencv.js, i have already build a EAST model on keras and converted to tensorflowjs model

can anyone help me with this, any resource will be great

Thanks.


Solution

  • So, initially you need to download the East frozen model and then conver it to tensorflow.js model by using the below command

    tensorflowjs_converter --input_format=tf_frozen_model --output_node_names='feature_fusion/Conv_7/Sigmoid,feature_fusion/concat_3' /path_to_model  /path_to_where_you_want_save_converted_model.
    
    

    Next after taking an input image and loading the model the below code will detect the text is there or not

     $("#predict-button").click(async function () {
            let image = $("#selected-image").get(0);
            let tensor = tf.browser.fromPixels(image)
                .resizeNearestNeighbor([640, 320])
                .expandDims(0);
                
    
        tensor = tf.cast(tensor, 'float32')
        const [output1, output2] = await model.predict(tensor);
        const data1 = await output1.data();
        const data2 = await output2.data();
    

    As the east model gives two outputs i.e. scores and geometry. so here data1 will give the geometry (which I ignored because my end goal was to detect if the text is present not to localize it) and data2 will give the scores.

    Next, I put a threshold of 0.5 to differentiate between the text is present or not. if the probability is greater than 0.5 then the text is present and if less than 0.5 than the text is not present on text.

    Note: for now, I have skipped the preprocessing step (except resize) where they subtract the mean RGB value from an RGB value of input image.