Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Flocksserver opened this issue Jan 28, 2021 · 3 comments
Open

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

Flocksserver opened this issue Jan 28, 2021 · 3 comments

Comments

@Flocksserver
Copy link

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?

@boncheolgu
Copy link
Owner

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

@uttarayan21
Copy link

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.

@faviasono
Copy link

faviasono commented Nov 16, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants