tensorflow: TFlite Custom trained model Issue (IndexError: invalid index to scalar variable)

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 and Raspbian
  • TensorFlow installed from (source or binary): TF
  • TensorFlow version (or github SHA if from source): 2.3.1

Command used to run the converter or code if you’re using the Python API If possible, please share a link to Colab/Jupyter/any notebook.

python /content/models/research/object_detection/exporter_main_v2.py \
    --trained_checkpoint_dir training \
    --output_directory inference_graph \
    --pipeline_config_path training/ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8.config

The output from the converter invocation

Output succeeded. (not sure what to put here)

Also, please include a link to the saved model or GraphDef

Model: https://drive.google.com/drive/folders/17iEVFzQjqhI6zP4zUJP0uTAnBy2TnWPR?usp=sharing
TFLiteModel :https://drive.google.com/drive/folders/1BCcWG-89OHts-510sev1VJepbDQkt9s0?usp=sharing

Failure details If the conversion is successful, but the generated model is wrong, state what is wrong:

I trained a SSD_MobilenetV2_FPN_680x680 to detect only black bears successfully and converted to tflite by following this guide: https://github.com/TannerGilbert/Tensorflow-Object-Detection-API-Train-Model.

I then followed EdjeElectronics’ guide on how to run tflite on Raspberry Pi: https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi/blob/master/Raspberry_Pi_Guide.md.

But, when I try to run TFLite_detection_webcam.py It gives an error:

pi@raspberrypi:~ $ source tflite1-env/bin/activate bash: tflite1-env/bin/activate: No such file or directory pi@raspberrypi:~ $ cd tflite1 pi@raspberrypi:~/tflite1 $ source tflite1-env/bin/activate (tflite1-env) pi@raspberrypi:~/tflite1 $ python3 TFLite_detection_webcam.py --modeldir=Bear_Detector_TFLite_model Traceback (most recent call last): File “TFLite_detection_webcam.py”, line 185, in <module> boxes = interpreter.get_tensor(output_details[0][‘index’])[0] # Bounding box coordinates of detected objects IndexError: invalid index to scalar variable.

I run his sample tflite model and it works. I’m guessing my the SSD_MobilenetV2_fpn model isnt compatible for Raspberry PI?

Im sorry if this post is not in the correct place or if I’m missing key info for help. I’m pretty new to all this stuff.

Any other info / logs

TFLite_detection_webcam.py https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi/blob/master/TFLite_detection_webcam.py

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

FIX: Rather than taking the classes at the 0th index of the output list, taking the 3rd one seemed to fix the issue.

boxes = interpreter.get_tensor(output_details[1]['index'])
classes = interpreter.get_tensor(output_details[3]['index'])
scores = interpreter.get_tensor(output_details[0]['index'])

At first, printing all the outputs after interpreter.invoke() seemed to give a zero array at the 3rd index of the list. Then I did remember that we had a label_id_offset that was causing the values to go to zero.