How do get label map file

I am asking for your help. I am just a beginner who is not familiar with TensorFlow datasets. I want to run EfficientDet-Lite2 to detect objects on Raspberry Pi 4, but I lack the label map file. Could you please guide me on how to obtain the label map file from “TensorFlow Hub”?

@arliang,

Welcome to the Tensorflow Forum,

When you load the tensorflow datasets by default it will get features and labels.

Could you please let us know, how you are loading the dataset?

Thank you!

OK!

The issue I encountered is with invoking, not training.
With simplified code, I can correctly obtain the output data from TensorFlow.
However, the classes are represented as index numbers, and I need a label map file to know the corresponding names for each index. I’m not sure how to obtain the label map file.

interpreter = tf.lite.Interpreter(model_path="efficient.lite2")
interpreter.set_tensor(input_details[0]['index'],   .....image data.... )
interpreter.invoke()
classes = interpreter.get_tensor(output_details)

Since I’m just a beginner and want to directly use existing models for object detection in photos, I imported the model from the following link:

TensorFlow Hub

@arliang,

Can you please refer to this object detection example, which uses tensorflow hub and loads the label map data for plotting and let us know if it helps?

Thank you!

1 Like

YES
This is my code, along with the images generated after identification.

interpreter = tf.lite.Interpreter(model_path="efficient.lite2")
interpreter.set_tensor(input_details[0]['index'],   .....image data.... )
interpreter.invoke()
boxes = detector.get_tensor(output_details[0]['index'])[0] # 
classes = detector.get_tensor(output_details[1]['index'])[0] # 
scores = detector.get_tensor(output_details[2]['index'])[0] #     
rangeNumber = detector.get_tensor(output_details[3]['index'])[0] #     
object_detector_num = len([x for x in scores if x > min_conf_threshold and x <= 1.0])

    for i in range(int(rangeNumber)):
        if ((scores[i] > min_conf_threshold) and (scores[i] <= 1.0)):
            ymin = int(max(1,(boxes[i][0] * imH)))
            xmin = int(max(1,(boxes[i][1] * imW)))
            ymax = int(min(imH,(boxes[i][2] * imH)))
            xmax = int(min(imW,(boxes[i][3] * imW)))
            img_boxes = cv2.rectangle(image_bgr, (xmin,ymin), (xmax,ymax), (10, 255, 0), 2)
            font = cv2.FONT_HERSHEY_SIMPLEX
            cv2.putText(img_boxes, str(classes[i]),(xmin, ymax-10), font, 0.5, (255,0,0), 2, cv2.LINE_AA)
            cv2.putText(img_boxes,str(scores[i]),(xmax, ymax-10), font, 0.5, (255,0,0), 2, cv2.LINE_AA) 

@arliang,

Did you try looking at this example which uses label map and apply it to the predictions?

Thank you!

I have already read this article, but I’m sorry, I don’t understand what it is trying to convey. You have been helping me all along, but it seems that you haven’t fully understood my question. All I need is the label map file. How can I get the label map file?
Could you please guide me on how to obtain the label map file from “TensorFlow Hub ”?

I feel confused too. TensorFlow Hub provides a user-friendly tool that allows everyone to use modules, so why don’t they make it simple and easy for us to obtain the label file?

@arliang,

We understand your concern. The label map is not directly available in TF hub. You can either get it from COCO label map available here or use TFLite which comes with model metadata. The metadata contains the label map information as well. Please check the Efficientdet lite model with metadata here.

To get started, TFLite provides tflite-support library where we can use TFLite model with metadata and get the predictions along with labels.

Please find this gist doing the same with the help of TF hub model.

Thank you!

1 Like

I sincerely appreciate your help. Your answer has broadened my horizons and resolved my long-standing doubts. Please accept my boundless gratitude.

2 Likes

@arliang,

Also, if we have a tflite model which has metadata, for example TensorFlow Hub , we can simply get the label map file by unzip command.

unzip path/lite-model_efficientdet_lite2_detection_metadata_1.tflite

Thank you!