19 releases

new 0.21.8 Dec 5, 2024
0.21.7 Sep 23, 2024
0.21.6 Jul 24, 2024
0.21.2 Mar 29, 2024
0.20.22 Nov 28, 2023

#991 in Machine learning

Download history 8/week @ 2024-08-20 23/week @ 2024-08-27 31/week @ 2024-09-03 40/week @ 2024-09-10 113/week @ 2024-09-17 150/week @ 2024-09-24 85/week @ 2024-10-01 39/week @ 2024-10-08 13/week @ 2024-10-15 7/week @ 2024-10-22 9/week @ 2024-10-29 45/week @ 2024-11-05 33/week @ 2024-11-12 47/week @ 2024-11-19 52/week @ 2024-11-26 636/week @ 2024-12-03

768 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

2MB
47K SLoC

tract-tflite

unimplemented, sausage is being made. If you want to help feel free to open a PR.

link to the tflite c api

link to the related issue

The generated code handles creating a model from a flatbuffer table. Right now the main task (as far as I understand) is to start adding the code to build a Tract Model from the ModelBuffer.

So the modelBuffer(the model read from a flatbuffer file) has a few components (with associated functions) worth looking at: operator_codes, subgraphs, and then buffers.

  • subgraphs are likely the primary thing needed to create a tract model
    • composed of tensors, inputs,outputs, operators, and a name
    • input and output are fairly small vectors, I suspect they may be indices
  • buffers are sometimes empty (why?)

Metadata

Tensors

  • probably need to convert from the generated datatypes to Tract's DatumType. it's in the toplevel data crate.
    • this is part of the depenendency tract-core
  • SO: what a variant tensor?

Operators

  • the list of builtin Operators can be found in the generated tflite schema around line 443 in the const array ENUM_VALUES_BUILTIN_OPERATOR: [BuiltinOperator; 162].
  • the official docs on supported supset of tensorflow operators in TFLite
  • the tflite c code

Subgraphs

Right now, I'm testing with a specific model under test data, so this might not generalize to other models. If you open the model in netron, you'll find 3 separate graphs: main, sequential/net/while_cond, and sequential/net/while_body.

In the main graph, node 10 is just listed as while, but it's actually composed of the other subgraphs.

scratchpad

I created a repository for the sole purpose of poking around with tflite models, if you would like to add a model for testing please put it inside test data, and add any test input to lfs. If you write some utility that would be useful for others contributers, feel free to add it. Otherwise just clone it and forget it, it's just trow-away code.

Dependencies

~14–22MB
~331K SLoC