alibaba / alibaba/TinyNeuralNetwork

请问下 转tflite 模型能支持签名吗?

Open
#299 9 comments 0 reactions 0 assignees View on GitHub
enhancement work/x-large
Dominant language
Python
Stars
879
Forks
134
PR merge metrics
No merged PRs in 30d

Description

在tflite2.7 版本后 已经支持多签名了:https://tensorflow.google.cn/lite/guide/signatures?hl=zh-cn

```py
class Model(tf.Module):

@tf.function(input_signature=[tf.TensorSpec(shape=[None], dtype=tf.float32)])
def encode(self, x):
result = tf.strings.as_string(x)
return {
"encoded_result": result
}

@tf.function(input_signature=[tf.TensorSpec(shape=[None], dtype=tf.string)])
def decode(self, x):
result = tf.strings.to_number(x)
return {
"decoded_result": result
}

model = Model()

# Save the model
SAVED_MODEL_PATH = 'content/saved_models/coding'

tf.saved_model.save(
model, SAVED_MODEL_PATH,
signatures={
'encode': model.encode.get_concrete_function(),
'decode': model.decode.get_concrete_function()
})

# Convert the saved model using TFLiteConverter
converter = tf.lite.TFLiteConverter.from_saved_model(SAVED_MODEL_PATH)
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]
tflite_model = converter.convert()

# Print the signatures from the converted model
interpreter = tf.lite.Interpreter(model_content=tflite_model)
signatures = interpreter.get_signature_list()
print(signatures)
```

这样一个tflite文件可以有多个graph,在调用的时候可以通过签名来找到子graph.
请教一下TinyNeuralNetwork能否支持一下这个功能?非常感谢啊!

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the TFLiteConverter flow and the signature handling demonstrated with interpreter.get_signature_list() in the issue. Define what support for multiple graphs and signature-based invocation should cover, then verify the converted model exposes and invokes both encode and decode signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.