Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

A

MAJOR PROJECT REPORT


ON
ARTIFICIAL INTELLIGENCE FITNESS TRAINER
Submitted in partial fulfilment of the requirements for award of the degree of

BACHELOR OF TECHNOLOGY
In
CSE (Artificial Intelligence & Machine Learning)

BY
XXXXXXXXXXX 20BH1AXXX

XXXXXXXXXXX 20BH1AXXX

XXXXXXXXXXX 20BH1AXXX

XXXXXXXXXXX 20BH1AXXX

Under the guidance of

Mr. M. APPARAO, M.Tech, (Ph.D)


Assistant Professor

EPARTMENT OF CSE (Artificial Intelligence & Machine Learning)

St. Mary’s Engineering College


(Approved by AICTE, NEW DELHI. & Affiliated to JNTU-HYDERABAD, Accredited by NAAC)

Deshmukhi (V), Pochampally (M), Yadadri Bhuvanagiri (D), Telangana -


50824 [2023-24]
CERTIFICATE

This is to certify that project report entitled “ARTIFICIAL INTELLIGENCE FITNESS


TRAINER” is bonafide work carried out in the Ⅳ/Ⅱ semester by XXXXXXXXXX
(20BH1AXXX), XXXXXXXXXX (20BH1AXXX), XXXXXXXXXX (20BH1AXXX),
XXXXXXXXXX (20BH1AXXX), in partial fulfilment award of Bachelor of Technology in
CSE (Artificial Intelligence & Machine Learning) from St. Mary’s Engineering college
during the academic year 2020-24.

INTERNAL GUIDE HEAD OF THE DEPARTMENT

Mr. M. APPARAO, M.Tech, (Ph.D) Dr. K Suresh Kumar , M.Tech, Ph.D

Dept. of CSE (AI&ML) Dept. of CSE (AI&ML)

EXTERNAL EXAMINER
ACKNOWLEDGEMENT

The satisfaction that accompanies the successful completion of this project would be
incomplete without the mention of the people who made it possible. We consider it as a
privilege to express our gratitude and respect to all those who guided us in the completion of
the project.
We are thankful to our internal guide Mr. M. APPARAO, MTech, (Ph.D) in
Department of CSE (Artificial Intelligence & Machine Learning), St. Mary’s
Engineering College for having been of a source encouragement and for insisting vigour to
do this project work
We are obliged to Dr. K Suresh Kumar , Head of the Department of CSE
(Artificial Intelligence & Machine Learning), St. Mary’s Engineering College for
his guidance and suggestion throughout project work.
We take this opportunity to express a deep sense of gratitude to Dr. T.N. Srinivas Rao,
Principal of St. Mary’s Engineering College for allowing us to do this project and for this
affectionate encouragement in presenting this project work.
We convey our sincere thanks to Sri Rev. K.V.K RAO, Chairman of St. Mary’s
Engineering College for giving us learning environment to grow out self personally as well
as professionally.
We would like to express our thanks to all staff members who have helped us directly and
indirectly in accomplishing this project work. We also extended our sincere thanks to our
parents and friends for their moral support throughout the project work. Above all we thank
god almighty for his manifold mercies in carrying out this project work successfully.

XXXXXXXXXX -20BH1AXXXX

XXXXXXXXXX -20BH1AXXXX

XXXXXXXXXX -20BH1AXXXX

XXXXXXXXXX -20BH1AXXXX
DECLARATION

This is to certify that the work report in thesis titled,”ARTIFICIAL


INTELLIGENCE FITNESS TRAINER”, submitted to the Department of CSE
(Artificial Intelligence & Machine Learning), St. Mary’s Engineering College in
fulfilment of degree for the award of Bachelor of Technology, is a bonafide work done by us.
No part of the thesis is copied from books, journals or internet and wherever the portion is
taken, the same has been duly referred in the text. The reported results are based on the
project work entirely done by us and not copied from any other sources. Also we declare that
the matter embedded in this thesis has not been submitted by us in full or partially there for
the award of any degree of any other institution or university previously.

XXXXXXXXXX -20BH1AXXXX

XXXXXXXXXX -20BH1AXXXX

XXXXXXXXXX -20BH1AXXXX

XXXXXXXXXX -20BH1AXXXX
CONTENTS
CHAPTER NAME PAGE No

1. INTRODUCTION 1-2
1.1 INTRODUCTION TO PROJECT 1
1.2 FEATURES 2

2. LITERATURE SURVEY 3-6

2.1 ABOUT THE DOMAIN 3


2.2 LITERATURE SURVEY 3

3. SYSTEM ANALYSIS 7-10

3.1 INTRODUCTION 7
3.2 EXISTING SYSTEM &ITS DISADVANTAGES 7
3.3 PROPOSED SYSTEM &ITS ADVANTAGES 8
3.4 INPUT DESIGN 9
3.5 OUTPUT DESIGN 10

4. SYSTEM STUDY 11-12

4.1 FEASIBILITY STUDY 11


4.1.1 ECONOMICAL FEASIBILITY 11
4.1.2 TECHNICAL FEASIBILITY 12
4.1.3 SOCIAL FEASIBILITY 12

5. SYSTEM REQUIREMENTS 13

5.1 HARDWARE REQUIREMENTS 13


5.2 SOFTWARE REQUIREMENTS 13

6. MODULE DESCRIPTION 14-15

7. SOFTWARE ENVIRONMENT 16-42

7.1 ANDROID 16
7.2 DOWNLOAD THE ANDROID SDK 24
7.3 ECLIPSE 33

8. SYSTEM DESIGN 43-44

8.1 DATA FLOW DIAGRAM 43


9. UML DIAGRAMS 45-49

9.1 INTRODUCTION 45
9.2 CLASS DIAGRAM 46
9.3 SEQUENCE DIAGRAM 47
9.4 USECASE DIAGRAM 48
9.5ACTIVITY DIAGRAM 49

10. SOURCE CODE 50-65

11.SYSTEM TESTING 66-69

11.1 INTRODUCTION 66
11.2 TYPES OF TESTINGS 66
11.2.1 UNIT TESTING 66
11.2.2 INTEGRATION TESTING 67
11.2.3 FUNCTIONAL TESTING 67
11.2.4 SYSTEM TESTING 68
11.2.5 WHITE BOX TESTING 68
11.2.6 BLACK BOX TESTING 68
11.2.7 ACCEPTANCE TESTING 69

12. OUTPUT SCREENS 70-78

13. CONCLUSION 79

14. BIBLIOGRAPHY 80-81

LIST OF FIGURES

FIGURE
S.NO FIGURE NAME
NO
1 7.1.1 ANDROID ARCHITECTURE
SELECT ANDROID AND MAINTAIN THE INSTALLATION PATH
2 7.2.1
OF THE ANDROID SDK.
3 7.2.2 SELECT ANDROID SDK AND AVD MANAGER
4 7.2.3 SELECT ANDROID SDK AND AVD MANAGER
5 7.2.4 INSTALLING THE ADT PLUGIN FOR ECLIPSE
6 7.2.5 PACKAGES AVAILABLE FOR DOWNLOAD
7 7.2.6 CHOOSE PACKAGES TO INSTALL
8 7.2.7 INSTALLING ARCHIVES
9 7..31 SOURCE CODE
10 7.3.2 SELECT NEW VIRTUAL DEVICE
11 7.3.3 CREATE NEW ANDROID VIRTUAL DEVICE
12 7.3.4 TEST DEVICE
13 8.1.1 DATA FLOW DIAGRAM
14 9.2 CLASS DIAGRAM
15 9.3 SEQUENCE DIAGRAM
16 9.4 SEQUENCE DIAGRAM
17 9.5 ACTIVITY DIAGRAM

LIST OF PLATES

S.NO PLATE No. PLATE NAME


1 12.1 Home Page
2 12.2 User Registration Page
3 12.3 Admin Login
4 12.4 User Activation
5 12.5
6 12.6
7 12.7
8 12.8
9 12.9
10 12.10
ABSTRACT
Inactivity is one of the main causes of obesity which has affected many people
worldwide. Studies show that fitness is an important goal for a healthy lifestyle and is been
used as a measurement for health-related quality of life. A fitness trainer can motivate and
teach users to do exercise daily and stay fit and healthy.
However, to use a fitness trainer might involve a huge cost and sometimes is not
suitable for a certain setting. Exercises are very beneficial for personal health but they can
also be ineffective and truly dangerous if performed in an incorrect method by the user.
There are lot of mistakes made during a workout when user workout alone without
supervision like wrong form which could result fatal for user as they can pull a hamstring or
even fall due to it. In our project, we introduce AI Trainer, an application that detects the
user’s exercise pose and provides personalized, detailed recommendations on how the user
can improve their form. Pose Trainer uses the state of the art in pose estimation module
known as “BlazePose” tool from “MediaPipe” to detect a user’s pose, then evaluates the
pose of an exercise to provide useful feedback.We record a dataset of over 1000 keypoints
coordinate of parts of body in correct and incorrect form, based on personal training
guidelines, we build a machine learning algorithm for evaluation.
CHAPTER 1

INTRODUCTION

1.1 Introduction

In the domain of Artificial Intelligence (AI) based fitness coaching, weightlifting is a flow
of body movement pack in an organized exercise to force the body muscles to contract under
tension by using weights such as barbells, dumbbells or even body weights in order to trigger
growth, strength, endurance and power. This exercise can be helpful to personal health. However,
it can also be potentially dangerous and inefficient if the exercise is performed in wrong posture
by the trainees. Performing wrong posture is a very common issue for every gymnast, either
beginner or even professional. This is because it is a big challenge for trainees to perform a series
of complex movements in weightlifting exercise. Posture issues can manifest into many different
conditions that can put trainee health in danger, such as neck pain, back pain, shoulder pain or
knee pain. Correct posture is able to minimize the strain on the human body by maintaining the
balance between muscles and skeleton. This balanced musculoskeletal state is very important
because it prevents further damage or any progressive deformation in weightlifting training and
protects the supporting structures in the body. Therefore, performing correct posture is a very
crucial aspect for proper arrangement of supporting structures, maintaining balance of the body
and effective functioning of the body.

1.2 Features

There are many fitness apps available in market which allows user to keep track of

their health and provide a workout plan to user to achieve their personal fitness goal.

These app have many functions that provide user with only data to user it does not actually
provide a space where user can do their work out without going to gym or having a personal
trainer.
These apps do not overview whether the user is actually doing the exercise and if they

are doing correctly.

Recently the number of people exercising at home has increased especially required
due to the COVID19 pandemic. Therefore, the need for no contact exercise instructions is in
great demand since physical access to the gym is limited or discouraged. To meet this demand,
many online exercise instruction videos are available. However, the systems are both passive
1
and have no real time feedback to aid the user. In this work, we propose an AI based fitness
monitoring system (AI Fitness Coach) that can offer real time guidance during exercise. The
AI Fitness Coach consists of a pose recognition unit, a fitness movement analysis unit, and a
feedback unit. The user captures their pose by a fixed camera. The pose recognition unit
processes the captured image and outputs the recognition result to the fitness movement
analysis unit. After the results are processed by the fitness movement analysis unit, advice is
output from the device through video or voice. On comparison to existing methods, the
proposed method results are at par and encouraging.

Figure 1.2 : Features present in these days

1.3 PROPOSED SYSTEM

There are many fitness apps available in market which allows user to keep track of
their health and provide a workout plan to user to achieve their personal fitness goal. These
app have many functions that provide user with system monitor also provide a only data to
user does not work out without going to gym or having a personal trainer. These apps do not
overview whether the user is actually doing the exercise and if they are doing correctly. To
overcome the above disadvantage of all existed system we introduce our project AI Fitness
trainer. This project is can defined as AI which detects our human body during our workout
and gives critical feedback on our exercise form and does rep count so user can put all their
focus and energy in the doing our workout rather than keeping the count of our exercise. The
system overcome the important disadvantage of not being able to workout at home and at any
time without guidance.
2
The system provides us the opportunity to work out anywhere, anytime with guidance so
we can do effective workout. System uses computer vision technology to execute the
functions of our system. The system uses state-of-the-art pose detection tool known as “Blaze
Pose” from “Media Pipe” to detect the form of the user’s body during the workout. OpenCV
is used to mark an exoskeleton on the user body and display reps count on the screen. System
uses different videos and photos of specific exercise to create 1000 of data of landmarks key
points and save as csv file use that dataset to train the ML model of that specific exercise
using machine learning classification algorithm named random forest classifier.

Figure 1.3: Fitness trainer using media pipe

3
CHAPTER 2

LITERATURE SURVEY
2.1 Chapter Overview

After discovering some introductory papers about the human posture detection, there
are few approaches to detect the human posture in weightlifting and some of them are able to
evaluate and make correction for correct posture.

2.2 Pose Trainer

Correcting Exercise Posture Using Pose Estimation

An approach which named Pose Trainer has been introduced by Chen et al. (2018) for
detecting and correcting human posture by using pose estimation. This approach consists of
three parts that constructed by six components. The first part has only one component, Video
Recording and it can only be done by user. The next part is built from Pose Estimation, Key
point Normalization and Exercise Detection. A state-of-the-art pose estimation deep neural
network, Open Pose from OpenCV is used within Pose Trainer for inference. The third part
involves detecting the quality of user’s predicted pose for specific exercise, which are Posture
evaluation.
In the first component, the video must be recorded from a particular perspective such as
facing front the camera or facing side to the camera that allows the exercise to be seen
clearly. Moreover, Pose Trainer does not require distance between body and camera or type
of camera. However, Pose Trainer does require user to crop and edit the exercise video by
themselves, which explaining why segmentation of replication in one exercise does not exist
in this application.
For the next component, deep Convolutional Neural Network (CNN) to label Red
Green Blue images. Open Pose, a pre-trained model is chosen for pose detection after
comparing multiple state-of-the-art pose estimators. The output of open Pose contained
coordinate of 18 key point locations and their respective confidence levels. The predicted key
points include nose, neck, shoulder, elbows, wrists, hips, knees, and ankles.
There are two purposes in key point Normalization step.First, a parser is wrote to use
the raw key point output from open Pose.List of key points are read while 2- coordination and
confidence level are segmented into joint key point object. Obscure key point that has zero
confidence level is eliminated. A Pose object which is a full skeletal estimation of a person is

4
constructed by composing each joint key point in every video frame. Then, a Pose Sequence
is composed to chain all Pose objects from each video frame. Secondly, in order to account
distance between body and camera, different body length measurements and other potential
problem, the pose is normalised based on the torso’s length in pixels. The torso length is
calculated by average distance from neck joint to right and left hip joints.
The fourth component is Perspective Detection. In this step, the ambiguity in camera
perspective is resolved. For instance, the bicep curl exercise can be recorded from the side of
camera and could be performed by one or both arms.
For second last component Evaluation Exercise can be achieved by two approaches,
geometric algorithm, and machine learning algorithm. First, geometric heuristics are designed
from key points of interest and personal training guidelines, in order to evaluate the body
vector. Secondly, a more data-driven which is machine learning approach is introduced to
evaluate the exercise posture. Since the recorded video can be any arbitrary length, this
caused different key point vector length such as exercise speed and this is a big challenge for
many machine learning algorithms.

Therefore, Dynamic Time Warping (DTW) with K-Nearest Neighbour (KNN) classifier is
chosen and it is a metric used to measure non-linear similarity between two time series. In
DTW, key point in second sequence is dynamically identified that corresponded to given key
point in first sequence. A distance matrix that consists Euclidean distance from different key
points in two sequences is measured by iterating all points using dynamic programming.
KNN classifier can predict correct or incorrect posture based from DTW distances.
There are various advantages and disadvantages found in this paper. One of the
advantages is user of Pose Trainer only needs to download open Pose and install Anaconda to
make it workable, by choosing open Pose. Unlike TensorFlow or Caffe, which require
complex user installations such as CUDA and CUDNN GPU libraries. Another advantage is
Pose Trainer can track multiple exercises instead of one with high accuracy, which make it
has high commercial value than the other similar apps.
For the disadvantages, Pose Trainer does not design as application, which means it is not
functional on phone. In order to solve this, they should export Pose Trainer to smartphones,
building an application that allows users to record video and get feedback at any place, any time.
The next disadvantage is Pose Trainer only able to provide posture feedback with vocabulary
format. This might be confusing to user because user may interpret the feedback with different
meaning or does not even understanding the meaning of feedback.

5
CHAPTER 3
BLOCK DIAGRAM, HARDWARE & SOFTWARE
DESCRIPTION

3.1 BLOCK DIAGRAM


The below figure represents the block diagram of ANN algorithm to identify fake profiles in
this project. We have taken application such as twitter of social media. A training set is a
portion of a data set used to fit (train) a model for prediction or classification of values that
are known in the training set, but unknown in other (future) data.

Figure 3.1: Block diagram of AI Fitness trainer

3.2 SOFTWARE DESCRIPTION

• Operating system - Windows 9/10/11


• Programming language - Python

• Software required
• Anaconda Libraries:

• Media pipe

6
• Open CV

• NumPy
• Tkinter

3.2.1 Anaconda IDE


Anaconda is an open-source distribution of the Python and R programming languages
for data science that aims to simplify package management and deployment. Package
versions in Anaconda are managed by the package management system, conda, which
analyzes the current environment before executing an installation to avoid disrupting other
frameworks and packages.

The Anaconda distribution comes with over 250 packages automatically installed.
Over 7500 additional open-source packages can be installed from PyPI as well as the condo
package and virtual environment manager. It also includes a GUI (graphical user interface),
Anaconda Navigator, as a graphical alternative to the command line interface. Anaconda
Navigator is included in the Anaconda distribution and allows users to launch applications
and manage conda packages, environments and channels without using command-line
commands. Navigator can search for packages, install them in an environment, run the
packages and update them.

The big difference between conda and the pip package manager is in how package
dependencies are managed, which is a significant challenge for Python data science. When
pip installs a package, it automatically installs any dependent Python packages without
checking if these conflict with previously installed packages. It will install a package and any
of its dependencies regardless of the state of the existing installation. Because of this, a user
with a working installation of, for example Tensor flow, can find that it stops working after
using pip to install a different package that requires a different version of the dependent
NumPy library than the one used by TensorFlow. In some cases, the package may appear to
work but produce different results in execution. In contrast, conda analyzes the current
environment including everything currently installed, and together with any version
limitations specified (e.g., the user may wish to have TensorFlow version 2.0 or higher),
works out how to install a compatible set of dependencies, and shows a warning if this cannot
be done.

Open-source packages can be individually installed from the Anaconda repository,

7
Anaconda Cloud (anaconda.org), or the user’s own private repository or mirror, using the
conda

8
install command. Anaconda Inc. compiles and builds the packages available in the Anaconda
repository itself, and provides binaries for Windows 32/64-bit, Linux 64-bit and MacOS 64-
bit. Anything available on PyPI may be installed into a conda environment using pip, and
conda will keep track of what it has installed itself and what pip has installed.

Figure 3.2.1: Anaconda Navigator

3.2.2 Media pipe


Media Pipe is an open-source framework for building pipelines to perform computer
vision inference over arbitrary sensory data such as video or audio. Using media Pipe, such a
perception pipeline can be built as a graph of modular components. In computer vision
pipelines, those components include model inference, media processing algorithms, data
transformations, etc. Sensory data such as video streams enter the graph, and perceived
descriptions such as object-localization or face-keypoint streams exit the graph. The
MediaPipe framework is mainly used for rapid prototyping of perception pipelines with AI
models for inferencing and other reusable components. It also facilitates the deployment of
computer vision applications into demos and applications on different hardware platforms.

Typically, image or video input data is fetched as separate streams and analysed using
neural networks such as TensorFlow, PyTorch, CNTK, or MX Net. Such models process data
in a simple and deterministic method: one input generates one output, which allows very
efficient processing execution. media Pipe, on the other hand, operates at much higher-level
semantics and allows more complex and dynamic behaviour. For example, one input can
generate zero, one, or multiple outputs, which cannot be modelled with neural networks.
Video processing and AI perception require streaming processing compared to batching
methods.

9
The main components of Media Pipe:

Packet: The basic data flow unit is called a “packet.” It consists of a numeric timestamp and
a shared pointer to an immutable payload.

Graph: Processing takes place inside a graph which defines the flow paths of packets
between nodes. A graph can have any number of input and outputs, and branch or merge data.

Nodes: Nodes are where the bulk of the graph’s work takes place. They are also called
“calculators” (for historical reasons) and produce or consume packets. Each node’s interface
defines a number of in- and output ports.

Streams: A stream is a connection between two nodes that carries a sequence of packets with
increasing timestamps.

Figure 3.2.2: Media pipe application

3.2.3 Open CV

OpenCV (Open-Source Computer Vision Library) is an open-source computer


vision and machine learning software library. OpenCV was built to provide a common
infrastructure for computer vision applications and to accelerate the use of machine
perception in the commercial products. Being an Apache 2 licensed product, OpenCV makes
it easy for businesses to utilize and modify the code.The library has more than 2500
optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art
computer vision and machine learning algorithms. These algorithms can be used to detect and
recognize faces, identify objects, classify human actions in videos, track camera movements,
track moving objects, extract 3D models of objects, produce 3D point clouds from stereo
cameras, stitch images together to produce a high resolution image of an entire scene, find
similar images from an image database, remove red eyes from images taken using flash,
follow eye movements, recognize scenery and establish markers to overlay it with augmented
reality, etc. OpenCV has
10
more than 47 thousand people of user community and estimated number of downloads
exceeding 18 million. The library is used extensively in companies, research groups and by
governmental bodies.

Along with well-established companies like Google, Yahoo, Microsoft, Intel, IBM,
Sony, Honda, Toyota that employ the library, there are many startups such as Applied Minds,
VideoSurf, and Zeitera, that make extensive use of OpenCV. OpenCV’s deployed uses span
the range from stitching streetview images together, detecting intrusions in surveillance video
in Israel, monitoring mine equipment in China, helping robots navigate and pick up objects at
Willow Garage, detection of swimming pool drowning accidents in Europe, running
interactive art in Spain and New York, checking runways for debris in Turkey, inspecting
labels on products in factories around the world on to rapid face detection in Japan.

It has C++, Python, Java and MATLAB interfaces and supports Windows, Linux,
Android and Mac OS. OpenCV leans mostly towards real-time vision applications and takes
advantage of MMX and SSE instructions when available. A fullfeatured CUDA and OpenCL
interfaces are being actively developed right now. There are over 500 algorithms and about
10 times as many functions that compose or support those algorithms. OpenCV is written
natively in C++ and has a templated interface that works seamlessly with STL containers.

Figure 3.2.3: Open CV module in python

3.2.4 NumPy

NumPy is a Python library used for working with arrays. It also has functions for
working in domain of linear algebra, Fourier transform, and matrices. NumPy was created in
2005 by Travis Oliphant. It is an open-source project and you can use it freely.

NumPy is a general-purpose array-processing package. It provides a high performance

multidimensional array object, and tools for working with these arrays.
11
It is the fundamental package for scientific computing with Python. It is opensource

software. It contains various features including these important ones:

• A powerful N-dimensional array object

• Sophisticated (broadcasting) functions

• Tools for integrating C/C++ and Fortran code


Besides its obvious scientific uses, NumPy can also be used as an efficient
multidimensional container of generic data. Arbitrary data-types can be defined using NumPy
which allows NumPy to seamlessly and speedily integrate with a wide variety
of databases.

Figur.3.2.4: NumPy module in python Installation:

• Mac and Linux users can install NumPy via pip command: #pip install numpy

• Windows does not have any package manager analogous to that in linux or unix or
any mac. Please download the pre-built windows installer for NumPy from here (according
to your system configuration and Python version). And then install the packages manually.

3.2.5 Tkinter
Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a
powerful object-oriented interface to the Tk GUI toolkit. Import the Tkinter module

Python offers multiple options for developing GUI (Graphical User Interface). Out of
all the GUI methods, tkinter is the most commonly used method. It is a standard Python
interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and
easiest way to create the GUI applications.
As mentioned, Tkinter is Python's default GUI library, which is nothing but a wrapper

module on top of the Tk toolkit.

12
Tkinter is based upon the Tk toolkit, and which was originally designed for the Tool

Command Language (Tcl).

GUI development portability and flexibility of Tk makes it the right tool which can be used to
design and implement a wide variety of commercial-quality GUI applications. Python with
Tkinter provides us a faster and efficient way in order to build useful applications that would
have taken much time if you had to program directly in C/C++ with the help of native OS
system libraries.

Once we have Tkinter up and running, we'll use basic building blocks known as widgets to
create a variety of desktop applications.

Figure 3.2.5: GUI using python 3.2.6


System Requirements to install anaconda:
License:
Free use and redistribution under the terms of the EULA for Anaconda Distribution.

Operating system:
Windows 8 or newer, 64-bit macOS 10.13+, or Linux, including Ubuntu, RedHat, CentOS
7+, and others. If your operating system is older than what is currently supported, you can
find older versions of the Anaconda installers in our archive that might work for you.

System architecture:
Windows- 64-bit x86; MacOS- 64-bit x86 & M1; Linux- 64bit x86, 64-bit aarch64 (AWS
Graviton2), 64-bit Power8/Power9, s390x (Linux on IBM Z & LinuxONE).
Minimum 5 GB disk space to download and install. On Windows, macOS, and Linux, it
is best to install Anaconda for the local user, which does not require administrator
permissions and is the most robust type of installation. However, with administrator
permissions, you can install Anaconda system wide

13
Add packages to the Anaconda environment using the pip command

Open Anaconda Command prompt as administrator Use cd\ to come out of the set directory or

path.

Run pip install command. pip install NumPy pip install pandas pip install picklemixin pip
install Requests

Figure 3.2.6: Installation of libraries in anaconda

The above image shows the command prompt to install the libraries required to set up the
Anaconda IDE and also to perform the experiment to get the accurate output

3.3 HARDWARE REQUIRED


1. Speed- 1.1 Ghz

2. RAM – 256 MB

3. Keyboard - Standard Windows Keyboard


14
4. Mouse - Two or Three Button Mouse

5. Monitor- SVGA

3.3.1 Speed-1.1 Ghz

What Does GHz Mean in a Computer Processor?

One of the most frequently touted measures of processor is given chip's speed in
gigahertz. Processors with higher GHz ratings can, theoretically, do more in a given unit of
time than processors with lower GHz ratings. However, the processor's speed rating is just
one of many factors that impact how fast it actually processes data. Given that some
specialized applications can be very computationally demanding, choosing the fastest
computer is more important than buying a machine with the highest clock speed.

System Clocks
Processors work according to a clock that beats a set number of times per second,
usually measured in gigahertz. For instance, a 3.1-GHz processor has a clock that beats 3.1
billion times per second , also 1.1 Ghz processor has a clock that beats 1.1 billion times per
second. Each clock beat represents an opportunity for the processor to manipulate a number
of bits equivalent to its capacity - 64-bit processors can work on 64 bits at a time, while 32-bit
processors work on 32 bits at a time.

3.3.2 RAM – 256 MB


RAM (Random Access Memory) is the hardware in a computing device where the
operating system (OS), application programs and data in current use are kept so they can be
quickly reached by the device's processor. RAM is the main memory in a computer. It is
much faster to read from and write to than other kinds of storage, such as a hard disk drive
(HDD), solid-state drive (SSD) or optical drive. Random Access Memory is volatile. That
means data is retained in RAM as long as the computer is on, but it is lost when the computer
is turned off. When the computer is rebooted, the OS and other files are reloaded into RAM,
usually from an HDD or SSD How much RAM do you need?

The amount of RAM needed all depends on what the user is doing. When video editing, for
example, it's recommended that a system have at least 16 GB RAM, though more is desirable.
For photo editing using Photoshop, Adobe recommends a system have at least 3GB of RAM
to

15
run Photoshop CC on a Mac. However, if the user is working with other applications at the
same time, even 8GB of RAM can slow things down.

3.3.3 Key Board - Standard Windows Keyboard

A keyboard is one of the primary input devices that allows users to input text into a
computer or any other electronic machinery. It is a peripheral device that is the most basic
way for the user to communicate with a computer. It consists of multiple buttons, which
create numbers, symbols, and letters, and special keys like the Windows and Alt key,
including performing other functions. The design of the keyboard comes from the typewriter
keyboards, and numbers and letters are arranged on the keyboard in that way, which helps to

type quickly.

Figure 3.3.3:Standard windows keyboard

The above keyboard design is called Qwerty design because of its first six letters
across in the upper-left-hand corner of the keyboard. Although the keyboard design is derived
from the typewrites, nowadays, it also includes many other keys as well as Alt/Option,
Control, and Windows key can be used as shortcuts to perform the particular operation by
combination with other keys. For example, if you press Control + S while working on a
document in Microsoft word, it will save the document you are working on. Furthermore,
most of the keyboards have function keys (F1 to F12 or F16) at the top of the keyboard and
arranged arrow keys in the downside used to perform numerous functions.

3.3.4 Mouse -Two or three Button Mouse

A mouse is a small device that a computer user pushes across a desk surface in order
to point to a place on a display screen and to select one or more actions to take from that
position. The mouse first became a widely-used computer tool when Apple Computer made it
a standard part of the Apple Macintosh. Today, the mouse is an integral part of the graphical

16
user interface GUI of any personal computer. The mouse apparently got its name by being
about the same size and colour as a toy mouse.

Figure.3.3.4 Mouse
A mouse consists of a metal or plastic housing or casing, a ball that sticks out of the
bottom of the casing and is rolled on a flat surface, one or more buttons on the top of the
casing, and a cable that connects the mouse to the computer. As the ball is moved over the
surface in any direction, a sensor sends impulses to the computer that causes a mouse-
responsive program to reposition a visible indicator (called a cursor) on the display screen.
The positioning is relative to some variable starting place. Viewing the cursor's present
position, the user readjusts the position by moving the mouse.

3.3.5 Monitor – SVGA


Super video graphics array (Super VGA or SVGA) is a high-
resolution standard used to channel video data to a compatible visual output device - usually a
computer monitor. This is actually a broad umbrella term for other computer display
standards.

Originally, it was just an extension to the VGA standard, which was a purely IBM
defined standard also known as ultra video graphics array (UVGA).

Figure 3.3.5: An SVGA monitor

17
CHAPTER 4
DESIGN AND IMPLEMENTATION
4.1 DESIGN PROCESS
This chapter will explain the general methodologies and list down technologies used
in the methodologies step.
This project follows standard machine learning pipeline process.

Figure 4.1.1:Machine Learning Pipeline Flowchart

Data Collection

Before started to collect the dataset, we need to define the data that we need to collect.
Therefore, a short interview is conducted with Mr Seong, a certified workout trainer that currently
works in FEEX Fitness Ideal Sdn Bhd. A lot of data has been gathered during the interview
included examples of incorrect posture performed by trainee. A list of common improper postures
was listed down and will be recognised and evaluated by the trained model. Mr Seong also
demonstrated the improper and proper postures to make sure the dataset contains correct proper
and improper posture workout video.
After I defined the list of class, I need to collect dataset in order to train tthe model, therefore
several workout videos are recorded and will be used in Model Training stage. The system
requires trainees to upload their exercise videos with any common format such as MP4,
MOA, AVI and etc. A total workout dataset is recorded in MP4 format with 2.19GB that
consists of three different workouts (Figure 3.2). There are total 845 repetitions with 265
repetitions in Bicep Curl class, 280 in Front Raise class and 300 repetitions in Shoulder Press
class.
There are totally seven classes including six improper postures and one proper posture in
Bicep Curl class, six classes including five improper postures and one proper posture in Front
raise class and six classes including five improper postures and one proper posture in
Shoulder Press class.

18
Figure 4.1.2:Fitness video process

Data Preparation

After the collection of dataset, I have performed some operations in Data Preparation Stage
(Figure 4.1.3).

Figure 4.1.3: Overview Process of Data Preparation Stage

First, I realised OpenCV is having problem in orienting video in correct angle. Some
videos that captured in portrait by phone will view as landscape in OpenCV (Figure 3.4).

19
Figure 4.1.4: Showing in Landscape Instead of Portrait

Open Pose has a flaw which it does not work well in disoriented frame. As shown in
Figure 4.1.4, OpenPose was unable to locate correct keypoints and identifying correct
keypoints is the important step for workout recognition.

To solve this challenge, the system must read the metadata that name rotation, this
metadata tells the video player to rotate the video for how many angles. Therefore, moviepy
is deployed to read the value of rotation metadata is rotate the video according to the value
(Figure 4.1.5).

Figure 4.1.5: Solution to Disoriented Video

20
Open Pose model will apply on these videos to identify the joint keypoints. A total of
eighteen keypoints will be identified in every video if a human object is detected (Figure
3.7). To be specific, the output of OpenPose model is a list of geometric position of 18
human keypoints and these geometric positions are still considered as raw data that do not
provide a lot of useful information for Model Training stage.
The next problem will be standardising the video perspective. For example, Figure
3.8 is showing two different perspectives even both users are facing same side to the camera.
4.2 IMPLEMENTATION
Conda is an open-source package and environment management system that runs
on Windows, macOS, and Linux. Conda quickly installs, runs, and updates packages and
their dependencies. It also easily creates, saves, loads, and switches between environments
on your local computer. It was created for Python programs, but it can package and distribute
software for any language.
Step 1 :
Click and Start All Programs Anaconda Command Prompt. A command
prompt window will open. Type idle to run the Python interpreter. A new window
titled Python Shell will open and you will see the Python >>> command prompt.

Figure.4.2.1:command prompt of anaconda

Step 2:
After running the command prompt of anaconda we will be able to get python IDLE
shell and now open the app file which is in the PC containing python program of GUI fitness
trainer.

21
Figure.4.2.2: command prompt
shell

Step 3:
Run the program and we will be able to get the output such as GUI containing the
commands or the exercises what we required to do and the output will be displayed as
followed by next step.

Figure 4.2.3: GUI AI Fitness trainer

Step 4:

Media Pipe is an open-source framework for building pipelines to perform computer vision
inference over arbitrary sensory data such as video or audio. Using MediaPipe, such a
perception pipeline can be built as a graph of modular components. In computer vision

22
pipelines, those components include model inference, media processing algorithms, data
transformations, etc. Sensory data such as video streams enter the graph, and perceived
descriptions such as object-localization or face-keypoint streams exit the graph.

Step 5: Figure 4.2.4:Node points stream

Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a powerful object-
oriented interface to the Tk GUI toolkit and with the help of Tkinter a GUI will be displayed
where we can see a person is doing a particular exercise on the screen.

Figure.4.2.5: GUI Application

23
CHAPTER-5
ADVANTAGES, LIMITATIONS AND APPLICATIONS
5.1 ADVANTAGES:

Ability to enhance performance :

Individuals of all fitness levels and abilities can create fitness objectives that are
tailored to their individual goals based on the devices they are using. In order for artificial
intelligence to provide meaningful insights, several characteristics will often need to be taken
into consideration, such as height, age and weight.
Artificial Intelligence-based diet planning ;

In many cases, diet and meal planning can be made more effective by utilising fitness
applications powered by artificial intelligence. When you're trying to achieve a certain
weight loss or fitness goal, you're likely to be able to benefit from a tool like this.
With the right food, you can achieve pretty much any realistic fitness dream. In fact,
nutrition has been shown to be more important than exercise when it comes to our health.
Thus, many of the best AI-based home training programs provide users with individualised
diet plans.
There are also different diet plans you can choose from, whether it's a vegetarian or rich
in protein, allowing you to further fine-tune the application to your needs.
General benefits of using AI in your fitness routine
Overall, there are several ways that individuals are likely to see their fitness routine improve
thanks to the use of smart technology. For one, it's often far more accessible than a personal
trainer, which simply makes it easier to get the information you need without having to rely
on another human being or keep up with the sometimes extortionate payments.

5.2 LIMITATIONS

 In-Person Coaches Provide the Most Customization and Personalization


 While the combination of AI with digital fitness coaching has a ton of potential and
while AI is changing the way people exercise in person fitness coaching offers a
tailored experience based on your individual goals and needs.
 Human Coaches Provide a Safer Experience
 Proper form during exercise is crucial to avoid injury and maximize the benefits
 of your workouts. And in-person coaches excel at providing real-time feedback,
making sure you maintain good form throughout your training sessions.
24
 The Human Factor for Staying on Track
 A human coach's ability to inspire, empathize, and support you can truly enhance
your engagement and dedication to your fitness journey.
 They can keep you motivated, ensuring you stay committed to your goals.

5.3 APPLICATIONS

 AI in fitness makes workouts more engaging and fun


 We can design different exercises for different age groups of users.
 Apart from this, the application can be used to spread awareness about the
different health-related government schemes and different health insurance related
information.
 AI powered personal trainer use a series of algorithms and machine learning to
recognise various human body joints. As a result, every posture could be analysed
for users by pinpointing strengths and weaknesses to assist them to get improved
body areas that need attention.
.

25
CHAPTER-6
RESULT ANALYSIS
The use of AI in personal training has become increasingly popular, allowing for
customizable and tailored workouts that can be tailored to the individual. However, it is
important to acknowledge the potential drawbacks that come with this technology. AI
technology can also customize fitness plans according to individual goals, providing detailed
insights down to a granular level which was previously not possible taking into account the
user’s medical history, biological makeup, lifestyle, and even environmental factors.

Step-1:Giving Input:

Here we are able to see the window of exercises also we need to select the exercise.
And the another window will be displayed to record the exercise.

Figure.6.1 Display of fitness exercises

Step-2: Internal Processing:


The OpenCV is used to display the output window where the video of the human
doing exercise is displayed and mediapipe is used to calculate the node points of human
doing exercise.

26
Figure.6.2:AI Fitness trainer using Mediapipe

Step-3: Final output:

The final stage displays the output that shows to count the exercise and the exercise is
displayed with the node points of human on a monitor.

SIT UP:

WALK:

27
PULL UP:

SQUAT:

Figure.6.3: Displays output

28
FUTURE SCOPE
AI revolutionizes fitness through fitness equipment that makes home workouts
smarter and better. In addition to the smart wearable (Apple Watch, Fitbit, and more)
which may help you track your fitness, personal AI trainers are also gaining in popularity
at an unparalleled rate.
Those who use AI personal trainers would know this new notion in the field of fitness,
but those who are amateur must be intrigued about it.

29
CONCLUSION
As a conclusion, the workout recognition and evaluation system had been successful
developed to achieve the project objectives. The system with the function of detect and
recognize the workout type from the input video had been tested with multiple workout type
under different environments and achieved around 98% accuracy. On the other hand, the
system is also able to classify different types of improper posture with the accuracy of
80.69% for Bicep Curl class, 65.35% for Front
Raise class and 89.75% for Shoulder Press class.
The problem of this project is the OpenPose model may tend to miss out some of the
joint keypoints. This may due to some factors such as complex background or dark
environment. It is essential to get the video which has better resolution or quality for the
detection and recognition. The another problem caused by OpenPose model is the time taken
for it to retrieve the keypoints location. Perhaps in future there are other alternative ways to
retrieve body keypoints location in shorter time, maybe within one second for one frame. The
problem restraints me for deploying the model in real-life scenario. There is actually another
interesting problem which is the complexity of human body movement. It is impossible to
list out every possible posture that made by human. Therefore, the improper postures that
predicted in this project are actually just the few most common postures.
There are actually few novelties and contributions from this project. The first one will
be creating new benchmark for this workout dataset. The reason I create my own workout
dataset is because I couldn’t find any public workout dataset. Therefore, I have uploaded the
workout dataset to Kaggle so that other people can access to my dataset for free and all the
annotations have been made. My approach that shown in this project can be a benchmark
approach for this dataset. Hopefully by making this dataset public to CV community can
raise the attention to the evaluation of quality in performing an activity field.

30
BIBLIOGRAPHY
Barbara, M 2014, Are you too Embarrassed to Exercise? Available from:
<https://www.psychologytoday.com/intl/blog/shyness-is-nice/201401/areyou-
tooembarrassed-exercise>. [05 August 2019].

Bonaros, B 2019, K-Means Elbow Method Code For Python Available from:
<https://predictivehacks.com/k-means-elbow-method-code-for-python/>. [22
April 2020].

Chen, S & Yang, R 2018, Pose Trainer: Correcting Exercise Posture using Pose Estimation.
Department of Computer Science Stanford University, California:
Stanford.

Eduardo, V, et al., 2013, Qualitative Activity Recognition of Weight Lifting Exercises.


th
Proceedings of the 4 Augmented Human International
Conference, pp. 116-123.

Imran, V, 2015, How to Choose the Value of K in KNN Algorithm. Available from:
<https://discuss.analyticsvidhya.com/t/how-to-choose-the-value-of-k-inknnalgorithm/2606>.
[22 April 2020].

Jason, B 2019, A Gentle Introduction to Computer Vision. Available from:


<https://machinelearningmastery.com/what-is-computer- vision/?
fbclid=IwAR375th0DO4vfPNy7n9BqGbx_gRizi3Wi_7JgyJE1RYbv9 NETFWxJxKBGm4>. [28
July 2019].

Jason, B 2019, A Gentle Introduction to Object Recognition With Deep Learning. <Available
from: https://machinelearningmastery.com/object-recognitionwith-deeplearning/>. [28 July
2019].

Kim, D, Cho, M, Park, Y, & Yang, Y 2015. Effect of an exercise program for posture
correction on musculoskeletal pain. Journal of physical therapy science, vol.
27, no. 6, pp. 1791–1794. doi:10.1589/jpts.27.1791

Kowsar, Y, Moshtaghi, M, Velloso, E, Kulik, L & Leckie, C 2016, Detecting Unseen


Anomalies in Weight Training Exercises. Microsoft Research Centre for Social NUI, pp.
517- 526.
Mike, S n.d., Posture-Improving Weight-Lifting Exercises. Available from:
<https://www.livestrong.com/article/371062-weight-lifts-thatimprove-posture/>. [01 August
2019].

Novatchkov, H & Baca, A 2012, Machine Learning Methods For The Automatic
th
Evaluation Of Exercises On Sensor-Equipped Weight Training Machines. 9
Conference of the International Sports Engineering Association, vol. 34, pp.
562–567.

Paul, R 2019, A Fundamental Guide to Weight Training. Available from:


<https://www.verywellfit.com/weight-training-fundamentals-a-conciseguide3498525>.[30
July 2019].

31
Qian, H, Mao, Y, Xiang, W & Wang, Z 2010, Recognition of Human Activities Using
SVM Multiclass Classifier. Pattern Recognition Letters, vol. 31, no. 2, pp.
100-111.

Timo, R, 2018, Python Vs. C++ for Machine Learning – Language Comparison. Available
from: <https://www.netguru.com/blog/python-vs.-c-for-machinelearninglanguage-
comparison>. [12 August 2018].

32
GLOSSARY
AI
Artificial intelligence Graphical- user interface Machine learning

GUI separated values Convolutional


comma - neural network Dynamic

MLwrapping
time -

CSV - k-nearest neighbour

CNN - Compute unified device architecture

DTW - Python package index

KNN - Graphics processing unit

CUDA - cognitive toolkit

PyPI - open source computer vision library

GPU - Toolkit

CNTK - Random access memory

OPEN CV - Super video graphics array

TK - Operating system

RAM - Hard disk drive

SVGA - Solid state drive

OS - Integrated development and learning environment

HDD - Artificial neural networks

SSD -

IDLE -

ANN -

33
APPENDIX
GUI FITNESS TRAINER.py

# python main.py -t sit-up


# or python main.py -t pull-up
# or python main.py -t push-up
# or python main.py -t
squat # or python
main.py -t walk

import sys
import os
from tkinter
import *

window=Tk()

window.title("AI FITNESS
TRAINER")
window.geometry('320x320')

def walkai():
os.system('python main.py -t
walk')

def squatai():
os.system('python main.py -t
squat')

def pushupai():
os.system('python main.py -t
push-up')

def pullupai():
os.system('python main.py -t
pull-up')

34
def situpai():
os.system('python main.py -t
sit-up')

walk = Button(window, text="WALK", fg="red",command=walkai)


walk.pack( side = LEFT)

squat = Button(window, text = "SQUAT", fg = "blue",command=squatai)


squat.pack( side = RIGHT )

pushup = Button(window, text="PUSH-UP",fg="red",command=pushupai)


pushup.pack( side = TOP)

pullup = Button(window, text = "PULL-UP", fg = "blue",command=pullupai)


pullup.pack( side = BOTTOM )

situp = Button(window, text = "SIT-UP", fg = "green",command=situpai)


situp.pack(side=TOP, expand=YES)

window.mainloop()

main.py

# python main.py -t sit-up


# or python main.py -t pull-up
# or python main.py -t push-up
# or python main.py -t
squat # or python
main.py -t walk

import cv2
import argparse
from utils
import * import
mediapipe as
mp
from body_part_angle import BodyPartAngle
35
from types_of_exercise import TypeOfExercise

ap =
argparse.ArgumentParser()
ap.add_argument("-t",
"--exercise_type",
type=str,
help='Type of activity to
do', required=True)
ap.add_argument("-vs",
"--video_source",
type=str, help='Type
of activity to do',
required=False)
args = vars(ap.parse_args())

args = vars(ap.parse_args())

mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose

if args["video_source"] is not None: cap =


cv2.VideoCapture("Exercise Videos/" +
args["video_source"]) else: cap =
cv2.VideoCapture(0) # webcam

cap.set(3, 800) # width


cap.set(4, 480) # height

# setup mediapipe with


mp_pose.Pose(min_detection_confidence=
0.5,
min_tracking_confidence=0.5) as pose:

counter = 0 # movement of
exercise status = True #
state of move while
cap.isOpened(): ret,
frame = cap.read()
# result_screen = np.zeros((250, 400, 3), np.uint8)

frame = cv2.resize(frame, (800, 480), interpolation=cv2.INTER_AREA)

36
# recolor frame to RGB

37
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame.flags.writeable = False
# make detection
results =
pose.process(frame) #
recolor back to BGR
frame.flags.writeable = True frame =
cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)

t
r
y
:
landmarks = results.pose_landmarks.landmark
counter, status =
TypeOfExercise(landmarks).calculate_exercise( args["exercise
_type"], counter, status) except: pass

frame = score_table(args["exercise_type"], frame, counter, status)

# render detections (for landmarks)


mp_drawing.draw_landmarks(
frame,
results.pose_landmarks,
mp_pose.POSE_CONNECTIONS,
mp_drawing.DrawingSpec(color=(255, 255, 255),
thickness=2,
circle_radius=2),
mp_drawing.DrawingSpec(color=(174, 139, 45),
thickness=2,
circle_radius=2),
)

cv2.imshow('Video', frame)
if cv2.waitKey(10) & 0xFF ==
ord('q'): break

cap.release()
cv2.destroyAllWindows()

38
39

You might also like