mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

Output model tensorflow

Open watermellon2018 opened this issue 1 year ago • 6 comments

I convert model tensorflow lite into tensorflow. And i predict the pose estimate at image. Output is tensor of shape [39 5]. I need only key points of body and coordinates. I get slice [0:33, 0:3] and i want it to draw at image. How i can do that? The range output model strange, it is not [0-1], i try to put this is at image with shape 256*256, but it is not correct. I try to use Sigmoid for predict tensor, but get strange values, example: [[1.000+00, 6.526e-29, 0], [1.000+00, 8.36e-31, 0], [0.0000009, 0.99999991] Thanks

watermellon2018 avatar Jul 27 '22 02:07 watermellon2018

Normalization not help, i convert prediction array to range [0; 1] by divide 255 and get this: image

watermellon2018 avatar Jul 27 '22 06:07 watermellon2018

Hi @watermellon2018, Is it implemented through python, Javascript or others? Could you please help me in reproducing the same with complete steps at our end. Thank you!

kuaashish avatar Jul 28 '22 08:07 kuaashish

@kuaashish It is implemented through python. I use tensorflow model pose_landmark_heavy. I pass image into model and get tensor with shape 1, 195, make reshape (39, 5), get only 33 points and 2 (x, y) coordinates, then i flip horizontal and normalized it Code:

TFLITE_FILE_PATH = 'model_float32.pb' # i convert tflite into tf
    graph_def = tf.compat.v1.GraphDef()
    with tf.io.gfile.GFile(TFLITE_FILE_PATH, 'rb') as f:
        graph_def.ParseFromString(f.read())
        tf.import_graph_def(graph_def, name='')

    input_node = 'input_1:0'
    output_layer = 'Identity:0'

 with tf.compat.v1.Session() as sess:
        prob_tensor = sess.graph.get_tensor_by_name(output_layer)
        predictions = sess.run(prob_tensor, {input_node: [input_data] })

        predictions = predictions.reshape((1, 39, 5))
        print(np.min(predictions[0, :, 0:2]), np.max(predictions[0, :, 0:2]))
        predictions = predictions[:, 0:33, 0:2][0]
        predictions[:, 0] = (256 - predictions[:, 0]) / 256
        predictions[:, 1] = predictions[:, 1] / 256

watermellon2018 avatar Jul 28 '22 10:07 watermellon2018

Hi @watermellon2018, Have you looked at this closed issue #1701 and comment. Thank you!

kuaashish avatar Jul 28 '22 10:07 kuaashish

@kuaashish Thank you. I added normalize image and post proccessing of the prediction, it a little bit help. But when i merged prediction from Python API and prediction from Tensorflow model. I get this (blue - python api / green - tensorflow): myplot

watermellon2018 avatar Jul 29 '22 05:07 watermellon2018

@watermellon2018 Good jobs, can you share your codes? The picture seems to be from the bgr channel.

liuyulvv avatar Aug 02 '22 14:08 liuyulvv

Hi @watermellon2018, This issue to more related to tensorflow. Could you please raise this issue into tensorflow repo. Thank you!

kuaashish avatar Aug 10 '22 16:08 kuaashish

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] avatar Aug 17 '22 17:08 google-ml-butler[bot]

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] avatar Aug 24 '22 18:08 google-ml-butler[bot]