Is there a way to get bounding boxes from the Microsoft's custom vision object detection model.pb file?

情到浓时终转凉″ 提交于 2019-12-04 15:40:35

You seem to be using python, so you can export the object-detection model from the customvision UI (select tensorflow options):

https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/export-model-python

which will give you a zipfile containing:

labels.txt
model.pb
python/object_detection.py
python/predict.py

Put everything in one directory then simply execute the code:

python predict.py image.jpg

Hey presto! This will print out a list of dictionaries like

{'boundingBox': {'width': 0.92610852, 'top': -0.06989955, 'height': 0.85869097, 'left': 0.03279033}, 'tagId': 3, 'tagName': 'myTagName', 'probability': 0.24879535}

The coordinates (relative to top left) are normalized to the width and height of the image.

Here is main (not my code!):

def main(image_filename):
    # Load a TensorFlow model
    graph_def = tf.GraphDef()
    with tf.gfile.FastGFile(MODEL_FILENAME, 'rb') as f:
        graph_def.ParseFromString(f.read())

    # Load labels
    with open(LABELS_FILENAME, 'r') as f:
        labels = [l.strip() for l in f.readlines()]

    od_model = TFObjectDetection(graph_def, labels)

    image = Image.open(image_filename)
    predictions = od_model.predict_image(image)
    print(predictions)

which you can modify as you see fit. Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!