autorope / donkeycar

Open source hardware and software platform to build a small scale self driving car.
http://www.donkeycar.com
MIT License
3.17k stars 1.3k forks source link

Update stop sign detector to run without EdgeTPU #953

Open Ezward opened 3 years ago

Ezward commented 3 years ago

The StopSignDetector runs a canned version of mobilenet for the EdgeTPU. This means that anyone that wants to use the stop sign detector must have an EdgeTPU. We should generalize the stop sign detector so it can also run the model on an RPi or a Nano.

Current code is using this model: https://github.com/google-coral/edgetpu/raw/master/test_data/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite That model will recognize a stop sign without any additional training.

So we could use that same ssd mobilenet v2 coco in a more generic tflite variation, then modify the code run it on the RPi; see https://github.com/google-coral/edgetpu/blob/master/test_data/ssd_mobilenet_v2_coco_quant_postprocess.tflite.

See https://medium.datadriveninvestor.com/mobile-object-detector-with-tensorflow-lite-9e2c278922d0 and https://www.tensorflow.org/lite/examples/object_detection/overview for some related info.

Further, we could then compile the .tf file using the Nvidia compiler to get a file that will run fast on the Nano's GPU.

  1. Generalize the code so it can run either the EdgeTPU version or the CPU (tflite) version.
  2. Add configuration to choose either EdgeTPU or CPU
  3. Add support for JetsonNano GPU;
    • compile the model to an optimized version for the Jetson;
    • modify the code to enable it if on the Nano.
    • Add configuration to select GPU version
Ezward commented 2 years ago

It looks like Tensorflow has changed their approach to object detection; https://www.tensorflow.org/lite/examples/object_detection/overview So we might want to use the Tensorflow Object Detection API https://github.com/tensorflow/models/tree/master/research/object_detection

There are now better models that mobilenet; a little research on state of the art my yield higher accuracy than mobilenet can provid.

Ezward commented 1 year ago

Note on performance; remember that we are also running the normal autopilot model, so performance described above will be low because we are trying to run multiple models. No one has done this as yet, so we don't know what the performance would be.

Ezward commented 1 year ago

Ok, now Google has deprecated https://github.com/tensorflow/models/tree/master/research/object_detection, and now recommends https://github.com/tensorflow/models/tree/master/official/vision Google sucks. This thing looks harder to use, perhaps just go back to the original mobilenet suggestion in the initial issue description.

Ezward commented 1 year ago

A user on discord also has used this tensorflow-lite example for people detection on small images (160x120) on the RaspberryPi

cfox570 commented 1 year ago

See Pull Request StopSign and Cone Detection https://github.com/autorope/donkeycar/pull/1131 I used TensorFlow Lite Object Detection with a custom cone model to implement traffic cone avoidance. It was tested with Raspberry Pi 4. I am adding a pull request for the docs Create object_detection.md https://github.com/autorope/donkeycar/pull/51