Giter Site home page Giter Site logo

Comments (3)

cocoa-xu avatar cocoa-xu commented on May 25, 2024 1

Hi @mnishiguchi, I also added tests for TFLiteElixir.TFLiteTensor, including improved error messages when backend is invalid. What do you think?

https://github.com/cocoa-xu/tflite_elixir/blob/d2a7cfb77cbc67dfc8ef324f74db0d10b2e308ec/test/tflitetensor_test.exs#L126-L194

from tflite_beam.

cocoa-xu avatar cocoa-xu commented on May 25, 2024

This should be better now. :)

iex> alias TFLiteElixir.InterpreterBuilder
TFLiteElixir.InterpreterBuilder
iex> alias TFLiteElixir.Ops.Builtin.BuiltinResolver
TFLiteElixir.Ops.Builtin.BuiltinResolver
iex> alias TFLiteElixir.FlatBufferModel
TFLiteElixir.FlatBufferModel
iex> alias TFLiteElixir.Interpreter
TFLiteElixir.Interpreter
iex> alias TFLiteElixir.TFLiteTensor
TFLiteElixir.TFLiteTensor
iex> filename = Path.join([__DIR__, "test", "test_data", "mobilenet_v2_1.0_224_inat_bird_quant.tflite"])
"./test/test_data/mobilenet_v2_1.0_224_inat_bird_quant.tflite"
iex> model = FlatBufferModel.build_from_file(filename)
#FlatBufferModel<%{
  "initialized" => true,
  "metadata" => %{"TFLITE_METADATA" => <<28>>, "min_runtime_version" => "1.5.0"},
  "minimum_runtime" => "1.5.0"
}>
iex> resolver = BuiltinResolver.new!()
#Reference<0.331881720.996278283.169380>
iex> builder = InterpreterBuilder.new!(model, resolver)
#Reference<0.331881720.996278283.169392>
iex> interpreter = Interpreter.new!()
INFO: Initialized TensorFlow Lite runtime.
#Reference<0.331881720.996278283.169402>
iex> :ok = InterpreterBuilder.build!(builder, interpreter)
:ok
iex> :ok = Interpreter.allocate_tensors(interpreter)
:ok
iex> t = Interpreter.tensor(interpreter, 0)
%TFLiteElixir.TFLiteTensor{
  name: "map/TensorArrayStack/TensorArrayGatherV3",
  index: 0,
  shape: [1, 224, 224, 3],
  shape_signature: [1, 224, 224, 3],
  type: {:u, 8},
  quantization_params: %TFLiteElixir.TFLiteQuantizationParams{
    scale: [0.0078125],
    zero_point: [128],
    quantized_dimension: 0
  },
  sparsity_params: %{},
  reference: #Reference<0.331881720.996278283.169424>
}
iex> TFLiteTensor.to_nx(t)
#Nx.Tensor<
  u8[1][224][224][3]
  [
    [
      [
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, ...],
        ...
      ],
      ...
    ]
  ]
>
iex> TFLiteTensor.to_nx(t, backend: nil)
#Nx.Tensor<
  u8[1][224][224][3]
  [
    [
      [
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, ...],
        ...
      ],
      ...
    ]
  ]
>
iex> TFLiteTensor.to_nx(t, backend: Nx.BinaryBackend)
#Nx.Tensor<
  u8[1][224][224][3]
  [
    [
      [
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, ...],
        ...
      ],
      ...
    ]
  ]
>

from tflite_beam.

mnishiguchi avatar mnishiguchi commented on May 25, 2024

Nice! The new error message is a lot less scary. Thank you!

from tflite_beam.

Related Issues (17)

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.