Search code examples
tensorflowobject-detection

how to get percentage of predicted value in Tensorflow Object Detection API?


I have already used object_detection_tutorial.ipynb to display object detector with percentage of predicted value,but the variable num_detections is a TensorVariable such as Tensor("num_detections:0", dtype=float32) ,so how can I print the percentage of predicted value?


Solution

  • What do you mean with num_detections is a TensorVariable? As you can see from their code, they're returning this tensor, num_detections = detection_graph.get_tensor_by_name('num_detections:0'). In this case num_detections is by default 100 because they trained their model this way. To get the percentage of predicted value, you rather need the scores. Let's say that your threshold is at 0.5, you could calculate the percentage of predicted value this way:

    import numpy as np
    
    threshold = 0.5 # in order to get higher percentages you need to lower this number; usually at 0.01 you get 100% predicted objects
    print(len(np.where(scores[0] > threshold)[0]) / num_detections[0])