GithubHelp home page GithubHelp logo

cocoa-xu / tflite_beam Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 5.0 30.71 MB

TensorFlow Lite Erlang bindings with optional EdgeTPU support.

License: Apache License 2.0

CMake 3.80% Makefile 2.10% C++ 64.96% C 1.81% Shell 3.48% Python 1.52% Erlang 22.32%
tensorflow-lite tpu-acceleration erlang erlang-library erlang-nif

tflite_beam's Issues

precompile for armv6?

any reason they are not precompiled presently?

tflite_elixir seems to have armv6 support..

TFLiteTensor.dims vs out_tensor.shape

This is rather a question about accessing tensor fields.

As I play with the Super Resolution example, I notice there are two ways to access shape and type of a tensor and they seem to give the same result at least in the context of the example. I am wondering if there is a case where we have to use the functions. Depending on it, we might need to explain in the doc or to consider deprecating the functions.

out_tensor.shape
# vs
TFLite.TFLiteTensor.dims(out_tensor)
out_tensor.type
# vs
type = TFLite.TFLiteTensor.type(out_tensor)

Missing module/function docs

Here are a list of blank documents as of 2023-03-14

module docs

  • TFLiteElixir (top-level module)
  • TFLiteElixir.Ops.Builtin.BuiltinResolver
  • TFLiteElixir.Coral

function docs

  • TFLiteElixir.reset_variable_tensor/1
  • TFLiteElixir.Coral.contains_edge_tpu_custom_op?/1
  • TFLiteElixir.Coral.dequantize_tensor/2
  • TFLiteElixir.Coral.edge_tpu_devices/0
  • TFLiteElixir.Coral.get_edge_tpu_context/1
  • TFLiteElixir.Coral.get_edge_tpu_context/2
  • TFLiteElixir.Coral.make_edge_tpu_interpreter/2
  • TFLiteElixir.FlatBufferModel.initialized/1
  • TFLiteElixir.Interpreter.get_signature_defs/1
  • TFLiteElixir.Interpreter.predict/2

cryptic `TFLiteTensor.to_nx/2` error message when no Nx backend provided

When TFLiteTensor.to_nx/2 is called without Nx backend provided, a cryptic error can occur. I am wondering if there is a way to make this error less cryptic and/or to print a human friendly error message.

https://hexdocs.pm/tflite_elixir/TFLiteElixir.TFLiteTensor.html#to_nx/2

The error seems to occur when Nx.from_binary/3 is called.

https://hexdocs.pm/nx/Nx.html#from_binary/3

** (UndefinedFunctionError) function nil.from_binary/3 is undefined
    nil.from_binary(#Inspect.Error<
  got KeyError with message:

      """
      key :__struct__ not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
      """

  while inspecting:

      %{__struct__: Nx.Tensor, data: nil, names: [nil], shape: {100}, type: {:f, 32}}

  Stacktrace:

    (nx 0.5.1) lib/nx/tensor.ex:165: Inspect.Nx.Tensor.inspect/2
    (elixir 1.14.3) lib/inspect/algebra.ex:341: Inspect.Algebra.to_doc/2
    (elixir 1.14.3) lib/kernel.ex:2254: Kernel.inspect/2
    (elixir 1.14.3) lib/exception.ex:717: anonymous fn/2 in Exception.format_arity/1
    (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir 1.14.3) lib/exception.ex:717: Exception.format_arity/1
    (elixir 1.14.3) lib/exception.ex:712: Exception.format_mfa/3
    (elixir 1.14.3) lib/exception.ex:623: Exception.format_stacktrace_entry/1

>, <<105, 9, 17, 64, 151, 171, 24, 191, 192, 69, 116, 62, 25, 75, 60, 63, 192, 10, 3, 192, 114, 80, 4, 63, 114, 80, 4, 64, 16, 4, 201, 63, 36, 209, 246, 63, 154, 234, 95, 191, 79, 52, 183, 190, 79, 52, 183, 190, 7, 189, ...>>, [])
    (tflite_elixir 0.1.5) lib/tflite_elixir/tflite_tensor.ex:124: TFLiteElixir.TFLiteTensor.to_nx/2

This error can be recreated just by removing :backend option in the examples/artistic_style_transfer.livemd notebook.

Add a wrapper layer `TFLite.Backend` for `TfLiteTensor`

Right now we have something like

Nx.tensor([1, 2, 3])
|> Nx.to_binary()
|> then(&TFTensor.set_data!(input_tensor, &1))

the goal is to do the same thing without explicitly calling to_binary/from_binary (maybe also include some other functions).

tensor = Nx.tensor([1, 2, 3])
tf_tensor = Nx.backend_transfer(tensor, TFLite.Backend)

TFLite.run(model, tf_tensor)
#=> This will also return a tensor allocated on TFLite.Backend

tensor = Nx.tensor([1, 2, 3])
TFLite.run(model, tensor)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.