-
Notifications
You must be signed in to change notification settings - Fork 222
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
Shape of input array in Conv1D operation #213
Comments
Hey @matteodonati, yes the input sizes are correct here but the expected types in the model are not. It looks like the convolutional layer is expecting a symmetric quantized input (signed char) but you are passing a float to it.
Is your input data a float? if so I recommend stitching in a symmetric quantize operator. This ops quantization params should be configured by the codegen (either directly in your model code or in the model params header file). If that doesn't work, you can get the zero point and scale directly from your tflite model via netron. TflmSymQuantOps::QuantizeOperator<int8_t, float> quantOp;
Tensor qInput = new RamTensor({1, 150, 6}, i8);
int32_t qInput_zp = -128;
float qInput_scale = 1.0;
PerTensorQuantizationParams qInput_quant_params(
qInput_zp, qInput_scale);
qInput->set_quantization_params(qInput_quant_params);
quantOp
.set_inputs({
{TflmSymQuantOps::QuantizeOperator<int8_t, float>::input, input},
})
.set_outputs({{TflmSymQuantOps::QuantizeOperator<int8_t, float>::output,
qInput}})
.eval(); One final note: Your input is a Let me know if you have any questions |
Thank you for the quick response @mbartling! I confirm that I used Keras to define, train and evaluate my model. Below is the code used to create it:
where And this is the code used to generate the C++ model:
where This is the output generated when I try to create the C++ model:
I also attached the three generated files (my_model.zip): my_model.zip Is the Thank you very much. |
Ah confirmed, the model looks correct! Turns out we added a bunch more quantized operators recently, including quantized Conv2D, and those are waiting for the next minor release. You can get them working by switching the uTensor branch from FYI, the operators maintain a mostly common interface/bit accurate computation across namespaces, so things like Conv2D can be interchanged just by changing the namespace in the model header. For example, the default reference quantized Conv2D stores weights as floats, but does accumulation with floats for clarity (slow on embedded systems), whereas the |
Thank you! I tried to switch uTensor to
I'm sorry to bother you this much. |
Cool I fixed a small issue with duplicate names in that operator (using @dboyliao can you add a test for this op? |
You mean |
@matteodonati which branch do you compile against? FYI, |
@dboyliao I updated the |
Oh, I see. |
Hey @matteodonati, sorry for the inconvenience, but ReduceMean is one of the few untested ops in uTensor. We will work on adding a test and letting you know when it's done. For now I will go ahead and mark it with the correct tag. |
FYI, this is the relevant PR: |
Thank you everyone! I was able to compile the application. The problem now is that for every different This is the code used in main.cpp:
|
Yeah my guess is this has to do with the reduce mean. Do you have access to a debugger? If so can you check that the inputs to reduce mean are always different? |
Unfortunately I don't, I'm sorry. |
Hey @matteodonati i think I know what the issue is with reduce mean, I will work on a fix for it sometime this afternoon and let you know. |
Thank you very much, I'll wait! |
Update: I am dumb and misread MaxPool as ReduceMean, so that's not the issue. @dboyliao @matteodonati do you know how weights are stored in kera's Conv1D? I know TFLM does some shuffling of the weight tensor, and may be that only affects Conv2D. |
@mbartling It looks like the filter shape is of |
It basically create a variable tensor and return it. |
If it can help, I just tried to use Conv2D instead of Conv1D in Keras:
so now I tried to compile the application using the same version of uTensor used in utensor-helloworld and this gave me the same error posted here. |
Just double checking, are you on the develop branch of uTensor? Also can you post which convolution2D operator get's generated? Is it in the Sorry for any confusion/roundabout debugging |
When I saw that Conv2D was not compiling even with the same version of uTensor used in utensor-helloworld I switch to the The operators generated are:
so the Conv2D is in |
@matteodonati can you DM me on the utensor slack? I want to set up a virtual debug session, it seems really odd that you are always getting the same output and I think it will help us narrow down the bug faster |
Just sent you a message, thank you. |
Hello everyone,
I'm currently trying to import a 1D CNN from Tensorflow using Mbed. In particular, I have data from six different sensors stored as follow:
input_data[150][6] = { {x1, y1, z1, x2, y2, z2}, {x1, y1, z1, x2, y2, z2}, {x1, y1, z1, x2, y2, z2}, ... }
so basically, in each batch, I have 150 timesteps, and in each timestep I have six values (channels).
In my C++ code I created a new input Tensor as follow:
Tensor input = new RomTensor({1, 150, 6}, flt, input_data);
The problem is, when I try to compile the application I get the following errors:
So the problem should be here:
Is the shape of
input_data
correct? How can I solve the issue?Thank you.
The text was updated successfully, but these errors were encountered: