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
Eye On Intelligence Challenge
  • Challenges & Projects
  • Design Challenges
  • Eye On Intelligence Challenge
  • More
  • Cancel
Eye On Intelligence Challenge
Blog Smarter Runner - Biomechanics Assistant
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Eye On Intelligence Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 19 Nov 2024 4:45 AM Date Created
  • Views 738 views
  • Likes 5 likes
  • Comments 7 comments
  • tensorflow
  • video processing
  • python
  • arty z7
  • opencv
  • Amazon Q
  • Eye on Intelligence Challenge
  • pynq
  • amd
  • onnx
  • linux
Related
Recommended

Smarter Runner - Biomechanics Assistant

vlasov01
vlasov01
19 Nov 2024

Project Overview

I like running, but I also get injuries from time to time. I attribute them to my bad running form. Unfortunately, I'm not alone. Many runners have the same challenge. 

Key Decisions

1. Use CPU instead of FPGA for video processing. Reasoning: I didn't have HDMI cameras or a USB to HDMI converter. Moving video stream from USB or network to FPGA requires CPU resources and is not a standard pattern for FPGA.

2. Use IP cameras instead of USB cameras, Reasong: Arty Z7 has only one USB port and my project requires feed from two cameras.

Arty Z7 - PINQ - Setup and Update

Python is the most productive language for me for AI applications. PYNQ provides a Python runtime environment for several boards, including Arty Z7.
It requires to flash SD card to enable it on Arty Z7.
After I flashed PYNQ, I created a network connection by connecting its ethernet port to a network switch.
Then I played with Jupiter notebooks provided as part of the PYNQ distribution. I was very interested in a USB Web Cam example. But it didn't work. The issue was with security permission for my USB webcam on Ubuntu.

sudo usermod -a -G video $LOGNAME

sudo vi /etc/udev/rules.d/10-webcam.rules
SUBSYSTEM=="video0", GROUP="video", MODE="0660"

And reboot

After it was fixed and the board was restarted the example started working well.

As I've selected PYNQ as my runtime environment it needs to be secured. I've started by trying to update it. But it was not able to connect to the internet as my switch was only connecting my PC and the board. So I've configured a network sharing of my PC wireless LAN connection. Now the board has access to the Internet.

But after the update, I've noticed some differences. It becomes much slower. The slowdown was caused by two processes. I start investigating it. One issue was related to a high CPU usage and another one was related to a process, which was filling up logs.

Model Selection

I've selected the movenet_singlepose_lightning model as it is quite small and can run without GPUs but still has quite good performance and a lot of documentation and samples.
There are several other models. They are quite good, but some of them are much bigger or have less documentation. The model accepts frames with dimensions 192 by 192.

TensorFlow 

Examples of the movenet_singlepose_lightning model were based on the TensorFlow framework. It was developed by Google. While I was able to deploy TensorFlow Lite runtime on Arty Z7 I was not very successful in running it. I was always getting Core Dump errors. So I start looking for alternatives.

ONNX

ONNX is another ML framework. It is maintained by Microsoft and its partners. I was able to build it for Arty Z7. It was quite a slow and error-prone process. Fortunately, there was a movenet_singlepose_lightning model converted into ONNX format. It saved me some time required for model conversion. I start testing the model. It was able to process images and find key points and their confidence scores. But it took ~ 1 second per frame.

UPDATE (19/11/2024):

I was able to build onnxruntime with xnnpack and its Python wrapper directly on Arty Z7. It requires a fast SD card, a lot of swap space (~32GB), and a lot of time (a few days). 

The first step is to remove the following package as onnxruntime is using another version.

sudo apt remove libeigen3-dev

After cloning the project you can try to build it. Here is my build command:
./build.sh --config Release --parallel --skip_submodule_sync --skip_tests --use_xnnpack --build_wheel --cmake_extra_defines CMAKE_CXX_FLAGS="-Wno-dev -Wall -Wextra -O3 -g3 -mfloat-abi=hard -mfpu=neon-vfpv3 -mcpu=cortex-a9 -mfloat-abi=hard" CMAKE_C_FLAGS="-Wno-dev -Wall -Wextra -O3 -g3 -mfloat-abi=hard -mfpu=neon-vfpv3 -mcpu=cortex-a9 -mfloat-abi=hard"

Video Streaming with OpenCV and FFMPEG

It is important to capture runner forms from side and rear perspectives. It requires two cameras. I've decided to use a pair of IP cameras I already had. I've connected to them from OpenCV and developed a prototype on my PC. I thought that the code would work on Arty Z7 as well. However, the video streaming of RTSP H264 was not reliable at all on SBC. So I decided to use FFMPEG to stream from cameras and pipe RAW frames directly. I also used it for decoding H264, rotating, resizing, and cropping images.  It worked with some challenges as after ~180 frames FFMPEG needs to be restarted. The restart takes ~2-3 seconds. FFMPEG has a lot of parameters and I hope I'll find the right set of them so it can receive streams without restarts.

image

Video Output

Not all video formats are supported by modern browsers. Encoding into some of them is very resource-intensive. After some research and experimentation I choose 

avc1. It is compatible with browsers and very fast.

Data capture

I've decided to use the SQLite 3 database to record keypoints data for each frame produced by the model. It will allow to use it to run different biomechanics assessment algorithms and relate them to the videos.

Demo

I've done a short run and created a short video to capture my running forms and related metrics.

image

One video was captured from a side view and another from the rear.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

To-Do List

I still have a long list of remaining tasks. Here are some of them:

Calculate key runners' metrics based on keypoints data set.

Complete integration with Tornado HTTP Server provided on PYNQ so it can show runner analytics on a smart TV during the run.

Create a stand for cameras.

Publish the project on Github.

Conclusion

Despite numerous challenges with software components, I was quite happy to get to this point. The project proved that even on the arml7v architecture, it is possible to run complex computer vision models in near real-time. While I haven't been able to complete all my objectives I've built a solid foundation for further improvements.

I would like to thank the AMD team and Element 14 for selecting my project proposal for this design challenge. The challenge pushed my curiosity and allowed me to explore new areas of sports biomechanics, computer vision, the ONNX framework, and the ML ecosystem. I would also like to thank all members of the community who have worked on this challenge or shared their feedback. And a special thanks to Amazon Q which helped me with some Python coding.

  • Sign in to reply
  • vlasov01
    vlasov01 9 months ago in reply to rsc

    I'll say it was probably the most challenging project I've participated in on Element 14. There have been a lot of advancements in computer vision in recent years and at the same time a lot of technical constraints too. I wish PYNQ for Arty Z7 had a working Tensorflow or onnxruntime preinstalled (or available) on its image.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 9 months ago in reply to DAB

    Thank you, DAB 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vlasov01
    vlasov01 9 months ago in reply to javagoza

    Thank you javagoza  for your feedback.

    I've updated ONNX section with a build instruction. You can also look at a related issue I've commented  https://github.com/microsoft/onnxruntime/issues/22463 .

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB 9 months ago

    Nice finish on your project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rsc
    rsc 9 months ago

    There are some very interesting projects in this challenge, I'm amazed at all the different ideas and ways of attacking the issues and finding solutions.  

    • 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