All Projects → finnickniu → Tensorflow_object_detection_tflite

finnickniu / Tensorflow_object_detection_tflite

Licence: mit
This is a repo for training and implementing the mobilenet-ssd v2 to tflite with c++ on x86 and arm64

Projects that are alternatives of or similar to Tensorflow object detection tflite

Tensorflow2.0 Examples
🙄 Difficult algorithm, Simple code.
Stars: ✭ 1,397 (+5720.83%)
Mutual labels:  object-detection, tensorflow-examples
Math object detection
An image recognition/object detection model that detects handwritten digits and simple math operators. The output of the predicted objects (numbers & math operators) is then evaluated and solved.
Stars: ✭ 52 (+116.67%)
Mutual labels:  object-detection, tensorflow-examples
Yolov3 Tf2
YoloV3 Implemented in Tensorflow 2.0
Stars: ✭ 2,327 (+9595.83%)
Mutual labels:  object-detection, tensorflow-examples
Tf Object Detection
Simpler app for tensorflow object detection API
Stars: ✭ 91 (+279.17%)
Mutual labels:  object-detection, tensorflow-examples
Fire Detection Cnn
real-time fire detection in video imagery using a convolutional neural network (deep learning) - from our ICIP 2018 paper (Dunnings / Breckon) + ICMLA 2019 paper (Samarth / Bhowmik / Breckon)
Stars: ✭ 340 (+1316.67%)
Mutual labels:  object-detection, tensorflow-examples
Orb slam2 ssd semantic
动态语义SLAM 目标检测+VSLAM+光流/多视角几何动态物体检测+octomap地图+目标数据库
Stars: ✭ 763 (+3079.17%)
Mutual labels:  object-detection
Global Localization Object Detection
a global localization system with object detection in semantic map
Stars: ✭ 5 (-79.17%)
Mutual labels:  object-detection
Avod
Code for 3D object detection for autonomous driving
Stars: ✭ 757 (+3054.17%)
Mutual labels:  object-detection
Bmw Tensorflow Training Gui
This repository allows you to get started with a gui based training a State-of-the-art Deep Learning model with little to no configuration needed! NoCode training with TensorFlow has never been so easy.
Stars: ✭ 736 (+2966.67%)
Mutual labels:  object-detection
Efficientdet Pytorch
A PyTorch impl of EfficientDet faithful to the original Google impl w/ ported weights
Stars: ✭ 906 (+3675%)
Mutual labels:  object-detection
Machine Learning Collection
A resource for learning about ML, DL, PyTorch and TensorFlow. Feedback always appreciated :)
Stars: ✭ 883 (+3579.17%)
Mutual labels:  tensorflow-examples
My Tensorflow Tutorials
This repo contains all of my TensorFlow tutorials
Stars: ✭ 795 (+3212.5%)
Mutual labels:  tensorflow-examples
Mxnet Ssd
MXNet port of SSD: Single Shot MultiBox Object Detector. Reimplementation of https://github.com/weiliu89/caffe/tree/ssd
Stars: ✭ 766 (+3091.67%)
Mutual labels:  object-detection
Tensorlayer
Deep Learning and Reinforcement Learning Library for Scientists and Engineers 🔥
Stars: ✭ 6,796 (+28216.67%)
Mutual labels:  object-detection
Deepcamera
Open source face recognition on Raspberry Pi. SharpAI is open source stack for machine learning engineering with private deployment and AutoML for edge computing. DeepCamera is application of SharpAI designed for connecting computer vision model to surveillance camera. Developers can run same code on Raspberry Pi/Android/PC/AWS to boost your AI production development.
Stars: ✭ 757 (+3054.17%)
Mutual labels:  object-detection
Federated Benchmark
A Benchmark of Real-world Image Dataset for Federated Learning
Stars: ✭ 18 (-25%)
Mutual labels:  object-detection
Getting Things Done With Pytorch
Jupyter Notebook tutorials on solving real-world problems with Machine Learning & Deep Learning using PyTorch. Topics: Face detection with Detectron 2, Time Series anomaly detection with LSTM Autoencoders, Object Detection with YOLO v5, Build your first Neural Network, Time Series forecasting for Coronavirus daily cases, Sentiment Analysis with BERT.
Stars: ✭ 738 (+2975%)
Mutual labels:  object-detection
Ailab
Experience, Learn and Code the latest breakthrough innovations with Microsoft AI
Stars: ✭ 6,896 (+28633.33%)
Mutual labels:  object-detection
Yolo annotation tool
Annotation tool for YOLO in opencv
Stars: ✭ 17 (-29.17%)
Mutual labels:  object-detection
Cvpr2021 Paper Code Interpretation
cvpr2021/cvpr2020/cvpr2019/cvpr2018/cvpr2017 论文/代码/解读/直播合集,极市团队整理
Stars: ✭ 8,075 (+33545.83%)
Mutual labels:  object-detection

System Environment:

System: Ubuntu 18.04

Opencv: opencv 3.2

Tensorflow: 1.13.1

Instructions:

The instruction for mobilenet-ssdv2 training

Convert images to tf.record

  1. Write label.pbtxt under the path models/research/object_detection/mobilenet_ssd_v2_train/dataset/ The format like this:
    item {
   id: 1
   name: 'person'
}
 
    item {
   id: 2
   name: 'car'
}


  1. Convert yout images and annotations to tfrecord by models datatool api.

    Commands:

    cd models/research/
    export PYTHONPATH=$PYTHONPATH:path to /models/research/:path to/models/research/slim
    protoc object_detection/protos/*.proto --python_out=.
    python object_detection/dataset_tools/create_coco_tf_record.py --image_dir=/path_to/img/ --ann_dir=/path_to/ann/ --output_path=/path_to/train.record --label_map_path=/path_to/demo/label.pbtxt

Train tensorflow model(fine tuning)

  1. Download the 'mobilenet ssd v2 quantized' model from model zoo, and replace it with models/research/object_detection/mobilenet_ssd_v2_train/pretrained_models(the origin one is the 'mobilenet ssd v2 quantized' as well)
  2. Modify the data path in pipeline.config. The data is the tf record you generated.
   train
   input_path:  "/path_to/train.record"

   test
   input_path:  "/path_to/train.record"
  1. Training
    
    cd models/research/
    export PYTHONPATH=$PYTHONPATH: path to /models/research/:path to/models/research/slim
    protoc object_detection/protos/*.proto --python_out=.
    python object_detection/legacy/train.py --train_dir=path to /models/research/object_detection/mobilenet_ssd_v2_train/CP/ --pipeline_config_path=path to/models/research/object_detection/mobilenet_ssd_v2_train/pipeline.config

  1. Using Tensorboard to visualize your training process
    tensorboard --logdir=/path_to/mobilenet_ssd_v2_train/CP
  1. Export your model to frozen graph, which can cheeck the results with demo.py.
    python object_detection/export_inference_graph.py --input_type=image_tensor --pipeline_config_path=/path_to/pipleline.config --trained_checkpoint_prefix=/path_to/mobilenet_ssd_v2_train/CP/model.ckpt-xxxxxx --output_directory=/path_to/mobilenet_ssd_v2_train/IG/
  1. Add label_map.json.
    {
        "1": "person"
    }
    {
        "2": "car"
    }
  1. Run demo.py.
    python demo.py PATH_TO_FROZEN_GRAPH cam_dir js_file
  1. Convert frozen_graph to tf_lite Use export_tflite_ssd_graph.py generate tflite_graph.pb
    python object_detection/export_tflite_ssd_graph.py --input_type=image_tensor --pipeline_config_path=path to/models/research/object_detection/mobilenet_ssd_v2_train/IG/pipeline.config --trained_checkpoint_prefix=path to/models/research/object_detection/mobilenet_ssd_v2_train/IG/model.ckpt --output_directory=path to/models/research/object_detection/mobilenet_ssd_v2_train/tflite --add_postprocessing_op=true
  1. Convert tflite_graph.pb to model.tflite
    tflite_convert --output_file=path to/models/research/object_detection/mobilenet_ssd_v2_train/tflite/model.tflite --graph_def_file=path to/models/research/object_detection/mobilenet_ssd_v2_train/tflite/tflite_graph.pb --input_arrays=normalized_input_image_tensor --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' --input_shape=1,300,300,3 --allow_custom_ops --output_format=TFLITE --inference_type=QUANTIZED_UINT8 --mean_values=128 --std_dev_values=127

Apply tflite model with c++

  1. Modify the line 89 at demo.cpp
   tflite::FlatBufferModel::BuildFromFile("../model.tflite");
  1. Modify the labelmap.txt with you annotation if you fine tuned your model.

  2. Run demo.cpp on x86 unbuntu, make sure opencv and bazel are installed.

    1. Build libtensorflowlite.so, under the tensorflow directory.
                bazel build -c opt //tensorflow/lite:libtensorflowlite.so --fat_apk_cpu=arm64-v8a
    
    1. Move .so to tensorflow_object_detection_tflite/lib
    2. Change find_library(TFLITE_LIBRARY tensorflow-lite "lib") to find_library(TFLITE_LIBRARY tensorflowlite "lib") in CMakeLists.txt.
    3. Build cmake
            mkdir build
            cd build
            cmake ..
            make -j
            ./demo
    
  3. Run demo.cpp on arm64-v8a ubuntu.

    1. Intall opencv on your arm64 motherboard.
    2. Build libtensorflow-lite.a, followed by the tensorflow tutorial https://www.tensorflow.org/lite/guide/build_arm64. Careful about the arm version, v7 or v8.
    3. Move .a to tensorflow_object_detection_tflite/lib
    4. keep find_library(TFLITE_LIBRARY tensorflow-lite "lib") unchanged.
    5. Build cmake
            mkdir build
            cd build
            cmake ..
            make -j
            ./demo
    
  4. If there is a flatbuffers error, you should build flatbuffers on your desktop, and use its header files and .a lib file, put and replace them into tensorflow_object_detection_tflite/include and tensorflow_object_detection_tflite/lib, respectively. You can check here to know how to build. https://github.com/google/flatbuffers/issues/5569#issuecomment-543777629

  5. Result image

Screenshot

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].