All Projects → zldrobit → Onnx_tflite_yolov3

zldrobit / Onnx_tflite_yolov3

Licence: gpl-3.0
A Conversion tool to convert YOLO v3 Darknet weights to TF Lite model (YOLO v3 PyTorch > ONNX > TensorFlow > TF Lite), and to TensorRT (YOLO v3 Pytorch > ONNX > TensorRT).

Projects that are alternatives of or similar to Onnx tflite yolov3

Unity Detection2AR
Localize 2D image object detection in 3D Scene with Yolo in Unity Barracuda and ARFoundation.
Stars: ✭ 147 (+182.69%)
Mutual labels:  onnx, yolov3
Models
A collection of pre-trained, state-of-the-art models in the ONNX format
Stars: ✭ 4,226 (+8026.92%)
Mutual labels:  jupyter-notebook, onnx
YOLOX
YOLOX is a high-performance anchor-free YOLO, exceeding yolov3~v5 with MegEngine, ONNX, TensorRT, ncnn, and OpenVINO supported. Documentation: https://yolox.readthedocs.io/
Stars: ✭ 6,570 (+12534.62%)
Mutual labels:  onnx, yolov3
Yolov3 Tf2
YoloV3 Implemented in Tensorflow 2.0
Stars: ✭ 2,327 (+4375%)
Mutual labels:  jupyter-notebook, yolov3
Tensorflow Onnx
Convert TensorFlow models to ONNX
Stars: ✭ 900 (+1630.77%)
Mutual labels:  jupyter-notebook, onnx
Deepstream Project
This is a highly separated deployment project based on Deepstream , including the full range of Yolo and continuously expanding deployment projects such as Ocr.
Stars: ✭ 120 (+130.77%)
Mutual labels:  onnx, yolov3
Tensorflow 2.x Yolov3
YOLOv3 implementation in TensorFlow 2.3.1
Stars: ✭ 300 (+476.92%)
Mutual labels:  jupyter-notebook, yolov3
Person remover
People removal in images using Pix2Pix and YOLO.
Stars: ✭ 96 (+84.62%)
Mutual labels:  jupyter-notebook, yolov3
Trainyourownyolo
Train a state-of-the-art yolov3 object detector from scratch!
Stars: ✭ 399 (+667.31%)
Mutual labels:  jupyter-notebook, yolov3
Pytorchnethub
项目注释+论文复现+算法竞赛
Stars: ✭ 341 (+555.77%)
Mutual labels:  jupyter-notebook, yolov3
Yolov3 Point
从零开始学习YOLOv3教程解读代码+注意力模块(SE,SPP,RFB etc)
Stars: ✭ 119 (+128.85%)
Mutual labels:  jupyter-notebook, yolov3
Mlnet Workshop
ML.NET Workshop to predict car sales prices
Stars: ✭ 29 (-44.23%)
Mutual labels:  jupyter-notebook, onnx
Tensorflow2.0 Examples
🙄 Difficult algorithm, Simple code.
Stars: ✭ 1,397 (+2586.54%)
Mutual labels:  jupyter-notebook, yolov3
pytorch YOLO OpenVINO demo
No description or website provided.
Stars: ✭ 73 (+40.38%)
Mutual labels:  onnx, yolov3
Keras Oneclassanomalydetection
[5 FPS - 150 FPS] Learning Deep Features for One-Class Classification (AnomalyDetection). Corresponds RaspberryPi3. Convert to Tensorflow, ONNX, Caffe, PyTorch. Implementation by Python + OpenVINO/Tensorflow Lite.
Stars: ✭ 102 (+96.15%)
Mutual labels:  jupyter-notebook, onnx
Pytorch Yolov4
PyTorch ,ONNX and TensorRT implementation of YOLOv4
Stars: ✭ 3,690 (+6996.15%)
Mutual labels:  yolov3, onnx
Yolov5
YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
Stars: ✭ 19,914 (+38196.15%)
Mutual labels:  yolov3, onnx
Imagenet
Trial on kaggle imagenet object localization by yolo v3 in google cloud
Stars: ✭ 56 (+7.69%)
Mutual labels:  jupyter-notebook, yolov3
Distiller
Neural Network Distiller by Intel AI Lab: a Python package for neural network compression research. https://intellabs.github.io/distiller
Stars: ✭ 3,760 (+7130.77%)
Mutual labels:  jupyter-notebook, onnx
Yolov3
YOLOv3 in PyTorch > ONNX > CoreML > TFLite
Stars: ✭ 8,159 (+15590.38%)
Mutual labels:  yolov3, onnx

Introduction

A Conversion tool to convert YOLO v3 Darknet weights to TF Lite model (YOLO v3 PyTorch > ONNX > TensorFlow > TF Lite), and to TensorRT model (dynamic_axes branch).

Prerequisites

  • python3
  • torch==1.3.1
  • torchvision==0.4.2
  • onnx==1.6.0
  • onnx-tf==1.5.0
  • onnxruntime-gpu==1.0.0
  • tensorflow-gpu==1.15.0

Docker

docker pull zldrobit/onnx:10.0-cudnn7-devel

Usage

  • 1. Download pretrained Darknet weights:
cd weights
wget https://pjreddie.com/media/files/yolov3.weights 
  • 2. Convert YOLO v3 model from Darknet weights to ONNX model: Change ONNX_EXPORT to True in models.py. Run
python3 detect.py --cfg cfg/yolov3.cfg --weights weights/yolov3.weights

The output ONNX file is weights/export.onnx.

  • 3. Convert ONNX model to TensorFlow model:
python3 onnx2tf.py

The output file is weights/yolov3.pb.

  • 4. Preprocess pb file to avoid NCHW conv, 5-D ops, and Int64 ops:
python3 prep.py

The output file is weights/yolov3_prep.pb.

  • 5. Use TOCO to convert pb -> tflite:
toco --graph_def_file weights/yolov3_prep.pb \
    --output_file weights/yolov3.tflite \
    --output_format TFLITE \
    --inference_type FLOAT \
    --inference_input_type FLOAT \
    --input_arrays input.1 \
    --output_arrays concat_84

The output file is weights/yolov3.tflite. Now, you can run python3 tflite_detect.py --weights weights/yolov3.tflite to detect objects in an image.

Quantization

  • 1. Install flatbuffers: Please refer to flatbuffers.

  • 2. Download TFLite schema:

wget https://github.com/tensorflow/tensorflow/raw/r1.15/tensorflow/lite/schema/schema.fbs
  • 3. Run TOCO to convert and quantize pb -> tflite:
toco --graph_def_file weights/yolov3_prep.pb \
    --output_file weights/yolov3_quant.tflite \
    --output_format TFLITE  \
    --input_arrays input.1 \
    --output_arrays concat_84 \
    --post_training_quantize

The output file is weights/yolov3_quant.tflite.

  • 4. Convert tflite -> json:
flatc -t --strict-json --defaults-json -o weights schema.fbs  -- weights/yolov3_quant.tflite

The output file is weights/yolov3_quant.json.

  • 5. Fix ReshapeOptions:
python3 fix_reshape.py

The output file is weights/yolov3_quant_fix_reshape.json.

  • 6. Convert json -> tflite:
flatc -b -o weights schema.fbs weights/yolov3_quant_fix_reshape.json

The output file is weights/yolov3_quant_fix_reshape.tflite. Now, you can run

python3 tflite_detect.py --weights weights/yolov3_quant_fix_reshape.tflite

to detect objects in an image.

Auxiliary Files

  • ONNX inference and detection: onnx_infer.py and onnx_detect.py.
  • TensorFlow inference and detection: tf_infer.py and tf_detect.py.
  • TF Lite inference, detection and debug: tflite_infer.py, tflite_detect.py and tflite_debug.py.

Known Issues

  • The conversion code does not work with tensorflow==1.14.0: Running prep.py cause protobuf error (Channel order issue in Conv2D).
  • fix_reshape.py does not fix shape attributes in TFLite tensors, which may cause unknown side effects.

TODO

  • [x] support tflite quantized model
  • [x] use dynamic_axes for ONNX export to support dynamic batching and TensorRT conversion (dynamic_axes branch)
  • [x] add TensorRT NMS support (trt_nms branch)

Acknowledgement

We borrow PyTorch code from ultralytics/yolov3, and TensorFlow low-level API conversion code from paulbauriegel/tensorflow-tools.

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].