tflite-rs
tflite-rs copied to clipboard
How to use tflite-rs with 4d Input and 2D Output
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?
ElemKindOf
for f32
is also implemented so you can get output data as f32
buffer. I think that the above code should work.
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
.
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?