Lesson 11, Project five.
Intelligent, mature station with BME 280 specifically for model training and development.
So the model you trained in the previous phase was transformed to a binary, including a model structure
and weights, and it can be now imported into wheel terminal together with the C++ code, which I believe
is somehow familiar to you, right?
Basically, TensorFlow Lite for Microcontrollers offers a model interpreter that is minimal and quick
to achieve low load start up and execution time.
The interpreter employs static, ordering any specialized or less dynamic memory allocator.
The data in the output buffers is fed into the model graph and the results are deposited in the output
buffer.
After the inference is completed and in order to reduce the size of the model and decrease inference
time, we perform two important optimizations.
First is that perform full integer quantization changing model, which inputs and outputs from floating
point thirty two numbers and each one occupying 32 bits of memory to integer eight numbers, each occupying
only eight bits, thus reducing size by a factor of four.
Right now, use micrometer table opera solver and specify operations that we have in neural network
to compile our code only with the operations needed to run the model, as opposed to using all ops resolver,
which includes all operations supported by current TensorFlow Lite for microcontrollers interpreter.
So in preparation, you need to make sure you have libraries for Wi-Fi and LV installed because we will
need them for our expansion tasks.
As we discussed further along now to start the practice, once the model training is finished, it says
here that create an M.D. sketch and then save it.
Then after that, copied the model, you train to the sketch folder and then re-open the sketch right
after that.
Change the variable name of model to something short term, and as this year used to code from real
terminal def, make your weather prediction static that enum, which you can find in the course materials
for testing.
Now, go over the main steps we have in the C++ code, and then we'll also include the headers for Tensor
Library and the file with model flood buffer.
So now notice how different things look.
It's better to use micrometer mid-table opera solver not h after you finish testing because it will
use less memory on your device and it's easier to use than all.
Obsess over that, each for testing, but it's better to use micro, mutable up.
Resolver that each when you're done.
And after that, set up the pointers for the error reporter and the model, the input and output, then
source and interpreter.
It's easy to see that our model has two outputs one for precipitation amount and one for the type of
weather we're having.
We'll also talk about the Tensor Arena, which you can think as a scratch board that wants input output
and intermediate arrays.
The size of the arena will depend on the model you are using and may need to be determined by testing.
Then, in setup function, it does more boring things like setting up error reporters, opera solvers,
interpreters and mapping the model.
It also allocate benzos and checks their shapes after allocating them.
This is when the code might not work at all because some of the model operations are not supported by
the current version of the TensorFlow Micro Library.
Changing the model's architecture or adding the support for the unsupported operation yourself, usually
by porting it from TensorFlow Lite, is actually the best way to get the support for the unsupported
operation.
And now finally, loop function we define as a placeholder for a quantized AI, anti-hate values and
an array with float values, which you can copy paste from the book for comparison of model inference
on device versus in column.
And now on this step, we quantized of float values into the AI into eight in four loop and then placed
them in the input tensor one by one.
So you can see there in the codes.
Then inference is performed by TensorFlow micro interpreter and if no errors are reported, values are
placed in the output.
10 Source check and compare the values for the same data point.
They should be the same for quantized TensorFlow.
Eight model in CoLab notebook and TensorFlow micro model.
Running on your real terminal, meaning there should be no difference in values between quantized TensorFlow
Lite in CoLab Notebook and TensorFlow Micro running on your real terminal when it comes to the same
data point.
Now the next step here is that open to sketch real terminal def micro weather prediction static that
we know from course materials and have a look at its contents.
Parts of the code are broken down into the main sketch.
We have get historical data and UI parts.
The first inference will have to wait for 24 hours because our model needs data from the last 24 hours
to solve this problem.
We get the weather from the last 24 hours from open weather that come and can do the first inference
right after the device starts up.
Then we replace the values in a circular buffer with the temperature, humidity and pressure from BME
to 80 sensor connected to the real thing.
Now I do see Groves suck in a library called LV.
Gale was used to make the UI.
It's a small and useful graphic library, so we'll have to build and upload the code.
Make sure you make changes to your Wi-Fi credentials and location in sketch before you upload it.
OK, connect to the internet.
After you upload, the device will get the data about your location for the last 24 hours and makes
its first guess before getting data from the BME to sorry.
It will wait for an hour if there is no sensor connected.
The program won't start up at all.
Now this is how it works.