You are on page 1of 36

Visvesvaraya Technological University

BELAGAVI, KARNATAKA.

AN INTERNSHIP REPORT

ON

“Deep Learning using PyTorch for Fall Detection”

Submitted to Visvesvaraya Technological University in partial


fulfillment of the requirement for the award of Bachelor of Engineering degree
in Computer Science and Engineering.

Submitted by

ARJUN C M 4JN20CS013

Under the guidance of


Mrs.Thaseen Bhashith. B.E., M.Tech.
Asst Professor, Dept. of CS&E,
JNNCE, Shivamogga.

Department of Computer Science & Engineering


Jawaharlal Nehru New College of Engineering
Shivamogga - 577 204
March 2024
National Education Society ®

CERTIFICATE
This is to certify that the internship entitled

“Deep Learning using PyTorch for Fall Detection”

Submitted by

ARJUN C M 4JN20CS013

Students of 8th semester B.E. CS&E, in partial fulfillment of therequirement


for the award of degree of Bachelor of Engineering in Computer Science and
Engineering of Visvesvaraya Technological University, Belagavi during the year
2023-24.

Signature of Guide Signature of Co-Ordinator

Mrs. Thaseen Bhashith. B.E., M.Tech Mrs Sreedevi S. B.E.,M.Tech


Asst Professor, Dept. of CS&E Assistant Professor, Dept. of CS&E

Signature of HOD

Dr. Jalesh Kumar B.E., M.Tech., Ph.D.


Professor and Head, Dept. of CS&E

Examiners: 1. 2.
ABSTRACT

Fall detection is a critical aspect of ensuring the safety and well-being of individuals, particularly
in contexts such as eldercare and healthcare facilities. Leveraging the advancements in artificial
intelligence and machine learning (AIML), this internship project aims to develop an efficient
human fall detection system using the PyTorch framework. The project begins with a
comprehensive exploration of existing fall detection methods and the challenges they pose.
Traditional methods often suffer from limitations in accuracy and scalability, motivating the
adoption of deep learning techniques facilitated by frameworks like PyTorch. Through this
internship project, participants will delve into PyTorch's capabilities, including its dynamic
computation graph and ease of model development. They will gain hands-on experience in dataset
preparation, model architecture design, and the training process using PyTorch.

i
ACKNOWLEDGEMENT

On presenting the internship seminar on “Deep Learning using PyTorch for Fall
Detection” I feel great to express my humble feelings of thanks to all those who have
helped me directly or indirectly in the successful completion of the internship seminar.
I would like to thank my respected guide Mrs. Thaseen Bhashith, Assistant
Professor, Dept. of CS&E, for her valuable suggestions and treasured assistance
throughout the internship and seminar.
I would like to thank my respected internship Seminar coordinator Mrs. SreedeviS
, Assistant Professor, Dept. of CS&E who have helped me a lot in completing this task,
for their continuous encouragement and guidance throughout the internship seminar.
I would like to thank Dr. Jalesh Kumar, Professor & Head, Dept. of CS&E, and
Dr. Y Vijaya Kumar, Principal, JNNCE, Shimoga for all their support and
encouragement.
I express my profound thanks to Ekathva Innovations Pvt. Ltd., Shimoga, and the
resource person Dr. Chetan K R, Professor & Head, Dept. of AI&ML for providingan
opportunity to carry out internship in their organization.
I am grateful to our institution Jawaharlal Nehru New College of Engineering and
Department of Computer Science and Engineering for imparting to me the knowledge
with which I can do my best.
Finally, I would also like to thank the whole teaching and non-teaching staff of
Computer Science and Engineering.

Thanking you all,

ARJUN C M
4JN20CS013

ii
TABLE OF CONTENT

ABSTRACT i
ACKNOWLEDGEMENT ii
TABLE OF CONTENT iii
Chapter 1 Company Profile 1-2
1.1 JNNCE EI 1-2
1.2 Ekathva Innovations Pvt.Ltd. 2
Chapter 2 About the Company 3-7
2.1 Initiatives of CIE 3-4

2.2 Additional Initiatives of CIE 4-6


2.3 Startups under CIE 6
2.4 Members of CIE 7
2.5 Members of Ekathva Innovations 7
Chapter 3 Tasks Performed 8-12
3.1 Technical Skills 8-11
3.1.1 Overview of AI 8-10

3.1.2 NumPy and PyTorch 10

3.1.3 Deep Learning framework 11

3.1.4 CNN 11
3.2 Soft Skills 11-12

3.3 Experiences 12
Chapter 4 Reflection Notes 13-22
4.1 Assignments 13-18
4.2 Project Overview 19
4.3 Implementation 20-24

4.4 Results and Analysis 24-25

Chapter 5 Conclusion 26

Bibliography 27

iii
Deep Learning using PyTorch for Fall Detection

Chapter 1
COMPANY PROFILE
The internship was carried out at Jawaharlal Nehru New College of Engineering,
Shivamogga. It was carried out under JNNCE EI LEARN Platform – a collaboration
between JNN College of Engineering with Ekathva Innovations Pvt. Ltd. The profile of
JNNCE EI and Ekathva Innovations Pvt. Ltd. are discussed in the following sections.

JNNCE EI
JNNCE - EI LEARN platform builds an online learning platform to engage the student
community with courses offered in the latest, trending technologies to make them job ready
by task-based, project-based courses by industry and academic trainers.
These Certification Courses are required for various reasons as mentioned below:
 These courses provide in-depth knowledge of the underlying technology needed
to perform a task efficiently.
 These courses are job focused and provide various technical skills related to the
development of full-stack applications, hybrid applications, database
applications, mobile applications, and many others. This helps an individual to
perform well when dealing with complex projects, vendors, and multiplatform
environment.
 To enhance the confidence level of an individual.
 The curriculum of these courses is designed in such a way that it includes all
practical skills to be used at the workplace. When an individual has prior
knowledge of his subject area it helps him to perform much more confidently
and efficiently at workplace.
 It provides training on designing, development, deployment, testing, and
documentation on the real-time projects and applies effectively into their work
environments. This assures employers about the capabilities of an employee that
he/she can successfully complete a job.
 It provides detailed knowledge and skills required to perform real-world job
responsibilities.

Dept of CS&E, JNNCE, Shivamogga Page 1


Deep Learning using PyTorch for Fall Detection

 Certification Course is followed by a series of tests conducted at the completion


of the course that helps to assess the capabilities and expertise of an individual
in his/her chosen subject area.

Ekathva Innovations Pvt. Ltd.


With the zeal of simplifying the day-to-day problems in the field of electronics, an
Indianstart-up company Ekathva Innovations Pvt., Ltd., came into the mainstream. The
company consists of electronics and computer science engineers who have enthusiasm
for making day-to-day life better with their creative ideas. The company, which was
established in mid of 2018 in the JNNCE Campus, Shivamogga in Karnataka state is
targeting the electronics and information technology field. The company mainly aims in
making user-friendly and economic products in the areas of design and development of
Embedded Systems, Printed circuit boards, Industrial automation, Home automation, and
automotive electronics which comes in the horizon of electronics whereas website
development and app development both on android and iOS in the field of information
technology. The company also banks on some in- house projects and is always open to
the projects proposed by clients.

Dept of CS&E, JNNCE, Shivamogga Page 2


Deep Learning using PyTorch for Fall Detection

Chapter 2
ABOUT THE COMPANY

This chapter details on the products, services, and organizational details of Ekathva
Innovations Pvt. Ltd. The milestones and departmental subdivisions are also explored.

Initiatives of CIE

NewGen IEDC: National Science and Technology Entrepreneurship Development


Board(NSTEDB), Department of Science & Technology (DST), Government of India
has started New Generation Innovation and Entrepreneurship Development Centre
(NewGenIEDC) at JNNCE in 2018 to “promote knowledge based and technology- driven
start-ups by harnessing young minds and their innovation potential in an academic
environment”. Students will be encouraged to take up innovative projects with possibility
of commercialization. Few amongst the “Job-Seekers” would be converted to “Job-
Generators” through the entrepreneurial route. Best 10 innovative projects in Batch-1
(2019-20) have been selected recently in which each project team will get upto Rs. 2.5
Lakhs funding support to undergo their projects.

New Age Incubation Network (NAIN) Centre: Department of IT BT, Government of


Karnataka has started “New Age Incubation Network” Centre at JNNCE in 2014 to build
startup & business ecosystem in and around Shivamogga. Innovative Project proposals
will be invited from JNNCE students, Alumni, Research Scholars & the public every year.
For Top 10 innovative ideas, there will be a funding of upto Rs. 3.00 Lakhs per Project.
Best 43 innovative projects in Batch-1 (2015-16), Batch-2 (2016-17), Batch-3 (2017-18) &
Batch-4 (2019-20) have been funded to a maximum of Rs. 3.00 Lakhs per project.

JNNRIC: JNNCE Research & Innovation Centre aims to nurture innovation and
encourageentrepreneurial talents among students, faculty and people of the region, and to
facilitate inter-disciplinary research and coordinates with Incubation Center to bring up
start-ups and promote budding entrepreneurs. JNNRIC might include research proposals
addressingthe Agricultural Technology, Renewable Energy and Energy Conservation
System ICT for Socially relevant problems. JNNRIC will assist students.

Dept of CS&E, JNNCE, Shivamogga Page 3


Deep Learning using PyTorch for Fall Detection

Faculty, staff and students to boost the research and Innovation by way of funding to
a certain extent (seed money) every year as shown in Table 2.1
JNNCART: Centre for Agriculture & Rural Technology, a Centre for Appropriate and
Agricultural Technologies was setup at JNNCE with the objective of serving farming
community and other people of the Malnad region. Students will be motivated to address
problems faced by the farmers through innovative, cost effective farming implement part
of their project work as prescribed in academic curriculum.
CART nurtures innovation, and encourages entrepreneurial talents among students, faculty
and people of the region to help agricultural needs of the farmers. It facilitates inter-
disciplinary research and coordinates with incubation centre to bring starts-ups and budding
entrepreneurs.
CART aims to Encourage students and faculty for innovation, idea generation and
product development, provide seed fund to transform an idea into a product, Arrange
workshops forstudents to create awareness in the field of agri-based entrepreneurship, help
with the patenting process, Inspire and support staff and students to achieve their potential
and meet the challenges of society, Facilitate development of at least two innovative
products that are socially relevant. The five products selected and executed for the year
2018-19 are
1. Arecanut Plucker cum Sprayer
2. Multipurpose Hybrid Sprayer
3. Mini Trencher Trenching Machine
4. Hydrophobic sand to combat water scarcity in irrigation
5. Trenching Machine

Additional Initiatives of CIE


Technology Business Incubator (TBI): Karnataka Council for Technological Upgradation
(KCTU), Govt. of Karnataka has approved a TBI and will be started soon. The main objective
of this TBI is to promote untapped creativity of individual innovators and to assist them to become
technology-based entrepreneurs. JNNCE – TBI aims to provide common instrumentation facility,
Mentors and Investors connection, Co-Working Space, Office Space, Small Manufacturing Units,
access to laboratories etc., for all associated individuals, innovators, startups, MSMEs and
Companies.

Dept of CS&E, JNNCE, Shivamogga Page 4


Deep Learning using PyTorch for Fall Detection

JNNCE-MHRD Institution’s Innovation Council: In association with MHRD’s


Innovation Cell (MIC) of AICTE, CIE JNNCE is working towards establishing an
Institution’s Innovation Council. Institution’s Innovation Council (IIC) at the Institute is a
unique model based on Hub-Spoke and coherence approach to align with the innovation
and entrepreneurship promotion and support programs are being organized by various
departments and ensures round the year activities in the campus for effective engagement,
learning and practicing innovation and entrepreneurship among students and faculty
community. Ideally, the Institution’s Innovation Council is a faculty-led but student-
centric body formed by the institute with the active representation of entrepreneurial
faculties, students and experts representations from regional ecosystem enablers, pre-
incubation and incubation centers within and outside the institute and work in synergize
manner towards to provide a platform to encourage, inspire and nurture young students by
exposing them to new ideas and process of resulting in innovative activities &
entrepreneurial in their formative years.

Intellectual Property Cell (IP Cell): In association with KSCST, VTPC and Inova Tree,
CIE JNNCE is working towards establishing an IP Cell to provide all required information
& guidance on IPR to Students, Alumni, Faculty, Research Scholars, Innovators, Startups,
Companies, Industrialists, Academic Institutions & Universities in and around
Shivamogga. Entrepreneurship Cell (E-Cell): In association with E-Cell IIT Madras, CIE
JNNCE is working towards establishing an E-Cell with the objective to develop spirit of
Entrepreneurship among the students, to motivate students towards self-employment and
entrepreneurship, to blend technical skills of students with entrepreneurial skills to convert
their innovative ideas into enterprise. Activities of this cell include Conducting Awareness
Programs, Skill Development Programs, Workshops, Business Plan Competitions, Boot
Camps, Entrepreneurial Talks, Mentoring Students, taking up innovative projects,
assisting in getting financial support, Company Incorporation, IPR etc., for Startups.

Technology Activities & Programs (TAP): A club of passion driven young students
excelling together, either be it in the process of creating innovations, be it being active &
rebellious dreamers in turning real time challenges prevailing in academics & to develop
an individual in all possible ways by learning & sharing the skillsets. TAP is a knowledge
sharing & knowledge gaining platform for all the interested students from

Dept of CS&E, JNNCE, Shivamogga Page 5


Deep Learning using PyTorch for Fall Detection
different streams & semesters which helps every individual student to be an out-of-the-
box thinker which helps to do innovative projects. Here the students can conduct group
activities, undergo projects etc., Ideas/Projects developed from TAP teams will be
supported by other platforms for further development & commercialization.

NAIN Creative Club: NAIN Creative Club, an initiative of NAIN Centre was started on
23rd September 2017 to provide a open platform for students to learn, excel & train
students by conducting workshops & Seminars on various cutting edge technologies &
languages. Club supports inter-departmental activities, which ignites the students to think
out of box and helps to gain & explore creativity.

Table2.1: CIEProject Funding

Sl. No Project Type Funding/Project No.of projects Total Funding


(INR) (In INR)
1. Innovative Up to Rs. 10 2,50,000
Project 25,000/-
2. Research & Up to Rs. 7 3,50,000
Innovation 50,000/-
Project
3. Research Project Up to Rs. 9 9,00,000
1,00,000/-

Startups under CIE


Ekathva Innovations Pvt. Ltd. was started in July 2018 by Mr. Vikas H C & teamfrom
NAIN first batch
CIE also has following development centers:

• Roots Goods Development Centre by Roots Goods OPC Pvt. Ltd.

• Sunrise Digital Media Development Centre by Sunrise Digital Media Pvt. Ltd.

• Ventalyst Development Centre by Ventalyst Pvt. Ltd.

• Silfra Tech Development Centre by Silfra Technologies Pvt. Ltd.

Many other Innovators, Project Teams, Startups, MSMEs & Companies are in
discussions and in pipeline to setup Startups, Development Centers & Centers of
Excellence at JNNCE under CIE. CIE also is in the process of establishingJNNCE
Research Park with the objective of pursuing research in technologies.

Dept of CS&E, JNNCE, Shivamogga Page 6


Deep Learning using PyTorch for Fall Detection

Members of CIE
1. Mr. Arun Kumar, Assistant Professor MCA, Project Manager, Center for
Innovation & Centre,Jawaharlal Nehru New College of Engineering, Shivamogga

2. Dr. Basappaji, Prof. Dept. of Mechanical Engineering,Project Coordinator, Chief


Coordinator, NewGen IEDC

3. Dr. Manjunath P Prof. Dean Academics, Dept. of ECE College Coordinator, NAIN
Centre
4. Dr. E Basavaraj Professor, Dept. Of Mechanical Engineering, Co-Ordinator,
JNNCART
5. Dr. Karthika B S, Assoc. Prof. and Head, Dept. of Civil Engineering, Convener,
JNNRIC

Members of Ekathva Innovations


With the ideas of innovation in creating the better future in the ever-changing fieldof
electronics and IT, company wants to be pioneer in some of the products which will change
the perspective of everyday life to the layman too. With the motto of invent for betterment,
Ekathva aims to strive hard in bringing out the economic, uncomplicated, simple products
to the world.
Ekathva Innovations currently having 5 members in team 4 directors and 2 employees
1. Vikas H C Co-Founder, CEO and Embedded Developer
2. Akshay K Kulkarni Co-Founder, COO and Full Stack
‘Software Developer
3. Koushik R Udupa Co-Founder and Embedded Developer
4. Akshay K Co-Founder and CFO
5. Manthan K Full Stack Developer

They are currently working on a Embedded Product which is under patent process
and on Information Technology services like Website Development, App Development
and Customized Software.

Dept of CS&E, JNNCE, Shivamogga Page 7


Deep Learning using PyTorch for Fall Detection

Chapter 3
TASKS PERFORMED
Technical Skills

Technical skills are the specialized knowledge and expertise required to perform
specific tasks and use specific tools and programs in real world situations. Diverse technical
skills are required in just about every field and industry, from IT and business administration
to health care and education.

Overview of AI
According to the father of Artificial Intelligence, John McCarthy, it is “The science
and engineering of making intelligent machines, especially intelligent computer
programs”.Artificial Intelligence is a way of making a computer, a computer-controlled
robot, or asoftware think intelligently, in the similar manner the intelligent humans
think. AI isaccomplished by studying how human brain thinks, and how humans learn,
decide, andwork while trying to solve a problem, and then using the outcomes of this study
as a basisof developing intelligent software and systems.
Goals of AI:
 To create an expert System: The systems which exhibit intelligent behavior, learn,
demonstrate, explain, and advise its users.
 To implement Human Intelligence in Machines: Creating systems that understand,
think, learn, and behave like humans.

Applications of AI

AI has been dominant in various fields such as −

 Gaming − AI plays crucial role in strategic games such as chess, poker, tic-tac- toe,
etc., where machine can think of large number of possible positions based on
heuristic knowledge.
 Natural Language Processing − It is possible to interact with the computer that
understands natural language spoken by humans.
 Expert Systems − There are some applications which integrate machine, software,

Dept of CS&E, JNNCE, Shivamogga Page 8


Deep Learning using PyTorch for Fall Detection
and special information to impart reasoning and advising. They provide

Dept of CS&E, JNNCE, Shivamogga Page 9


Deep Learning using PyTorch for Fall Detection

explanation and advice to the users.


 Vision Systems − These systems understand, interpret, and comprehend visual
input on the computer. For example,
1) A spying aero plane takes photographs, which are used to figure out spatial
information or map of the areas.
2) Doctors use clinical expert system to diagnose the patient.
3) Police use computer software that can recognize the face of criminal with the
stored portrait made by forensic artist.
 Speech Recognition − Some intelligent systems are capable of hearing and
comprehending the language in terms of sentences and their meanings while a
human talks to it. It can handle different accents, slang words, noise in the
background, change in human’s noise due to cold, etc.
 Handwriting Recognition − The handwriting recognition software reads the text
written on paper by a pen or on screen by a stylus. It can recognize the shapes of the
letters and convert it into editable text.
 Intelligent Robots − Robots are able to perform the tasks given by a human. They
have sensors to detect physical data from the real world such as light, heat,
temperature, movement, sound, bump, and pressure. They have efficient processors,
multiple sensors and huge memory, to exhibit intelligence. In addition, they are
capable of learning from their mistakes and they can adapt to the new environment.
Types of AI:
1. Reactive Machine:
 Purely reactive machines are the most basic types of AI.
 Such AI systems do not store memories or past experiences for future
actions.
 These machines only focus on current scenarios and react on it as per
possible best action.
 IBM’s Deep Blue system is an example of a reactive machine.
 Google’s AlphaGo is also an example of a reactive machines
2. Limited Memory:
 Limited memory machines can store past experiences or some data for a
short period of time.

Dept of CS&E, JNNCE, Shivamogga Page 10


Deep Learning using PyTorch for Fall Detection

 These machines can use stored data for a limited time period only.
 Self-driving cars are one of the best examples of Limited Memory systems.
These cars can store the recent speed of nearby cars, the distance of other
cars, the speed limit, and other information to navigate the road.
3. Theory of Mind:
 Theory of Mind AI should understand the human emotions, people, beliefs,
and be able to interact socially like humans.
 This type of AI machines is still not developed, but researchers are making
lots of efforts and improvement for developing such AI machines.
4. Self-Awareness:
 Self-Awareness AI is the future of Artificial Intelligence. These machines
will be super intelligent and will have their own consciousness, sentiments,
and self-awareness.
 These machines will be smarter than the human mind.
 Self-Awareness AI does not exist still and it is a hypothetical concept.

NumPy and PyTorch


PyTorch is a machine learning framework based on the Torch library, used for
applicationssuch as computer vision and natural language processing, originally developed
by Meta AIand is now part of the Linux Foundation umbrella. It is free and open-source
software. NumPy is Python library that provides a simple yet powerful data structure: the
n-dimensional array. This is the foundation on which almost all the power of Python’s data
science toolkit is built, and learning NumPy is the first step on any Python data scientist’s
journey.
Benefits of NumPy:
 More Speed: NumPy uses algorithms written in C that complete in nanoseconds
rather than seconds.
 Fewer Loops: NumPy helps you to reduce loops and keep from getting tangled up
in iteration indices.
 Clearer code: Without loops, your code will look more like the equations you’re
trying to calculate.
 Better quality: There are thousands of contributors working to keep NumPy fast,
friendly, and bug free.

Dept of CS&E, JNNCE, Shivamogga Page 11


Deep Learning using PyTorch for Fall Detection

Deep Learning framework


A deep learning framework is an interface, library or a tool which allows us to build
deeplearning models more easily and quickly, without getting into the details of underlying
algorithms. They provide a clear and concise way for defining models using a collection of
pre-built and optimized components. Top 5 deep learning framework are TensorFlow,
Keras, PyTorch, Caffe, and Deeplearning4j.
Key features of good deep learning framework:
 Optimized for performance
 Easy to understand and code
 Good community support
 Parallelize the processes to reduce computation
 Automatically compute gradients

CNN
A convolutional neural network (CNN or convnet) is a subset of machine learning. It
is one of the various types of artificial neural networks which are used for different
applications and data types. A CNN is a kind of network architecture for deep learning
algorithms and is specifically used for image recognition and tasks that involve the processing
of pixel data. There are other types of neural networks in deep learning, but for identifying
and recognizing objects, CNNs are the network architecture of choice. This makes them
highly suitable for computer vision (CV) tasks and for applications where object recognition
is vital, such as self- driving cars and facial recognition.

Soft Skills
The following soft skills were acquired during four weeks of internship.

 Time Management: Time management skills are those that help us use our time
effectively and achieve desired results. Time management skills can help you
allocate your time properly and accomplish tasks efficiently. Important skills related
to successful time management skills include Organization, prioritization, Goal
setting, Communication, Planning, Delegation, Stress management.
 Personality Development: Personality development refers to how the organized

Dept of CS&E, JNNCE, Shivamogga Page 12


Deep Learning using PyTorch for Fall Detection
patterns of behavior that make up each person’s unique personality emerge over
time. Many factors go into influencing personality, including genetics, environment,
parenting, and societal variables. Perhaps most importantly, it is the ongoing
interaction of all of these influences that continue to shape personality over time.
 Communication: Effective Communication is significant for managers in the
organizations so as to perform the basic functions of management, i.e., Planning,
Organizing, Leading, and Controlling. Communication helps managers to perform
their jobs and responsibilities. Communication serves as a foundation for planning.
All the essential information must be communicated to the managers who in turn
must communicate the plans so as to implement them.
 Problem-Solving skills: Problem-solving skills allow us to find candidates who are
cognitively equipped to handle anything their jobs throw at them. Problem solvers
can observe, judge, and act quickly when difficulties arise when they inevitably do.
 Work ethics: Employees who are ethically positive, honest, hardworking, and driven
by principles of fairness and decency in the workplace, increase the overall morale
and enhance the performance of an organization. A company that has established
behavioral policies can improve its reputation and help ensure its long- term
success.
 Adaptability Skills: Adaptability expands our capacity to handle change, no matter
how serious it might be. Instead of throwing away our energy trying to change our
circumstances, we will change ourselves right from within, thus making us thrive
in whatever situation we find yourself.

Experiences
From my internship at Ekathva innovations, I was able to get a better understanding of
technical skills. The lessons that I have learnt from my supervisor and cooperating mentors
have made be confident that I will continue to grow and develop professionally and in my
personal endeavors. I learnt about many trending topics of which industries are using in a
very efficient way. I enjoyed implementing those skills that I have learnt and that has
boosted my confidence to work on projects individually. Overall, I found my internship
experience to be positive, and I’m sure I will be able to use the skills I learned in my career
later.

Dept of CS&E, JNNCE, Shivamogga Page 13


Deep Learning using PyTorch for Fall Detection

Chapter 4
REFLECTION NOTES

Assignments
List of assignments:
1. Write python program to convert phone number to word but while converting repeated
like 2 or 3 should be converted to double or triple. Example phone number 9900923050
should be converted as double nine double zero two three zero five zero.
ph_no=input("Enter phone number:")
if(len(ph_no)!=10):
print("Please enter 10 digits")
else:
d=1
k=0
for i in range(10):
if(k>0 or k>1):
k=k-1
continue

if(i<=8):
while(ph_no[i]==ph_no[i+1]):
d=d+1
k=k+1

if(i<8):
i=i+1
else:
break
while(d>3):
d=d-1
k=k-1
if(d==2):
print("Double",end=" ")
d=1

if(d==3):
print("Triple",end=" ")
d=1

if(ph_no[i]=="1"):
print("one",end=" ")

if(ph_no[i]=="2"):
print("two",end=" ")
if(ph_no[i]=="3"):

Dept of CS&E, JNNCE, Shivamogga Page 14


Deep Learning using PyTorch for Fall Detection

print("three",end=" ")
if(ph_no[i]=="4"):
print("four",end=" ")
if(ph_no[i]=="5"):
print("five",end=" ")
if(ph_no[i]=="6"):
print("six",end=" ")
if(ph_no[i]=="7"):
print("seven",end=" ")
if(ph_no[i]=="8"):
print("eight",end=" ")
if(ph_no[i]=="9"):
print("nine",end=" ")
if(ph_no[i]=="0"):
print("zero",end=" ")

Output:

Enter phone number:6678733367


Double six seven eight seven Triple three six seven

2. Write a class neural network and instantiate with attributes number of inputs, number of
outputs and number of outputs. Define a method model with parameters with weights and
bias and return inputs*weights + bias. Instantiate this class with at least 3 objects.

class neuralNetwork:
numer_of_inputs=0
number_of_outputs=0

def init (self,numer_of_inputs,number_of_outputs):


self.numer_of_inputs=numer_of_inputs
self.number_of_outputs=number_of_outputs

def model(self,weigths,bais):
return self.numer_of_inputs*weigths+bais

obj1=neuralNetwork(10,10)
obj2=neuralNetwork(20,20)
obj3=neuralNetwork(30,30)

print(obj1.model(15,7))
print(obj2.model(10,8))
print(obj3.model(12,6

Dept of CS&E, JNNCE, Shivamogga Page 15


Deep Learning using PyTorch for Fall Detection
Output:
157
208
366

3. Create a one dimensional numpy array [10,9,-2,3,16,2,11] and compute median of the
same using various numpy functions. Don’t use any loops.

import numpy as np
arr=np.array([10,9,2,3,16,2,11)
med=np.median (arr)
print(med)

Output:
9.0

4. Create a matrix: A= [[1 4 3] [ 2 1 6] [ 4 2 3]] find its determinant in numpy using

indexing and slicing.

import numpy as np
arr=np.array([1,4,3,2,1,6,4,2,3]).reshape(3,3)
d=((arr[0][0])*((arr[1][1]*arr[2][2])-(arr[1][2]*arr[2][1])))
d-=((arr[0][1])*((arr[1][0]*arr[2][2])-(arr[1][2]*arr[2][0])))
d+=((arr[0][2])*((arr[1][0]*arr[2][1])-(arr[1][1]*arr[2][0])))
print(d)

Output:
63

5. Create a uniformly spaced array of 24 elements from 5 to 60. Reshape to 4X6. Create a

mask for divisible by 3 and display masked elements.


U=np.linspace(5,60,24,dtype=int)
print(U)
R=U.reshape(4,6)
mask=R%3==0
print("Masked elements are:")
print(R[mask])

Output:
Uniformly spaced array elements are :
[ 5 7 9 12 14 16 19 21 24 26 28 31 33 36 38 40 43 45 48 50 52 55 57 60]
[[False False True True False False]
[False True True False False False]
[ True True False False False True]
[ True False False False True True]]
Masked elements are : [ 9 12 21 24 33 36 45 48 57 60]

Dept of CS&E, JNNCE, Shivamogga Page 16


Deep Learning using PyTorch for Fall Detection

6. Implement following Taylor series:

Also find its derivative for x=[-3,-2,-1,0,1,2,3] and plot graphs of X vs f(X) and X vs f’(X)

!pip3 install matplotlib


!pip install
d2l import
torch
fac=torch.jit.builtins.math.factorial
def f_x(x,terms):
j=torch.arange(terms) for k
in j:
res=torch.sum(x**(2*k)/fac(k)) return res
def diff_fx(x,terms):
i=torch.arange(terms)
for k in i:
difr=torch.sum(2*k*(x**(2*k-1))/fac(k)) return difr
x=torch.Tensor([-3,-2,-1,0,1,2,3])
A=torch.Tensor([f_x(-3,5),f_x(-2,5),f_x(-1,5),f_x(0,5),f_x(1,5),f_x(2,5),f_x(3,5)])
D=torch.Tensor([diff_fx(-3,5),diff_fx(-2,5),diff_fx(-1,5),diff_fx(0,5),diff_fx(1,5),diff_fx(2,5),diff_fx(3,5)])
A, D

!pip3 install matplotlib


%matplotlib inline
import torch
from d2l import torch as d2l
d2l.use_svg_display()
d2l.set_figsize(figsize=(3.5,3.0))
d2l.plt.xlabel('X')
d2l.plt.ylabel("f(X)")
d2l.plt.title("X vs f(X)")
d2l.plt.plot(x,A)
!pip3 install matplotlib
%matplotlib inline
import torch
from d2l import torch as d2l d2l.use_svg_display()
d2l.set_figsize(figsize=(3.5,3.0))
d2l.plt.xlabel('X')
d2l.plt.ylabel("f'(X)")
d2l.plt.title("X vs f'(X)")
d2l.plt.plot(x,D)

Dept of CS&E, JNNCE, Shivamogga Page 17


Deep Learning using PyTorch for Fall Detection

Output:

Fig 4.1 Output of practice code 6

7. Download lena.jpg from the class room and upload to Google colab. Then process the image
into a single torch variable. For each channel, find out the frequency of occurrence of each pixel
value and display 2 top pixels who has largest frequency of occurrence. [Use kornia] Where n -is
the number of pixels, p(xi) is pixel value of ith pixel

!pip install kornia

!pip install kornia-rs

import kornia as K

import cv2

import torch

import numpy as np

import matplotlib.pyplot as plt

img_tensor = K.io.load_image("/content/sample_data/lena_color.tiff", K.io.ImageLoadType.RGB32,


device="cpu")

tensor_image = img_tensor.float()

num_channels, height, width = tensor_image.shape

pixel_frequencies = []

for channel_idx in range(num_channels):

channel = tensor_image[channel_idx]

frequencies = torch.bincount(channel.view(-1).long(), minlength=256)

pixel_frequencies.append(frequencies)

for channel_idx in range(len(pixel_frequencies)):

frequencies = pixel_frequencies[channel_idx]

Dept of CS&E, JNNCE, Shivamogga Page 18


Deep Learning using PyTorch for Fall Detection

top_indices = torch.argsort(frequencies, descending=True)[:5]

print(f"Channel {channel_idx + 1}: Top 5 Pixel Values:")

for idx in top_indices:

print(f"Pixel Value {idx}: ")

print(f"Frequency {frequencies[idx]}")

Output:
Channel 1: Top 5 Pixel Values:
Pixel Value 0:
Frequency 262032
Pixel Value 1:
Frequency 112
Pixel Value 175:
Frequency 0
Pixel Value 161:
Frequency 0
Pixel Value 174:
Frequency 0
Channel 2: Top 5 Pixel Values:
Pixel Value 0:
Frequency 262144
Pixel Value 175:
Frequency 0
Pixel Value 161:
Frequency 0
Pixel Value 174:
Frequency 0
Pixel Value 173:
Frequency 0

8. Create a batch of 3 flower images (download flower images from internet) and report which
image has highest normalization range
import cv2
import numpy as np
image_paths = ['/content/sample_data/i1.jpg', '/content/sample_data/i2.jpg', '/content/sample_data/i3.jpg']
max_range = -1
max_range_image = None
for image_path in image_paths:
image = cv2.imread(image_path)
image = image.astype(np.float32) / 255.0
channel_ranges = np.ptp(image, axis=(0, 1))

total_range = np.sum(channel_ranges)
if total_range > max_range:
max_range = total_range
max_range_image = image_path
print(f"The image with the highest normalization range is {max_range_image} with a total range of
{max_range:.4f}.")

Output:
The image with the highest normalization range is /content/sample_data/i1.jpg with a total range of
3.0000.

Dept. of CS&E, JNNCE, Shivamogga


Page 19
Deep Learning using PyTorch for Fall Detection

Project Overview

What we are going to do here is just one alternative which we can categorize as a vision-
based fall detection system. The objective is to build model which is able to detect falls from
just a simple plain video. The most of this project is based on and credited to this paper, Real-
time Vision-based Fall Detection with Motion History Images and Convolutional Neural
Networks.
CNN MODEL:
A Convolutional Neural Network (CNN) is a type of deep learning architecture
commonly used for tasks involving image recognition, classification, and segmentation.
CNNs use convolutional layers to extract features from input images. A CNN model
consists of convolutional layer, pooling layer and fully connected layer.
 Convolutional Layers: Convolutional layers, the fundamental components of CNNs,
utilize learnable filters (kernels) to extract features from input images, detecting patterns
like edges, textures, or shapes.
 Pooling Layers: Pooling layers are commonly employed following convolutional
layers to decrease spatial dimensions and computational complexity. By employing
operations such as max-pooling or average-pooling, pooling layers aggregate information
from neighboring pixels.
 Fully Connected Layers: Fully connected layers serve as traditional neural network
layers in which each neuron is interconnected with every neuron in the preceding and
succeeding layers. These layers play a crucial role in taking the high-level featuresextracted
by convolutional and pooling layers and mapping them to the desired output classes.
As depicted in the figure 4.2, a Convolutional Neural Network (CNN) with three
layers illustrates the sequential flow of operations crucial for image analysis and
classification. The initial convolutional layer employs learnable filters to extract intricate
patterns like edges, textures, and shapes from the input image. Following this, a pooling
layer reduces the spatial dimensions and computational complexity by aggregating
information from neighboring pixels through operations such as max-pooling or average-
pooling. Finally, the fully connected layer serves as the core of classification, where
high-level features gleaned from previous layers are mapped to the desired output

classes. This streamlined architecture captures the essence of feature extraction, spatial

Dept. of CS&E, JNNCE, Shivamogga


Page 20
Deep Learning using PyTorch for Fall Detection

reduction, and classification, essential for effective image recognition and segmentation
tasks in CNNs.

Fig 4.2 Diagram of CNN

Implementation

The implementation steps for the Fall Detection in Deep Learning in PyTorch are as
follows:
1. Dataset Creation and Preprocessing:
The process begins with loading the dataset comprising images that exhibit various
images. These images may be sourced from diverse sources, like Kaggle/Github. Once
the dataset undergoes preprocessing to extract relevant image features.

Create Dataset
data_dir = f'{root}/dataset'
batch_size = 32

transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(), # convert 1 to 3 channels
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

train_dataset = datasets.ImageFolder(f'{data_dir}/train', transform=transform)

train_dataloader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size,

Dept. of CS&E, JNNCE, Shivamogga


Page 21
Deep Learning using PyTorch for Fall Detection
shuffle=True)

Dept. of CS&E, JNNCE, Shivamogga


Page 22
Deep Learning using PyTorch for Fall Detection

train_sizes = len(train_dataset)
class_names = train_dataset.classes

val_dataset = datasets.ImageFolder(f'{data_dir}/val', transform)

val_dataloader = torch.utils.data.DataLoader(val_dataset, batch_size=batch_size)

val_sizes = len(val_dataset)

Create Model
class FDNet(nn.Module):
def _init_(self, out_features=2):
super(FDNet, self)._init_()
mnet = models.mobilenet_v2(pretrained=True)
for name, param in mnet.named_parameters():
if("bn" not in name):
param.requires_grad_(False)

in_features = mnet.classifier[1].in_features
mnet.classifier = nn.Sequential(
nn.Dropout(p=0.2, inplace=False),
nn.Linear(in_features,500),
nn.ReLU(),
nn.Dropout(),
nn.Linear(500, out_features))
self.mnet = mnet

def forward(self, images):


features = self.mnet(images)

return features

2. Dataset Splitting:
The dataset is split into training and testing datasets at the time of downloading the
dataset from Kaggle/Github.

Dept. of CS&E, JNNCE, Shivamogga


Page 23
Deep Learning using PyTorch for Fall Detection

3. Model Training:
For Fall Detection classification, a Convolutional Neural Network (CNN)
architecture is selected due to its effectiveness in extracting hierarchical features from
images. The CNN comprises multiple layers, including convolutional, pooling, and fully
connected layers, which collectively learn discriminative representations from the input
images. During training, the model learns to optimize its parameters by iteratively
adjusting them to minimize a predefined loss function, typically using techniques like
backpropagation and gradient descent.

def train(model, optimizer, loss_fn, train_loader, val_loader, start_epoch = 0, epochs=20,


device="cpu"):
model.to(device)
for epoch in range(start_epoch, start_epoch+epochs):
training_loss = 0.0
valid_loss = 0.0
model.train()
for batch in train_loader:
optimizer.zero_grad()
inputs, targets = batch
inputs = inputs.to(device)
targets = targets.to(device)
output = model(inputs)
loss = loss_fn(output, targets)
loss.backward()
optimizer.step()
training_loss += loss.data.item() * inputs.size(0)
training_loss /= len(train_loader.dataset)

model.eval()
num_correct = 0
num_examples = 0
for batch in val_loader:
inputs, targets = batch
inputs = inputs.to(device)
output = model(inputs)
targets = targets.to(device)
loss = loss_fn(output,targets)

Dept. of CS&E, JNNCE, Shivamogga


Page 24
Deep Learning using PyTorch for Fall Detection

valid_loss += loss.data.item() * inputs.size(0)


correct = torch.eq(torch.max(F.softmax(output, dim=1), dim=1)[1], targets).view(-1)
num_correct += torch.sum(correct).item()
num_examples += correct.shape[0]
valid_loss /= len(val_loader.dataset)

print('Epoch: {}, Training Loss: {:.2f}, Validation Loss: {:.2f}, accuracy = {:.2f}'.format(epoch,
training_loss,
valid_loss, num_correct / num_examples))

4. Model Evaluation:
Following the training phase, the performance of the trained model is evaluated
using the testing dataset. The testing dataset contains unseen data samples that were not
used during training, providing an unbiased assessment of the model's generalization
ability. The model's predictions on the testing dataset are compared against the ground
truth labels to assess its accuracy and effectiveness in identifying vegetable features.

test_dataset = datasets.ImageFolder(f'{data_dir}/test', transform)

test_dataloader = torch.utils.data.DataLoader(test_dataset, batch_size=batch_size)

test_sizes = len(test_dataset)

4. Accuracy Calculation:
The accuracy of the trained model is calculated by determining the ratio of correctly
classified samples to the total number of samples in the testing dataset. This metric
provides a quantitative measure of the model's performance in accurately identifying
different levels of Fall Detection based on the extracted facial features. A higher
accuracy indicates a more reliable and effective drowsiness detection model, capable of
making accurate predictions in real-world scenarios.

outputs_np = np.empty((0), dtype=int)


targets_np = np.empty((0), dtype=int)

Dept. of CS&E, JNNCE, Shivamogga


Page 25
Deep Learning using PyTorch for Fall Detection

model.eval()
num_correct = 0
num_examples = 0
for batch in test_dataloader:
inputs, targets = batch
inputs = inputs.to(device)
outputs = model(inputs)
outputs = torch.max(F.softmax(outputs, dim=1), dim=1)[1]
targets = targets.to(device)
correct = torch.eq(outputs, targets).view(-1)
num_correct += torch.sum(correct).item()
num_examples += correct.shape[0]

outputs_np = np.concatenate([outputs_np, outputs.cpu().numpy()], axis=None)


targets_np = np.concatenate([targets_np, targets.cpu().numpy()], axis=None)

print(f'Accuracy: {num_correct / num_examples:.2f}')


print(num_correct, num_examples)

Results and Analysis

Fig 4.4.1 Snapshot of Accuracy of Fall Detection

Dept. of CS&E, JNNCE, Shivamogga


Page 26
Deep Learning using PyTorch for Fall Detection

Fig 4.4 Snapshot of Output of the project

Fig 4.4 Visualization of the Output

Dept. of CS&E, JNNCE, Shivamogga


Page 27
Deep Learning using PyTorch for Fall Detection

The model was trained and evaluated using large dataset of images. The dataset was
categorised into training and testing datasets. The Convolution Neural Network (CNN) was
finely-tuned on the datasets using techniques of Deep Learning. The layers of the model were
trained using datasets.

Dept. of CS&E, JNNCE, Shivamogga


Page 28
Deep Learning using PyTorch for Fall Detection

Chapter 5
CONCLUSION

Fall detection is a major concern among healthcare sector since it leads to both physical and
metal damage to people, especially the elderly. As our society is turning into aging society, it is
becoming even more concerned. Today, to prevent it, there are many technologies being
developed. In conclusion, AIML-based human fall detection represents a significant step
forward in ensuring the safety and well-being of individuals. Through innovation, collaboration,
and a commitment to leveraging technology for good, we have developed a solution that has the
potential to positively impact lives and communities around the world. As we look to the future,
the potential applications of AIML-based fall detection are vast and diverse. From elderly care
to industrial safety, there exists a wide range of scenarios where our system can make a
meaningful impact in preventing accidents and saving lives.

Dept. of CS&E, JNNCE, Shivamogga


Page 29
Deep Learning using PyTorch for classifying vegetables

BIBLIOGRAPHY

[1] https://numpy.org
[2] https://pytorch.org
[3] https://numpy.org/learn
[4] https://web.mit.edu/dvp/Public/numpybook.pdf
[5] https://isip.piconepress.com/courses/temple/ece_4822/resources/books/Deep-Learning-with-
PyTorch.pdf
[6] https://github.com/nithiroj/Fall-Detection-PyTorch.git

Dept. of CS&E, JNNCE, Shivamogga Page 27

You might also like