element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
At The Core Design Challenge
  • Challenges & Projects
  • Design Challenges
  • At The Core Design Challenge
  • More
  • Cancel
At The Core Design Challenge
Blog Tennis Picker@The Core#4 The ML configuration and Obeject Detection
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join At The Core Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 18 Apr 2023 3:03 AM Date Created
  • Views 518 views
  • Likes 6 likes
  • Comments 1 comment
Related
Recommended

Tennis Picker@The Core#4 The ML configuration and Obeject Detection

fyaocn
fyaocn
18 Apr 2023

#4 The ML configuration and Obeject Detection

Table of Contents

  • 1 Machine Learning in PSoC 62Sx
  • 2 Object Detection
  • 3 Migrating ML magicwand Project
  • 4 Machine Learning Configurator
  • 5 ML project in General
  • 6 TFLM or IFX and memory challenges

1 Machine Learning in PSoC 62Sx

Infineon provide ModusToolbox as a set of tools to develop applications for Infineon devices, including GUIs, command-line programs, software libraries, and third-party software.  Machine learning solution is part of the ModusToolbox ecosystem that helps to  build, evaluate and benchmark pre-trained ML models. The ML libraries easily and efficiently run the inference on an Infineon MCU.

ML configurator is one GUI tool to import pre-trained machine learning models and generate an embedded model (as C-code or binary file). This generated model can be used with the ML library along with your application code for a target device. ML configurator also helps to fit the pre-trained model of choice and evaluate its performance.

Machine learning can run on any PSoC 6 MCU. The recommended hardware/kit platform is the CY8CKIT-062S2-43012. This CY8CKIT-062S2 Kits can be targeted as well, but the  memory size and performance requirements to run the inference engine are bottlenet when it comes to designing the NN, as migration ML magic wand project below.

2 Object Detection

Object detectors can identify which of a known set of objects might be present and provide information about their positions within the given image or a video stream. Refer to  Tensorflow object_detector page for more details. An object detector is trained to detect the presence and location of multiple classes of objects.

image

There have been dozens of valid object detection model such as VGG, mobile Net, and yolo. But all of them are oversizing for embedded MCUs. That is why there are little resources on such applications.

Tensorflow provide SSD_mobileNet tflite as compressed format, but is still too large for PSoC 62S4 with 256 KB Flash and 128 KB SRAM.

The idea of moving the rover accoring to the size and location of detected Box is the core of this Tennis Picker project. And That is obviously challengous.

3 Migrating ML magicwand Project

Before the SSD model project, go to sample magic wand project is fast-tracking. This is normal ML example in many arduino boards library. In Modus Toolbox IDE, it is called gesture classification. Detect moving gesture with 6-D gyro-sensors.

First, import the PSoC 62S2-kit example project and build it,

image

The SRAM memory is 1M and flash of 256k.

Then, start library manager

image

to add bsp

image

select the PSoC 62S4 as active BSP the update the library,

image

Build the project, it passes, only because the Flash can hold the codes, but not fit for SRAM with 115968 Byte. It is sure to crash where downloading into the MCU.

image

But that is not the point for now. Modus toolbox provide ML configurator to do modification and validation.

4 Machine Learning Configurator

Laounch the ML configurator from Modus Toolbox directly, Then setting parameters of NN model, browse and import ML model in h5 format

image

Start validation on desktop, with sample random numbers. This is QEMU behind this simulation, it works fine.

image

ML configurator can evaluate memory size.

image

and optimize size of memory as reference

image

It can download into board for validation as well, the board feed true value by means of serial port, the ML engine runs in desktop computer

image

It fails since there is no such data get from board, BIM60 is not comes with PSoC 62S4, only valid in PSoC 62S2 Kits.

image

Anyway, the ML configurator is valid all-in-one tool for ML project.

5 ML project in General

To make it simple, here is ML project development flow,

image

The hardware of CY8CKIT-062S4 PSoC 62S4 pioneer kit support the software structure,

image

ML Configurator has two options for inference engine:
• TFLM inference engine
• Infineon inference engine

It is recommand to work with IFX, with reference to APIs of MTB Machine Learning Inference Engine Library. For TFLM , refer to TFLM  APIs in github.

Here is core ML engine in for-Loop of Gesture Task ,

for(;;)
    {
        /* Wait until there is 128 samples from the accelerometer and the
         * gyroscope in the circular buffer */
        cy_rtos_waitbits_event(&sensor_event, &sensor_event_bits, true, true, CY_RTOS_NEVER_TIMEOUT);

        uint16_t cur = 0;

        /* Cast the data from an int16 to a float for pre-processing */
        int16_t temp_buffer[SENSOR_BATCH_SIZE][SENSOR_NUM_AXIS];
        cy_fifo_read(&sensor_fifo, &temp_buffer, SENSOR_BATCH_SIZE * SENSOR_DATA_WIDTH);
        cast_int16_to_float(&temp_buffer[0][0], &data_feed[0][0], SENSOR_BATCH_SIZE*SENSOR_NUM_AXIS);

        /* Third order butter-worth filter */
        while(cur < SENSOR_NUM_AXIS)
        {
            /* Initialize and run the filter */
            iir_filter_init(&butter_lp_fil, coeff_b, coeff_a, n_order);
            iir_filter(&butter_lp_fil, &data_feed[0][0], SENSOR_BATCH_SIZE, cur, SENSOR_NUM_AXIS);
            cur++;
        }

        /* A min max normalization to get all data between -1 and 1 */
        normalization_min_max(&data_feed[0][0], SENSOR_BATCH_SIZE, SENSOR_NUM_AXIS, MIN_DATA_SAMPLE, MAX_DATA_SAMPLE);

        /* Get the model output size */
        int model_output_size = mtb_ml_model_get_output_size(magic_wand_obj);

        /* Convert to int16 based on the q format */
        MTB_ML_DATA_T data_feed_int[SENSOR_BATCH_SIZE][SENSOR_NUM_AXIS];
        mtb_ml_utils_convert_flt_to_int16(&data_feed[0][0], &data_feed_int[0][0], SENSOR_BATCH_SIZE*SENSOR_NUM_AXIS, QFORMAT_VALUE);

        /* Feed the Model */
        input_reference = (MTB_ML_DATA_T *) data_feed_int;
        result_buffer = (MTB_ML_DATA_T *) malloc(model_output_size * sizeof(MTB_ML_DATA_T));
        mtb_ml_model_run(magic_wand_obj, input_reference, result_buffer);
        control(result_buffer, model_output_size);
    }

All input data be prepared are read for one and only code to ML get feedback,

mtb_ml_model_run(magic_wand_obj, input_reference, result_buffer);

This makes every one access Machine Learning easily, even without  previous experience thanks to toolset provide by Infineon Modus Toolbox.

6 TFLM or IFX and memory challenges

In all, this CY8CKIT-062S4 PSoC 62S4 pioneer kit is fit for Machine Learning project, but challengous in memory size. Another part consumes memory most is the camera library, that make the situation complex and hard to solve.

But there are still wayout. I shall figure it out on external memory.


#3 Rover Platform                                                                                            #5 Picking Tennis via Dual-Core IPC
  • Sign in to reply
  • navadeepganeshu
    navadeepganeshu over 2 years ago

    Great blog showcasing ML features. Interesting and this is something that I never explored and thought a PSoC could support!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube