Getting started
Welcome to our “Getting Started” section of the Bosch BME AI-Studio. The BME AI-Studio brings together our BME688 Development Kit (equipped with the BME688 gas sensor) and our BSEC Software (BME Library).
This section will give you a short introduction and a hands-on example on how to use the application.
The BME688 Gas Sensor
The BME688 gas sensor is like a digital nose. It can detect gases by measuring their unique electric fingerprint and therefore distinguish different gas compositions.
However, the sensor has to be taught about these different gases first. That means, we have to train the sensor using Machine Learning.
And that’s where the BME AI-Studio comes in: It lets you explore and verify your specific use cases: With the application, you can collect your gas measurements, train Machine Learning algorithms and export a final algorithm to be used with the BSEC Software in your project.
Example: Coffee vs. Normal Air
Let’s take a look at a real world example.
Assume, you want to use the BME688 to detect coffee beans. Or in other words: distinguish the gas composition of coffee from the gas composition of normal air and other smells.
So in order to train an algorithm for that, we first have to record gas measurements of coffee and normal air.
A Few Things To Keep In Mind
Before we start with the measurements, there are three things to keep in mind:
If you have a brand new BME Board, you should stabilize the sensors on the board before taking any measurements. To do so, connect the board to power with a Micro USB cable and let it run for at least 24 hours. This procedure is necessary only once and your board is then ready to take reliable measurements.
Make sure that your BME Board is configured correctly. It is recommended to use the Default configuration for your first round of data recording.
Make sure that an SD card is inserted in the board.
Also make sure that a coin cell battery is inserted in the dedicated slot of your development kit board. This is needed for the real time clock (RTC). If the RTC time should be out of sync, please connect your board to the BME AI-Studio Mobile App to automatically resync to the correct time.
Step 1: Record Normal Air
OK – let’s start the Measurement Session for our Coffee Detection Example.
Let’s record normal air as our first Specimen. We are just going to record the gas composition of the room. Additional smells to make the detection more robust should be added later. But to keep it simple in this example we just stick to normal air for now.
Connect the BME Board to power and place the board on your table. Always be careful not to touch the sensors with your fingers while handling the board.
If everything is Ok and the board is recording data, the red LED will start blinking. Let the board record for about 30 minutes.
Step 2: Record Espresso Coffee
Now, let’s move on to the coffee. For this example, we prepared two types of coffee in order to have a bit of variance in our measurements: Espresso and filter coffee. Let’s measure the espresso coffee first.
Place the espresso coffee in a relatively air-tight container. Press “Button 1” (labeled “S1”) on the board to mark this moment in the data. Place the board in the container together with the coffee, and record the gas composition for 30 minutes.
Step 3: Record Normal Air Again
After that, let’s measure normal air again. Take the board out of the container. This time, press “Button 2” (labeled “S2”) on the board to set another marker in the data.
Place the board again on your table, and record the gas composition for another 30 minutes. Put the container with the coffee far away, so it doesn’t interfere with the recording.
Step 4: Record Filter Coffee
Finally, let’s record the last Specimen: Filter coffee. Same procedure as with the espresso coffee: Place the filter coffee in a second container, press “Button 1” on the board and place it in the container along with the coffee. Again, record the gas composition for 30 minutes.
Once you are finished with your Measurement Session, you can just power off the board by unplugging the USB cable.
Step 5: Import & Label The Data
Now it’s time to open BME AI-Studio on your computer. Create a new project and select a location, where you want to save it on your hard drive. Let’s call the project “Coffee Example”. Then select Import data
. Remove the SD card from the BME Board, connect it to your computer and select the file on the card with the ending .bmerawdata
.
The application now gives you an overview of your recorded data. There’s a plot showing you the data on a timeline. First, give your Measurement Session a name. Let’s call it “Coffee Session”.
Below the plot, there are already four Specimens defined – one that started with powering on the board, and three that started when we pressed the buttons during measurement. On the left, there are input fields to label each Specimen. We measured normal air first, then espresso coffee, then again normal air, and finally filter coffee.
If you forgot to press a button during the measurement, you could define Specimens manually here as well.
Select Import Data
to finish. The data is now copied to the project folder on your hard drive.
Once the import is finished, you can see your four Specimens in your Specimen Collection
. The Specimen Collection is where you can collect and manage all of your recorded data for a specific project. If you select one of the Specimens, you can see all available details about this Specimen on the right hand side.
Step 6: Create New Algorithm and Classes
So now that we have recorded and imported the data into the Specimen Collection, it is finally time to create and train an algorithm.
Switch to My Algorithms
and select New algorithm
. We can give this algorithm a name, let’s call it “Coffee or Not”.
As you remember, in our example use case we wanted to detect when coffee is present. That means, we need to teach our algorithm the difference between two so called “classes”: Coffee and other smells. So let’s create these two classes. Select Add class
and give this class a name. Let’s call it “Coffee”.
Next, we have to select the Specimens from our Specimen Collection that should be part of that class. In our example, that would be the two Specimens “Espresso Coffee” and “Filter Coffee”.
Now, let’s create the second class. We call this one “Normal Air” and select the two “Normal Air” Specimens to be associated with this class.
Step 7: Train And Evaluate The Algorithm
Now, that we have defined our two classes with their respective Specimens, we can train our algorithm. There are additional settings for the algorithm and the training, but for now you can leave these settings at their default values. Just hit Train Neural Net
and BME AI-Studio will start to train the algorithm.
Once the training is finished, you can see the results. The most important value to check is the Accuracy
. The higher the Accuracy the better the algorithm’s performance.
One thing you should be aware of though: The algorithm training results can be too perfect. If you have recorded too little data, it might happen that the algorithm adapts too closely to that specific data – and gives perfect results. However, it won’t be able to predict other data that is slightly different. To make the algorithm more robust, you could record additional coffee blends or other smells, like tea or juices. In short: always make sure to record enough data with a bit of variance.
A second thing to check is the so called Confusion Matrix
, which you will find under Details
. It shows the algorithm’s performance to distinguish our two classes “Coffee” and “Normal Air”.
A part of the Specimen’s data has been reserved just for this performance test. The rows show what the actual classes of these test elements were, while the columns show which classes were predicted by the algorithm. That means, for a good result, the upper left quadrant and the lower right quadrant should be dark blue and have a high number – indicating how often the algorithm made the right prediction for both classes. At the same time, the upper right and lower left quadrants should be light blue and have a low number, since these numbers indicate how often the algorithm made the wrong prediction. The upper right quadrant tells you how often the algorithm falsely predicted “Normal Air”, when in fact it was “Coffee”. And the lower left quadrant tells you how often the algorithm predicted “Coffee”, when it actually was “Normal Air”.
In our example, the results look pretty good. More than 90% accuracy and very few false predictions in the Confusion Matrix. That’s a good result for a first training.
Step 8: Export The Algorithm
As a last step, if you are happy with the result, you can export the algorithm as a BSEC Configuration File
for the BSEC Software. This config file can be used together with the BSEC Software in your project.
Conclusion
If you have any questions or if you want to get further information, for example on how to use the BSEC Software, please write us an email or check out the Bosch Sensortec Community.
Happy training!