1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Tensorflow lite sample code does not work from the tutorials

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    https://ai.google.dev/edge/litert/models/signatures#java I have the model generated, I have the model loaded. I verified this because I can see the signatures that are available:

    I don't know what the encoded_result and decoded_result variables should be. Can someone give me a concrete example code?

    val encodeInput = mutableMapOf<String, Any>()
    val encodeOutput = mutableMapOf<String, Any>()

    encodeInput["x"] = arrayOf(floatArrayOf(9f))
    encodeOutput["encoded_result"] = arrayOf(arrayOf("9"))

    interpreter!!.runSignature(encodeInput,encodeOutput, "encode")

    val decodeInput = mutableMapOf<String, Any>()
    val decodeOutput = mutableMapOf<String, Any>()

    decodeOutput["decoded_result"] = arrayOf(arrayOf("9"))
    decodeInput["x"] = arrayOf(floatArrayOf(9f))

    interpreter!!.runSignature(decodeInput, decodeOutput, "decode")`


    This is what I have and this is the tf functions:

    `

    @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
    }`


    I understand the encodeInput[x] we're passing in the value of x to be encoded but are we also telling the function what the output of x will be ? encoded_result: result? If so , what is the point of the method if we tell it what the input and output will be for both the encode and decode function? If I can working kotlin code that would help me IMMENSELY. Thank you!

    I've tried countless example code and I expected no errors and the decodeOutput to be of the format encoded_result: "9" "decoded_result: 9

    but I keep getting these Cannot convert between a TensorFlowLite tensor with type STRING and a Java object of type [[F (which is compatible with the TensorFlowLite type FLOAT32).

    and also changed code around and was getting: StringToNumberOp errors

    things I have tried: I was able to just create a simple addition function to take in a number and add 5 to it and that works but when i try to use string manipulations that fails. I want to be able to pass in lists of string data and have that be fed to the model for training on device specifically.

    Continue reading...

Compartilhe esta Página