8000 GitHub - alexkrz/convert-models: Repository to convert Pytorch models to ONNX
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

alexkrz/convert-models

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert Models

The conversion is expected to be run from the root directory of the project. First, we download the official Pytorch checkpoints from CR-FIQA: https://github.com/fdbtrs/CR-FIQA.

We put the checkpoints in a folder checkpoints/ within the root directory. Our folder structure should then look as follows:

root/
├── checkpoints/
│   ├── onnx/
│   │   ├── ...
│   └── pytorch/
│       ├── CRFIQA-L/
│       │   ├── 181952backbone.pth
│       │   └── training.log
│       └── CRFIQA-S/
│           └── 32572backbone.pth
├── cpp/
├── data/
├── python/
├── results/

Python setup

  1. Navigate into python folder

  2. Set up conda environment

    conda env create -n convert -f environment.yml
  3. Install pip dependencies

    conda activate convert
    pip install -r requirements.txt

Now, we can convert the model by activating the conda environment and running from the root directory:

python python/convert_model.py

Test the pytorch model on sample data

For testing the model checkpoints, we use the Labeled Faces in the Wild (LFW) dataset: https://www.kaggle.com/datasets/jessicali9530/lfw-dataset.

We unzip the images into the data directory at data/lfw-deepfunneled/.

Next, we can run the Pytorch script by running:

python python/compute_quality.py

The results will be stored in a .txt file at results/crfiqa-l_lfw.txt.

Test the onnx model on sample data

Next, we want to test the converted onnx model on the LFW dataset.

Therefore, we run the following python script:

python python/run_onnx.py

The results will be stored in a .txt file at results/crfiqa-l_lfw_onnx.txt.

Test the onnx model in CPP framework

To test the onnx model in a CPP framework, we need to setup the corresponding environment.

The project requires cmake >= 3.23 and conan > 2.0. If you cannot install these dependencies directly on your system, we recommend to use a conda virtual environment.

To set up the conda virtual environment, navigate into the cpp folder and run

conda env create -n conan -f environment.yml

The required packages are then installed in a conda environment with the name conan.

Fur further information on compiling the C++ code, look into cpp/README.md.

Resources

List of useful resources:

Todos

  • Use opencv instead of onnxruntime
  • Compare results between pytorch model and onnx model
  • Add cpp implementation for onnx model
  • Replace absolut paths in example.cpp

About

Repository to convert Pytorch models to ONNX

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0