Convert keras-yolo3 to onnx

TL;DR

-Original data learning procedure using Keras version implementation of YOLO v3 (as of June 24, 2020) HDF5 format (* .h5) created How to convert to ONNX format

Reference site

axinc-ai/yolov3-face onnx/keras-onnx

important point

Sometimes the converted onnx file could not be inferred. It can be inferred from the onnx file that was originally prepared.

The detailed conditions have not yet been identified.

1. Creating an environment

1.1. Source preparation

Clone with git from axinc-ai / yolov3-face

git clone https://github.com/axinc-ai/yolov3-face.git

Next, clone keras-yolo3 linked in yolov3-face.

cd .\yolov3-face
git clone https://github.com/qqwweee/keras-yolo3.git

1.2. Creating a python environment for conversion

Create a virtual environment "yolov3-face" with conda

conda create -n yolov3-face python=3.6 -y

Install the required modules. Since the detailed version is specified in axinc-ai / yolov3-face and it is not prepared in the conda repository, install it with pip.

conda activate yolov3-face
pip install tensorflow==1.13.2
pip install keras==2.2.4
pip install keras2onnx==1.5.1
pip install opencv-python
pip install pillow
pip install matplotlib

1.3. Creating a python environment for inference

Create virtual environment "yolov 3-face-inference" with conda

conda create -n yolov3-face-inference python=3.6 -y

Install the required modules. Since the detailed version is specified in axinc-ai / yolov3-face and it is not prepared in the conda repository, install it with pip.

conda activate yolov3-face-inference
pip install tensorflow==1.13.2
pip install onnxruntime
pip install keras==2.2.4
pip install pillow

2. Conversion and judgment (verified with the provided example)

First, verify with the prepared sample

2.1. Conversion

** Format **

python keras-yolo3-to-onnx.py <h5-model-filepath> <classes-filepath> <anchors-filepath> <onnx-filepath>
Parameters Contents to be specified
h5-model-filepath Model file created with keras
classes-filepath A file that describes the class name used when creating the model
anchors-filepath Anchor file used when creating the model
onnx-filepath Converted ONNX file

** Run **

cd .\keras-onnx

conda activate yolov3-face
python keras-yolo3-to-onnx.py ../model_data/logs/trained_weights_final.h5 ../model_data/face_classes.txt ../model_data/tiny_yolo_anchors.txt ../model_data/ax_face.onnx

2.2. Reasoning

** Format **

python inference.py <onnx-filepath> <classes-filepath> <targetimage-filepath> <outputimage-filepath>
Parameters Contents to be specified
onnx-filepath Converted ONNX file
classes-filepath A file that describes the class name used when creating the model
inputimage-filepath Image file to infer
outputimage-filepath File drawing the inference result

** Run **

cd .\keras-onnx

conda activate yolov3-face-inference
python inference.py ../model_data/ax_face.onnx ../model_data/face_classes.txt ../images/couple.jpg output.jpg

3. For files processed by Original data learning procedure using Keras version implementation of YOLO v3 (as of June 24, 2020)

File value
Model file created with keras ../model_data/yolo_logs/models/Step2_yolo_weight_mAP_best.h5
Class file ../model_data/voc_classes.txt
Anchor file ../model_data/yolo_anchors.txt
Converted ONNX file ../model_data/ax_yolov3.onnx

3.1. Conversion

cd .\keras-onnx

conda activate yolov3-face
python keras-yolo3-to-onnx.py ../model_data/yolo_logs/models/Step2_yolo_weight_mAP_best.h5 ../model_data/voc_classes.txt ../model_data/yolo_anchors.txt ../model_data/ax_yolov3.onnx

3.2. Reasoning

python inference.py ../model_data/ax_yolov3.onnx ../model_data/voc_classes.txt ../images/couple.jpg output.jpg

reference

keras-yolo3 + JetsonNano

https://qiita.com/rhene/items/b2a8ebe1f003e1107f63 http://mirai-tec.hatenablog.com/entry/2019/08/24/102129 http://mirai-tec.hatenablog.com/entry/2019/09/03/235156

YOLOv3(Darknet) + JetsonNano

https://soralab.space-ichikawa.com/2019/06/jetson-tx2-tensorrt-yolov3/ https://www.nakasha.co.jp/future/ai/vol2_yolov3nvidia_jetson_nano.html

TensorRT + Jetson Nano https://qiita.com/tsutof/items/f81d3900fa77d954ef39

Convert from kerass to ONNX

https://medium.com/axinc/yolov3-66c9b998c096

Other

https://qiita.com/agumon/items/114da6921c5dc4f7d7f9 https://github.com/zzh8829/yolov3-tf2 https://qiita.com/plseal/items/f493c67b2e810f2f876e http://mirai-tec.hatenablog.com/entry/2020/01/12/115546 https://rightcode.co.jp/blog/information-technology/tensorflow2-yolov3-run

Recommended Posts

Convert keras-yolo3 to onnx
Convert to HSV
Convert 202003 to 2020-03 with pandas
Convert kanji to kana
Convert dict to array
Convert json to excel
Convert hexadecimal string to binary
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
Convert HTML to text file
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
Convert IP address to decimal
Convert SDF to CSV quickly
Convert genbank file to gff file
Convert python 3.x code to python 2.x
Convert Tweepy Status object to JSON
Convert .ipynb to .html (with BatchFile)
Function to convert Excel column to number
Convert PDF to Documents by OCR
Convert markdown to PDF in Python
Convert A4 PDF to A3 every 2 pages
Convert wma to mp3 on Mac
Set opset to embed in ONNX
Convert some Japanese names to antonyms
convert ggplot based graph to html
Workflow to convert formula (image) to python
Convert list to DataFrame with python
Convert sentences to vectors with gensim
How to convert 0.5 to 1056964608 in one shot
Python> list> Convert double list to single list
Convert from pdf to txt 2 [pyocr]
How to convert Tensorflow model to Lite
Convert a string to an image
[Python] Convert natural numbers to ordinal numbers
Convert decimal numbers to n-ary numbers [python]
Program to convert Japanese to station name
How to convert from .mgz to .nii.gz
Convert PDF to image with ImageMagick
A tool to convert Juniper config
Python> tuple> Convert double tuple to single tuple
[Python] How to convert db file to csv
Convert xml format data to txt format data (yolov3)
Convert memo at once with Python 2to3
How to easily convert format from Markdown
Convert Python> two value sequence to dictionary
[Python] How to convert a 2D list to a 1D list
How to convert csv to tsv in CLI
How to convert Python to an exe file
Convert matplotlib graphs to emf file format
[Python] Convert csv file delimiters to tab delimiters
Convert from PDF to CSV with pdfplumber
Convert GFF3 to MSS for DDBJ submission
Convert (compress) formatted JSON string to 1-line JSON
Convert psd file to png in Python
Convert MetaImageIO (* .mha, * .mhd) to tiff stack
Convert character strings to features with RoBERTa
Convert Excel data to JSON with python
Convert from katakana to vowel kana [python]
Use pandas to convert grid data to row-holding (?) Data
Convert FX 1-minute data to 5-minute data with Python