Edge Impulse logo
Blog Post

Save Yourself a Trip: Fall Detection Using a Transformer Model

Artificial Intelligence, TinyML, Machine LearningThis wearable device detects falls using a Transformer-based model on the Arduino GIGA R1 WiFi.

Nick Bild

April 26, 2023

    Falls are a major health concern for older adults, as they can result in serious injuries, reduced mobility, and a decreased quality of life. Despite the many existing efforts designed to prevent falls, the magnitude of the problem is huge, and continues to place a significant burden on both fall victims and healthcare systems.

    According to the Centers for Disease Control and Prevention (CDC), falls are the leading cause of fatal and nonfatal injuries among adults aged 65 and older. In fact, older adults are treated in emergency departments for fall-related injuries every 11 seconds, and an older adult dies from a fall every 19 minutes in the United States.

    The financial cost of falls is also substantial. The CDC estimates that the total medical costs for fall injuries in older adults exceeded $50 billion in 2015 alone, and this number is projected to increase as the population ages.

    Arduino GIGA R1 WiFi development board and accelerometer modue

    With the problem being so large, and anticipated to only grow larger over time, it is clear that more work is needed to help reduce falls. Engineer Naveen Kumar believes that the key to solving this problem involves detecting a fall the moment that it happens. Many of the more serious consequences of a fall can be averted by a rapid response.

    But to realize this goal, each and every high-risk individual needs to be equipped with a device that can detect falls at any time of day or night. That sounds like a high barrier to clear, but a proof of concept device recently built by Kumar shows that reaching this goal may not be nearly as difficult as it sounds.

    His idea was to use an accelerometer integrated into a belt worn around the waist to collect motion information from the wearer. That motion information would then be fed into a machine learning classifier that was trained to distinguish normal, daily activities from falls. Because of their ability to selectively focus on different parts of sequential input data, and capture context information that is important for understanding the meaning of the sequence, Kumar decided to use a Transformer-based model developed with Edge Impulse Studio for this purpose.

    On the hardware side, the new Arduino GIGA R1 WiFi development board was selected.  With the STM32H747XI dual Cortex-M7/M4 32-bit low power CPU and a megabyte of RAM, this little powerhouse has more than enough horsepower to tackle running a machine learning model that has been highly optimized by Edge Impulse for edge computing platforms. A Seeed Studio Grove three-axis accelerometer was hooked up to the Arduino, then the components were attached to a belt to make it comfortably wearable.

    Examining the uploaded training data

    It would take a lot of time and effort to collect an accelerometer dataset that is representative of what would be seen under real-world conditions as one goes about their daily activities, or falls down. Kumar did not want to take that project on, but fortunately, there are a number of existing datasets, so he did not have to. SisFall, a fall and movement dataset, which happened to be collected using the same ADXL345 accelerometer used in this project, was downloaded.

    A Python script was written to translate the SisFall data into JSON format, after which it was uploaded to an Edge Impulse Studio project using the Edge Impulse CLI. By including the class name in the JSON file names, each sample was automatically assigned a label.  Using the Edge Impulse API, the samples were split up into 4,000 ms segments. Finally, using the Edge Impulse Studio dashboard, the dataset was divided up into training and testing portions.

    As a next step, Kumar created the impulse, which defines how sensor data is processed from the moment it is produced, all the way through to the prediction. The preprocessing blocks were very simple — they defined how the data should be sliced up into windows, then specified that all of the parameters from the accelerometer measurements should be passed forward, unchanged, to the machine learning algorithm. That algorithm was defined by a classification block.

    Data Explorer can reveal problems with the uploaded data

    A very particular type of model architecture was desired for this project, so Kumar switched to expert mode, which gave him total control over the definition of the model design. Here, each layer of the classifier was designed, including the Transformer elements that are expected to provide great results for this application.

    Before going any further, the Data Explorer tool was used to get a peek at the training data. This, by and large, showed good separation between the daily activity and fall classes, which indicates that the model should be able to discover the relevant features that distinguish them. With this boost of confidence, the training process was initiated with a button click.

    After a short training period, metrics were presented to help assess how well the model was performing. This showed that the classifier had reached an average accuracy rate of over 96%. This was a great result, but to confirm that it was not the result of model overfitting, the more stringent model test tool was also run. This checks samples that were held out of the training process, and confirmed that the model was working well — it revealed an average classification accuracy rate exceeding 97%.

    Validating the model’s performance

    That is a model ready for real-world use, so Kumar shifted to deploy the model to the Arduino GIGA R1 WiFi board. Arduino hardware is very well supported by Edge Impulse, so it was as simple as selecting the “Arduino library” option from the deployment tab in the Studio, then importing it into Arduino IDE. This library contains the full machine learning analysis pipeline, and also gives a developer the ability to add in their own programming logic.

    In this case, Kumar chose to simply flash an LED when a fall was detected. That serves the purpose of a proof of concept, but he notes that the Arduino board he selected is also Wi-Fi-capable, so the code could easily be modified to wirelessly transmit a notification of the fall to physicians and first responders as well.

    Kumar made his Edge Impulse Studio project public, so if you are in the market for a fall detector, cloning this project will get you most of the way there. If you have other accelerometer-based ideas in mind, read through the detailed project documentation. You will find that the methods used here can be easily adapted to solve a wide range of problems.

    Want to see Edge Impulse in action? Schedule a demo today.


    Are you interested in bringing machine learning intelligence to your devices? We're happy to help.

    Subscribe to our newsletter