Install onnxoptimizer

This commit is contained in:
Fangjun Kuang 2024-04-09 14:55:58 +08:00
parent 10ae39f8ab
commit 589eb626f9
16 changed files with 26 additions and 8 deletions

View File

@ -2,6 +2,8 @@
set -ex set -ex
python3 -m pip install onnxoptimizer
log() { log() {
# This function is from espnet # This function is from espnet
local fname=${BASH_SOURCE[1]##*/} local fname=${BASH_SOURCE[1]##*/}

View File

@ -49,6 +49,7 @@ RUN pip install --no-cache-dir \
multi_quantization \ multi_quantization \
numba \ numba \
numpy \ numpy \
onnxoptimizer \
onnx \ onnx \
onnxmltools \ onnxmltools \
onnxruntime \ onnxruntime \

View File

@ -55,6 +55,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -55,6 +55,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -69,6 +69,7 @@ RUN pip uninstall -y tqdm && \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -56,6 +56,7 @@ RUN pip install --no-cache-dir \
onnx \ onnx \
onnxruntime \ onnxruntime \
onnxmltools \ onnxmltools \
onnxoptimizer \
multi_quantization \ multi_quantization \
typeguard \ typeguard \
numpy \ numpy \

View File

@ -38,6 +38,7 @@ from typing import Dict
import k2 import k2
import onnx import onnx
import onnxoptimizer
import torch import torch
import torch.nn as nn import torch.nn as nn
from onnxruntime.quantization import QuantType, quantize_dynamic from onnxruntime.quantization import QuantType, quantize_dynamic
@ -234,12 +235,13 @@ def export_audio_tagging_model_onnx(
def optimize_model(filename): def optimize_model(filename):
# see https://github.com/microsoft/onnxruntime/issues/1899#issuecomment-534806537 # see
from onnx import optimizer # https://github.com/microsoft/onnxruntime/issues/1899#issuecomment-534806537
# and
# https://github.com/onnx/onnx/issues/582#issuecomment-937788108
passes = ["extract_constant_to_initializer", "eliminate_unused_initializer"] passes = ["extract_constant_to_initializer", "eliminate_unused_initializer"]
onnx_model = onnx.load(filename) onnx_model = onnx.load(filename)
optimized_model = optimizer.optimize(onnx_model, passes) optimized_model = onnxoptimizer.optimize(onnx_model, passes)
onnx.save(optimized_model, filename) onnx.save(optimized_model, filename)

View File

@ -8,13 +8,14 @@ pypinyin==0.50.0
tensorboard tensorboard
typeguard typeguard
dill dill
onnx==1.15.0 onnx>=1.15.0
onnxruntime==1.16.3 onnxruntime>=1.16.3
onnxoptimizer
# style check session: # style check session:
black==22.3.0 black==22.3.0
isort==5.10.1 isort==5.10.1
flake8==5.0.4 flake8==5.0.4
# cantonese word segment support # cantonese word segment support
pycantonese==3.4.0 pycantonese==3.4.0