From dd52837f0a46bfab0c80ef802276647f8f6523a9 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Wed, 12 Feb 2025 18:45:27 +0100 Subject: [PATCH 1/4] chore: bump tflite_beam to v0.3.8 Signed-off-by: Cocoa --- mix.exs | 4 ++-- mix.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 5162c42..7c2ef5d 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule TFLiteElixir.MixProject do require Logger @app :tflite_elixir - @version "0.3.7" + @version "0.3.8" @github_url "https://github.com/cocoa-xu/tflite_elixir" def project do @@ -27,7 +27,7 @@ defmodule TFLiteElixir.MixProject do defp deps do [ - {:tflite_beam, "~> 0.3.6"}, + {:tflite_beam, "~> 0.3.8"}, {:nx, "~> 0.5"}, {:stb_image, "~> 0.6"}, {:ex_doc, "~> 0.27", only: :docs, runtime: false} diff --git a/mix.lock b/mix.lock index 24360ce..a9a62db 100644 --- a/mix.lock +++ b/mix.lock @@ -11,5 +11,5 @@ "nx": {:hex, :nx, "0.6.4", "948d9f42f81e63fc901d243ac0a985c8bb87358be62e27826cfd67f58bc640af", [:mix], [{:complex, "~> 0.5", [hex: :complex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bb9c2e2e3545b5eb4739d69046a988daaa212d127dba7d97801c291616aff6d6"}, "stb_image": {:hex, :stb_image, "0.6.4", "d7cf19791e80d2d18ef1a5f3f6a8a828e76871f6bb4c20d860a5fa58779c70aa", [:make, :mix], [{:cc_precompiler, "~> 0.1.0", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.7.0", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: true]}, {:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: true]}], "hexpm", "2719309d9e59271c0f92cfae5bd569690bbbad48bcb9b38b2b3d9d8856fa2d47"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, - "tflite_beam": {:hex, :tflite_beam, "0.3.6", "5ea1c0d98e8a35b561c8b5ff018781c25a18cb516344d6629763d930e611229a", [:rebar3], [], "hexpm", "695226c8ab6a0b4ddff505a69f3459202c14d3c679b3e946fa3a946801e4fe7a"}, + "tflite_beam": {:hex, :tflite_beam, "0.3.8", "ed8ee5dd40941197670ce2a7430b0f39b23a16d22e663f6aec5e6ff41ece23c4", [:rebar3], [], "hexpm", "54a0e2fb7e76253de76d18ed13a59fa47b7bbb09b923d5c9b23a69ef4b7e5c06"}, } From cbd00cc33c3edb4bab5336988cb5d84d66f4d26b Mon Sep 17 00:00:00 2001 From: Cocoa Date: Wed, 12 Feb 2025 18:47:54 +0100 Subject: [PATCH 2/4] chore: bump nerves-build Signed-off-by: Cocoa --- .github/workflows/nerves-build.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nerves-build.yml b/.github/workflows/nerves-build.yml index 24691fa..7a5aaa2 100644 --- a/.github/workflows/nerves-build.yml +++ b/.github/workflows/nerves-build.yml @@ -48,7 +48,7 @@ jobs: env: MIX_ENV: prod NERVES_PROJ_NAME: nerves_tflite - NERVES_LIVEBOOK_VER: "v0.14.0" + NERVES_LIVEBOOK_VER: "v0.14.2" TFLITE_BEAM_PREFER_PRECOMPILED: "true" TFLITE_BEAM_CORAL_SUPPORT: "true" @@ -94,7 +94,8 @@ jobs: libedgetpu_library: armv7l steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: @@ -109,8 +110,8 @@ jobs: mix local.hex --force mix local.rebar --force mix archive.install hex nerves_bootstrap --force - wget -k https://github.com/fwup-home/fwup/releases/download/v1.11.0/fwup_1.11.0_amd64.deb -O fwup_1.11.0_amd64.deb - sudo dpkg -i fwup_1.11.0_amd64.deb + wget -k https://github.com/fwup-home/fwup/releases/download/v1.11.0/fwup_1.12.0_amd64.deb -O fwup_1.12.0_amd64.deb + sudo dpkg -i fwup_1.12.0_amd64.deb - name: Make a nerves project run: | @@ -138,12 +139,12 @@ jobs: cp "./_build/${MIX_TARGET}_${MIX_ENV}/nerves/images/nerves_livebook.fw" "/tmp/firmware/${NERVES_PROJ_NAME}_${{ matrix.pair.target }}_${MIX_ENV}.fw" - name: Upload build artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.NERVES_PROJ_NAME }}_${{ matrix.pair.target }}_${{ env.MIX_ENV }}.fw path: /tmp/firmware/${{ env.NERVES_PROJ_NAME }}_${{ matrix.pair.target }}_${{ env.MIX_ENV }}.fw - - uses: softprops/action-gh-release@v1 + - uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: files: /tmp/firmware/${{ env.NERVES_PROJ_NAME }}_${{ matrix.pair.target }}_${{ env.MIX_ENV }}.fw From 7259e2c3a7b63684eaf33b4cb588c970a13572c5 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Wed, 12 Feb 2025 18:59:29 +0100 Subject: [PATCH 3/4] updated unit tests Signed-off-by: Cocoa --- lib/tflite_elixir/flatbuffer_model.ex | 9 +++++++-- test/interpreter_test.exs | 4 ++-- test/test_data/parrot-expected-out.bin | Bin 965 -> 965 bytes test/tflite_task_classify_image_test.exs | 12 ++++++------ test/tflite_task_detect_image_test.exs | 20 ++++++++++---------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/tflite_elixir/flatbuffer_model.ex b/lib/tflite_elixir/flatbuffer_model.ex index 9a1e3d2..d2c01cd 100644 --- a/lib/tflite_elixir/flatbuffer_model.ex +++ b/lib/tflite_elixir/flatbuffer_model.ex @@ -3,7 +3,6 @@ defmodule TFLiteElixir.FlatBufferModel do An RAII object that represents a read-only tflite model, copied from disk, or mmapped. """ - import TFLiteElixir.Errorize alias TFLiteElixir.ErrorReporter @@ -48,7 +47,13 @@ defmodule TFLiteElixir.FlatBufferModel do end end - deferror(build_from_file(filename, opts)) + def build_from_file!(filename, opts) do + case build_from_file(filename, opts) do + {:error, message} when is_list(message) -> raise List.to_string(message) + {:error, message} when is_binary(message) -> raise message + res -> res + end + end @doc """ Verifies whether the content of the file is legit, then builds a model diff --git a/test/interpreter_test.exs b/test/interpreter_test.exs index 25b4c0d..ab34e25 100644 --- a/test/interpreter_test.exs +++ b/test/interpreter_test.exs @@ -90,7 +90,7 @@ defmodule TFLiteElixir.Interpreter.Test do filename = Path.join([__DIR__, "test_data", "mobilenet_v2_1.0_224_inat_bird_quant.tflite"]) interpreter = Interpreter.new!(filename) - assert 67 == Interpreter.nodes_size(interpreter) + assert 65 == Interpreter.nodes_size(interpreter) end test "nodes_size/1 with invalid interpreter" do @@ -102,7 +102,7 @@ defmodule TFLiteElixir.Interpreter.Test do filename = Path.join([__DIR__, "test_data", "mobilenet_v2_1.0_224_inat_bird_quant.tflite"]) interpreter = Interpreter.new!(filename) - assert [65, 62, 66, 64] == Interpreter.execution_plan(interpreter) + assert Enum.to_list(0..64) == Interpreter.execution_plan(interpreter) end test "execution_plan/1 with invalid interpreter" do diff --git a/test/test_data/parrot-expected-out.bin b/test/test_data/parrot-expected-out.bin index b103da24a658affd7249ec62775d196e3e93527d..d53ebdee9ab5e8738c7d3c96d36ed6f07e0c248c 100644 GIT binary patch delta 31 ncmX@gew2NJ%S0uGi2^JWGkO`>Co;-y7GZ2>Vq7zM4znfzq74ar delta 29 lcmX@gew2NJ%Vaqwm5CX>jBFDb List.delete_at(0) |> List.delete_at(0) |> Enum.join("\n") + + assert result =~ "-------RESULTS--------" + assert result =~ "Ara macao (Scarlet Macaw): 0.7" + assert result =~ "Platycercus elegans (Crimson Rosella): 0." + assert result =~ "Coracias caudatus (Lilac-breasted Roller): 0." end @tag :require_tpu diff --git a/test/tflite_task_detect_image_test.exs b/test/tflite_task_detect_image_test.exs index dd26f8a..9f00396 100644 --- a/test/tflite_task_detect_image_test.exs +++ b/test/tflite_task_detect_image_test.exs @@ -19,16 +19,16 @@ defmodule TFLiteElixir.Test.DetectImage do ) end) - """ - cat - id : 16 - score: 0.934 - bbox : [3, -1, 294, 240] - """ = - String.split(output, "\n") - |> List.delete_at(0) - |> List.delete_at(0) - |> Enum.join("\n") + assert """ + cat + id : 16 + score: 0.953 + bbox : [3, -1, 294, 240] + """ = + String.split(output, "\n") + |> List.delete_at(0) + |> List.delete_at(0) + |> Enum.join("\n") end @tag :require_tpu From 022ea0ac8915d74a5c328a0858e05ecec8314ec4 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Wed, 12 Feb 2025 19:02:04 +0100 Subject: [PATCH 4/4] chore: bump nerves-build Signed-off-by: Cocoa --- .github/workflows/nerves-build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nerves-build.yml b/.github/workflows/nerves-build.yml index 7a5aaa2..6e02ca1 100644 --- a/.github/workflows/nerves-build.yml +++ b/.github/workflows/nerves-build.yml @@ -51,6 +51,7 @@ jobs: NERVES_LIVEBOOK_VER: "v0.14.2" TFLITE_BEAM_PREFER_PRECOMPILED: "true" TFLITE_BEAM_CORAL_SUPPORT: "true" + FWUP_VERSION: "1.12.0" strategy: fail-fast: false @@ -110,8 +111,8 @@ jobs: mix local.hex --force mix local.rebar --force mix archive.install hex nerves_bootstrap --force - wget -k https://github.com/fwup-home/fwup/releases/download/v1.11.0/fwup_1.12.0_amd64.deb -O fwup_1.12.0_amd64.deb - sudo dpkg -i fwup_1.12.0_amd64.deb + curl -fSL "https://github.com/fwup-home/fwup/releases/download/v${FWUP_VERSION}/fwup_${FWUP_VERSION}_amd64.deb" -o "fwup_${FWUP_VERSION}_amd64.deb" + sudo dpkg -i "fwup_${FWUP_VERSION}_amd64.deb" - name: Make a nerves project run: |