tflite-rs icon indicating copy to clipboard operation
tflite-rs copied to clipboard

How to use tflite-rs with 4d Input and 2D Output

Open Flocksserver opened this issue 4 years ago • 3 comments

Hey guys, I am a bit lost. I would like to port python tflite code to rust. I have a model with: Input conv2d_6_input type float32[1,16,35,1] Output float32[1,1]

The corresponding python code looks like this:

        input = np.float32(current_mfccs.reshape(1, current_mfccs.shape[0], current_mfccs.shape[1], 1))
        self.interpreter.set_tensor(self.input_details[0]['index'], input)
        self.interpreter.invoke()
        output = self.interpreter.get_tensor(self.output_details[0]['index'])
        val = output[0][0]

Is this possible with the current state of the crate? If I see it correct, only types of ElemKindOf can be retrieved as output. And therefore float32[1,1] for example is not supported? Is there sth. I have missed/misunderstood?

Flocksserver avatar Jan 28 '21 13:01 Flocksserver

ElemKindOf for f32 is also implemented so you can get output data as f32 buffer. I think that the above code should work.

boncheolgu avatar Jan 29 '21 00:01 boncheolgu

I still don't quite understand how to take the input as a 4d array, could you provide an example in rust ? @boncheolgu I'm also trying to port similar python code to tflite-rs.

uttarayan21 avatar Feb 11 '22 09:02 uttarayan21

Hi, I am trying to use the example to run on a random input but I am not sure how to pass the input_tensor to the Interpreter. With tflite we could do with float* input = interpreter->typed_input_tensor<float>(0);, but not clear with tflite-rs. The example uses input_file.read_exact(interpreter.tensor_data_mut(input_index)?)?; but I just want to try with a random input. Do you have any help?

faviasono avatar Nov 16 '22 14:11 faviasono