Skip to content

Commit

Permalink
Upgrade to onnxruntime 1.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Jan 14, 2023
1 parent afbcfb4 commit b2af638
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ COPY lib/ ./lib/
RUN mkdir -p /usr/local/include/onnxruntime && \
tar -C /usr/local/include/onnxruntime \
--strip-components 1 \
-xvf "lib/onnxruntime-${TARGETARCH}${TARGETVARIANT}.tgz"
-xvf "lib/onnxruntime-linux-${TARGETARCH}${TARGETVARIANT}.tgz"

# Build larynx binary
COPY Makefile ./
Expand All @@ -50,10 +50,10 @@ RUN mkdir -p larynx && \
cp -dR /usr/share/espeak-ng-data ./larynx/ && \
cp -d /usr/local/include/onnxruntime/lib/libonnxruntime.so.* ./larynx/ && \
cp /build/build/larynx ./larynx/ && \
tar -czf larynx.tar.gz larynx/
tar -czf "larynx_${TARGETARCH}${TARGETVARIANT}.tar.gz" larynx/

# -----------------------------------------------------------------------------

FROM scratch

COPY --from=build /dist/larynx.tar.gz ./
COPY --from=build /dist/larynx_*.tar.gz ./
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Download a release:
* [amd64](https://github.com/rhasspy/larynx2/releases/download/v0.0.1/larynx_amd64.tar.gz) (desktop Linux)
* [arm64](https://github.com/rhasspy/larynx2/releases/download/v0.0.1/larynx_arm64.tar.gz) (Raspberry Pi 4)

If you want to build from source, see the [Makefile](Makefile) and [C++ source](src/cpp).
If you want to build from source, see the [Makefile](Makefile) and [C++ source](src/cpp). Last tested with [onnxruntime](https://github.com/microsoft/onnxruntime) 1.13.1.


## Usage
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
1 change: 0 additions & 1 deletion lib/onnxruntime-amd64.tgz

This file was deleted.

1 change: 0 additions & 1 deletion lib/onnxruntime-arm64.tgz

This file was deleted.

1 change: 0 additions & 1 deletion lib/onnxruntime-armv7.tgz

This file was deleted.

Binary file removed lib/onnxruntime-linux-aarch64-1.12.1.tgz
Binary file not shown.
Binary file added lib/onnxruntime-linux-aarch64-1.13.1.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions lib/onnxruntime-linux-amd64.tgz
1 change: 1 addition & 0 deletions lib/onnxruntime-linux-arm64.tgz
Binary file removed lib/onnxruntime-linux-armhf-1.12.0.tgz
Binary file not shown.
Binary file removed lib/onnxruntime-linux-x64-1.12.1.tgz
Binary file not shown.
Binary file added lib/onnxruntime-linux-x64-1.13.1.tgz
Binary file not shown.
15 changes: 0 additions & 15 deletions src/cpp/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const string instanceName{"larynx"};

struct ModelSession {
Ort::Session onnx;
vector<char *> inputNames;
vector<char *> outputNames;
Ort::AllocatorWithDefaultOptions allocator;
Ort::SessionOptions options;
Ort::Env env;
Expand Down Expand Up @@ -48,19 +46,6 @@ void loadModel(string modelPath, ModelSession &session) {
session.onnx = Ort::Session(session.env, modelPath.c_str(), session.options);
auto endTime = chrono::steady_clock::now();
auto loadDuration = chrono::duration<double>(endTime - startTime);

size_t numInputNodes = session.onnx.GetInputCount();
size_t numOutputNodes = session.onnx.GetOutputCount();

for (size_t i = 0; i < numInputNodes; i++) {
session.inputNames.push_back(
session.onnx.GetInputName(i, session.allocator));
}

for (size_t i = 0; i < numOutputNodes; i++) {
session.outputNames.push_back(
session.onnx.GetOutputName(i, session.allocator));
}
}

} // namespace larynx
Expand Down
13 changes: 9 additions & 4 deletions src/cpp/synthesize.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SYNTHESIZE_H_
#define SYNTHESIZE_H_

#include <array>
#include <chrono>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -64,12 +65,16 @@ void synthesize(SynthesisConfig &synthesisConfig, ModelSession &session,
speakerIdShape.size()));
}

// From export_onnx.py
array<const char *, 4> inputNames = {"input", "input_lengths", "scales",
"sid"};
array<const char *, 1> outputNames = {"output"};

// Infer
auto startTime = chrono::steady_clock::now();
auto outputTensors =
session.onnx.Run(Ort::RunOptions{nullptr}, session.inputNames.data(),
inputTensors.data(), inputTensors.size(),
session.outputNames.data(), session.outputNames.size());
auto outputTensors = session.onnx.Run(
Ort::RunOptions{nullptr}, inputNames.data(), inputTensors.data(),
inputTensors.size(), outputNames.data(), outputNames.size());
auto endTime = chrono::steady_clock::now();

if ((outputTensors.size() != 1) || (!outputTensors.front().IsTensor())) {
Expand Down

0 comments on commit b2af638

Please sign in to comment.