Internship Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Internship Report

Contents
Installing Miniconda .............................................................................................................................................. 3
Downloading and Installing: .............................................................................................................................. 3
Run the Miniconda installer .............................................................................................................................. 3
Jupyter Notebook: ............................................................................................................................................. 5
Learning python..................................................................................................................................................... 7
Using Simplilearn: .............................................................................................................................................. 7
Topics: ................................................................................................................................................................ 7
Python Tasks .......................................................................................................................................................... 8
Scientific calculator using Python: ..................................................................................................................... 8
Checking number in List: ................................................................................................................................. 12
Hangman Game: .............................................................................................................................................. 12
Searching in list: ............................................................................................................................................... 14
Shopping Cart: ................................................................................................................................................. 14
User Data base using python: .......................................................................................................................... 18
Installation Raspberry pi OS: ............................................................................................................................... 22
Raspberry pi 4 specifications: .......................................................................................................................... 22
Installation of Raspbian operating system: ..................................................................................................... 23
Connecting Raspberry pi to laptop: ................................................................................................................. 24
Putty: ............................................................................................................................................................... 25
VNC Viewer: ..................................................................................................................................................... 27
Final Project ......................................................................................................................................................... 28
Object Detection:............................................................................................................................................. 28
Introduction: .................................................................................................................................................... 28
Importance: ..................................................................................................................................................... 28
Components used in Project: .......................................................................................................................... 28
Working on Project: ......................................................................................................................................... 28
Setup Virtual Env ............................................................................................................................................. 30
Installing tensorflow lite in python 3: .............................................................................................................. 31
Use Cases of TensorFlow Mobile .................................................................................................................. 31
Running Project: .............................................................................................................................................. 32
Installing Miniconda

Downloading and Installing:


First, download Miniconda from Anaconda, Inc. You want one for “Python 3.something,” not “Python
2.something.”

Run the Miniconda installer


Double-click the “.exe” file to run setup. Click “Next,” then click “I Agree” on the following
screen.
Jupyter Notebook:
To install the Jupyter notebook software. Open command prompt and type the below code:

>pip install jupyter


When installation is complete, let's run the Jupyter Notebook web application. To do this, you
need to go to a cmd prompt and execute this command

>Jupyter notebook

As soon as you hit the above command button, It will open a browser with jupyter notebook

Let's write hello world program in the Jupyter notebook. The browser will look like

➢ print('Hello world')
Learning python

Using Simplilearn:
04 – 11 July 2022 Learning Python Week 1
12 - 19 July 2022 Learning Python week 2
20- 27July, 2022 Learning python Week 3

Topics:
The topics covered are :

• Top 10 Reason Why You Should Learn Python

• Tips for Learning Python

• Install Python on Windows

• Python IDEs

• Python Variables

• Python Numbers
• Python Strings

• Python If-Else Statement

• Python Loops

• Python For Loops

• Python While Loop

• Python Arrays

• Python List

• Python Sets and Dictionaries

• Python Tuples

• Python Slicing

• Python Regular Expression (RegEX)

• Python Functions

• Objects and Classes in Python

• Python OOPs Concept

Python Tasks

Scientific calculator using Python:


Code:

import math

#for selecting the opertions

operation=float( input ("select the operation you want to do \n1.addition\n 2.subtraction \n


3.multiplication \n 4.division \n 5.Square root \n 6.Cos(0) \n 7.Sin(0) \n 8.tan(0)\n 9.sec0 \n 10.Cosec0 \n
11.cotan0 \n"))

#we can use if else ledder


# For Addition

if (operation==1):

num1=float(input("\n enter the 1st number"))

num2=float(input("\nenter the 2nd number"))

print("the addition is:",str(num1+num2))

# For Subtraction

elif (operation==2):

num1=float(input("\n enter the 1st number"))

num2=float(input("\nenter the 2nd number"))

print("\t the subtraction is :",str (num1-num2))

# For Multiplication

elif (operation==3):

num1=float(input("\n enter the 1st number"))

num2=float(input("\nenter the 2nd number"))

print("\t the multiplication is :", str (num1*num2))

# For Division

elif (operation==4):

num1=float(input("\n enter the 1st number"))

num2=float(input("\nenter the 2nd number"))

print("\t the division is :",str(num1/num2))


# For Square root

elif(operation==5):

num1=float(input("\n enter the 1st number"))

print("\t the square root is :",str(math.sqrt(num1)))

# For Cos0

elif(operation==6):

num1=float(input("\n enter the number"))

print("\t the cos of the given number is :",math.cos(num1))

# For Sin0

elif(operation==7):

num1=float(input("\n enter the number"))

print("\t the sin of the given number is :",math.sin(num1))

# For Tan0

elif(operation==8):

num1=float(input("\n enter the number"))

print("\t the tan of the given number is :",math.tan(num1))

elif(operation==9):

num1=float(input("\n enter the number"))

print("\t the acos of the given number is :",math.acos(num1))

# For Sin0

elif(operation==10):
num1=float(input("\n enter the number"))

print("\t the cos of the given number is :",math.asin(num1))

# For Tan0

elif(operation==11):

num1=float(input("\n enter the number"))

print("\t the cos of the given number is :",math.atan(num1))

else:

print("invalid Option")

Output:
Checking number in List:
Code:

list=[1,8,9,7,6,2,7,88,5,48,65,25,58,96]

check=input("enter the value")

if check in list:

print("present in the list")

else:

print("number not found")

Output:

Hangman Game:
Code:

import random

play = True

while play:

Name = input("enter your name ")

print("good luck",Name)

list = ["Jamal","Kamal","Fawad","Haseeb","Hassan","Abdullah","Ahmad","Awab","Uzair","Shahzaib"

"Usama","Asim", "Umar","Saqib","Uzair","Ali","Usman","Suleiman",

"Furqan","Waqas","Samee","Annus","ateeq","arbab","waheed","usama","mohib","umair",

"haris","mubeen","ismail", "hamza","luqman","imran"]

words = random.sample(list,10)
word = random.choice(words)

print(word)

print("this is the list you have to guess any word from these words")

print(words)

life = 3

while life > 0:

guess = input("enter the word that i have choose\n")

print(guess)

if word == guess:

print("you guess the word correctly")

break

elif word != guess:

print("sorry you entered the wrong guess")

print("you also lose a life",life)

life = life - 1

if life == 0:

print("SORRY you failed")

again = str(input("if you dont want to play enter no or press any key and enter "))

if again == "no":

play = False

Output:
Searching in list:
code

list=[]

for numbers in range(500,1000):

if numbers%3 == 0 and numbers%2!=0:

list.append(numbers)

print(list)

Output:

Shopping Cart:
Code:

def start():
while True:

print()

print('''

Select a number for the action that you would like to do:

1. View shopping list

2. Add item to shopping list

3. Remove item from shopping list

4. Clear shopping list

5. Exit

''')

selection = input("Make your selection: ")

if selection == "1":

displayList()

elif selection == "2":

addItem()

elif selection == "3":

removeItem()

elif selection == "4":

clearList()

elif selection == "5":

sys.exit()

else:
print("You did not make a valid selection.")

shopping_list = []

def displayList():

print()

print("--- SHOPPING LIST ---")

for i in shopping_list:

print("* " + i)

def addItem():

item = input("Enter the item you wish to add to the shopping list: ")

shopping_list.append(item)

print(item + " has been added to the shopping list.")

def removeItem():

item = input("Enter the item you wish to remove from the shopping list: ")

shopping_list.remove(item)

print(item + " has been removed from the shopping list.")

def clearList():

shopping_list.clear()

print("The shopping list is now empty.")


start()

Output:
User Data base using python:
import csv

def register():

email = input("Please enter your email address: ")

password = input("Please enter the password: ")

password1 = input("Retype your password: ")

# now if both the passwords are equal then store password and email in file and make registration
successful.
if password == password1:

# fields = ["Email", "Password"]

reg = [email, password]

with open(r"C:\Users\Haseeb\Haseeb.csv", "a", newline="") as _file:

csv_file = csv.writer(_file)

# csv_file.writerow(fields)

csv_file.writerow(reg)

print("Registration successful!!!")

with open(r"C:\Users\Haseeb\Haseeb.csv", "r") as File:

csvFile = csv.reader(File)

for lines in csvFile:

print(lines)

else:

print("Password Mismatch!!")

def login():

Email = input("Please enter your registered email: ")

Password = input("Please enter your password: ")

with open(r"C:\Users\Haseeb\Haseeb.csv", "r") as _File:

_csvFile = csv.reader(_File)

for lines in _csvFile:

if lines == [Email, Password]:

# print(lines)

print("You are logged in : ")

return True
# IsCreated = False

while True:

# check if the user is logged in or not:

print("Checking if the user is already logged in or not: ")

# ans = checklogin()

ans = login()

if ans == True:

print("1. Log out")

print("2. Quit")

option = input("Select the any function from above options: ")

if option in ('1', '2'):

if option == '1':

print("Successfully Logged out!!")

elif option == '2':

print("Thank you for your time!")

break

else:

print("Invalid choice! Enter the correct option. Thanks")

else:

print("Not logged in: ")

while True:

print("1. login")

print("2. Registration")

print("3. Quit")

choice = input("As you are not logged in. So, choose one of the above functions: ")

if choice in ('1', '2', '3'):

if choice == '1':
login()

elif choice == '2':

register()

elif choice == '3':

print("Thank you for your time!")

break

else:

print("Invalid choice! Enter the correct option. Thanks")

Output:
Installation Raspberry pi OS:

Raspberry pi 4 specifications:
• Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz
• 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM (depending on model)
• 2.4 GHz and 5.0 GHz IEEE 802.11ac wireless, Bluetooth 5.0, BLE
• Gigabit Ethernet
• 2 USB 3.0 ports; 2 USB 2.0 ports.
• Raspberry Pi standard 40 pin GPIO header (fully backwards compatible with previous
boards)
• 2 × micro-HDMI ports (up to 4kp60 supported)
• 2-lane MIPI DSI display port
• 2-lane MIPI CSI camera port
• 4-pole stereo audio and composite video port
• H.265 (4kp60 decode), H264 (1080p60 decode, 1080p30 encode)
• OpenGL ES 3.1, Vulkan 1.0
• Micro-SD card slot for loading operating system and data storage
• 5V DC via USB-C connector (minimum 3A*)
• 5V DC via GPIO header (minimum 3A*)
• Power over Ethernet (PoE) enabled (requires separate PoE HAT)
• Operating temperature: 0 – 50 degrees C ambient

* A good quality 2.5A power supply can be used if downstream USB peripherals consume less
than 500mA in total.
Installation of Raspbian operating system:
⮚ Insert a microSD card in your laptop or desktop.
⮚ Download and install Raspberry Pi Imager.
⮚ Interface will be

⮚ Once installed, run the Raspberry Pi Imager program. Choose ‘Raspberry Pi OS (32 bit)’
from the OS menu.
⮚ We press ctrl+shift+X new menu will open to set the host name and enable SSH to
configure WIFI and then click save .

⮚ Click ‘Choose SD card’ and select your card from the menu.
⮚ Click Write. This process will take several minutes as Raspberry Pi Imager downloads
Raspberry Pi OS and load it to microSD card.

Connecting Raspberry pi to laptop:


Firstly we will install Advance IP scanner , putty and VNC Viewer on laptop.
On Windows ,by connecting ethernet to laptop open the Network and Sharing Center
(Control Panel > Network and Sharing Center > View network connections).
Putty:
The interface of putty is

● By entering the hostname in the putty we will click on open to find our host device . click
open button to proceed.
● A login as: message will pop-up and asks you to enter your SSH username. However, for
shared hosting users, you will need to enter a predefined username. After entering your
username, press Enter.
● Type SSH password and press Enter again. For security reasons, the screen won’t show
the password but will register what you type.

● For enabling the server in Raspberry pi


Enter sudo raspi-config in terminating window. Set the hostname first
Then click on interfacing option and select SSH .give same SSH and password and given
while installing OS.
Select OK
Choose finish

VNC Viewer:
Then open VNC and connect to raspberrypi using ip address of raspberrypi we have found using previous
steps. The interface of vnc is shown below:
Final Project

Object Detection:
Introduction:
Object detection is a computer vision technique for locating instances of
objects in images or videos. Object detection algorithms typically leverage machine learning or
deep learning to produce meaningful results. When humans look at images or video, we can
recognize and locate objects of interest within a matter of moments. The goal of object detection
is to replicate this intelligence using a computer.

Importance:
Object detection is a key technology behind advanced driver assistance systems
(ADAS) that enable cars to detect driving lanes or perform pedestrian detection to improve road
safety. Object detection is also useful in applications such as video surveillance or image retrieval
systems.

Components used in Project:


➢ Raspberry pi 4
➢ Raspberry pi Camera
➢ Adafruit Cable

Working on Project:
Connecting Camera:
Connect your camera module to the CSI port on your Raspberry Pi;
this is the long thin port adjacent to the HDMI socket. Gently lift the collar on top of the
CSI port Slide the ribbon cable of the camera module into the port with the blue side
facing the Ethernet.

Once the cable is seated in the port, press the collar back down to lock the cable in place.
If done properly you should be able to easily lift the Pi by the camera’s cable without it
falling out.
Turn the Raspberry Pi on and launch the Raspberry Pi Software Configuration tool by typing the
following command:

>sudo raspi-config

Go to “Interface options” > “Camera”


• “Would you like the camera interface to be enabled?”
Yes!
• Exit raspi-config and accept the reboot

Setup Virtual Env


Checking version

python --version

Install venv - Python virtual environment module

"The venv module provides support for creating lightweight “virtual


environments” with their own site directories, optionally isolated from system
site directories. Each virtual environment has its own Python binary (which
matches the version of the binary that was used to create this environment)
and can have its own independent set of installed Python packages in its site
directories."

install the venv module for Python virtual environments


sudo apt-get install python3-venv

make directory

mkdir project

ls

cd project

python3 -m virtualenv env

source env/bin/activate

Install libraries:

python3 -m pip install "picamera[array]"

python3 -m pip install tflite-runtime

python3

Installing tensorflow lite in python 3:


What is Tensorflow lite ?

TensorFlow Lite is an open-source, product ready, cross-platform deep learning framework that converts a
pre-trained model in TensorFlow to a special format that can be optimized for speed or storage. The special
format model can be deployed on edge devices like mobiles using Android or iOS or Linux based embedded
devices like Raspberry Pi or Microcontrollers to make the inference at the Edge.

Use Cases of TensorFlow Mobile


The three main and important Use case of TensorFLow Mobile are as follows:

• Gesture Recognition in TensorFlow: It’s wont to control applications


or perform any special task supported by the hands or other gestures,
through analyzing sensor data.
• Image Recognition in TensorFlow: It’s used to detect or get a way of
the image captured with a mobile. If the users are taking photos to
understand some information that or want to use some effect (filters)
thereon then Images Recognition play the measure role to recognize
the Photo correctly. Example: Camera, Image Editor, etc.
• Speech Recognition in TensorFlow: Various applications related to
speech can build with a speech-driven interface using Tensorflow. To
Recognize the voice correctly Speech Recognition is Applies here.
There are many popular applications from which some that work on the
Speech Recognition System are Google Translate, Google
Assistant, etc.

Installing the tflite library:

import tflite_runtime

tflite_runtime._version_

Downloading the example file:

git clone https://github.com/tensorflow/examples --depth 1

Then use our script to install a couple Python packages, and download the TFLite model:

cd examples/lite/examples/image_classification/raspberry_pi

Running Project:
Targeting directory:

cd project
source env/bin/activete

cd examples/lite/examples/image_classification/raspberry_pi/

ls

python3 classify.py

Code:

import argparse

import sys

import time

import cv2

from tflite_support.task import core

from tflite_support.task import processor

from tflite_support.task import vision

# Visualization parameters

_ROW_SIZE = 20 # pixels

_LEFT_MARGIN = 24 # pixels
_TEXT_COLOR = (0, 0, 255) # red

_FONT_SIZE = 1

_FONT_THICKNESS = 1

_FPS_AVERAGE_FRAME_COUNT = 10

def run(model: str, max_results: int, score_threshold: float, num_threads: int,

enable_edgetpu: bool, camera_id: int, width: int, height: int) -> None:

"""Continuously run inference on images acquired from the camera.

Args:

model: Name of the TFLite image classification model.

max_results: Max of classification results.

score_threshold: The score threshold of classification results.

num_threads: Number of CPU threads to run the model.

enable_edgetpu: Whether to run the model on EdgeTPU.

camera_id: The camera id to be passed to OpenCV.

width: The width of the frame captured from the camera.

height: The height of the frame captured from the camera.

"""

# Initialize the image classification model

base_options = core.BaseOptions(

file_name=model, use_coral=enable_edgetpu, num_threads=num_threads)

# Enable Coral by this setting

classification_options = processor.ClassificationOptions(

max_results=max_results, score_threshold=score_threshold)
options = vision.ImageClassifierOptions(

base_options=base_options, classification_options=classification_options)

classifier = vision.ImageClassifier.create_from_options(options)

# Variables to calculate FPS

counter, fps = 0, 0

start_time = time.time()

# Start capturing video input from the camera

cap = cv2.VideoCapture(camera_id)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)

cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)

# Continuously capture images from the camera and run inference

while cap.isOpened():

success, image = cap.read()

if not success:

sys.exit(

'ERROR: Unable to read from webcam. Please verify your webcam settings.'

counter += 1

image = cv2.flip(image, 1)

# Convert the image from BGR to RGB as required by the TFLite model.

rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# Create TensorImage from the RGB image

tensor_image = vision.TensorImage.create_from_array(rgb_image)

# List classification results

categories = classifier.classify(tensor_image)

# Show classification results on the image

for idx, category in enumerate(categories.classifications[0].categories):

category_name = category.category_name

score = round(category.score, 2)

result_text = category_name + ' (' + str(score) + ')'

text_location = (_LEFT_MARGIN, (idx + 2) * _ROW_SIZE)

cv2.putText(image, result_text, text_location, cv2.FONT_HERSHEY_PLAIN,

_FONT_SIZE, _TEXT_COLOR, _FONT_THICKNESS)

# Calculate the FPS

if counter % _FPS_AVERAGE_FRAME_COUNT == 0:

end_time = time.time()

fps = _FPS_AVERAGE_FRAME_COUNT / (end_time - start_time)

start_time = time.time()

# Show the FPS

fps_text = 'FPS = ' + str(int(fps))

text_location = (_LEFT_MARGIN, _ROW_SIZE)

cv2.putText(image, fps_text, text_location, cv2.FONT_HERSHEY_PLAIN,

_FONT_SIZE, _TEXT_COLOR, _FONT_THICKNESS)

# Stop the program if the ESC key is pressed.

if cv2.waitKey(1) == 27:
break

cv2.imshow('image_classification', image)

cap.release()

cv2.destroyAllWindows()

def main():

parser = argparse.ArgumentParser(

formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument(

'--model',

help='Name of image classification model.',

required=False,

default='efficientnet_lite0.tflite')

parser.add_argument(

'--maxResults',

help='Max of classification results.',

required=False,

default=3)

parser.add_argument(

'--scoreThreshold',

help='The score threshold of classification results.',

required=False,

type=float,

default=0.0)

parser.add_argument(

'--numThreads',
help='Number of CPU threads to run the model.',

required=False,

default=4)

parser.add_argument(

'--enableEdgeTPU',

help='Whether to run the model on EdgeTPU.',

action='store_true',

required=False,

default=False)

parser.add_argument(

'--cameraId', help='Id of camera.', required=False, default=0)

parser.add_argument(

'--frameWidth',

help='Width of frame to capture from camera.',

required=False,

default=640)

parser.add_argument(

'--frameHeight',

help='Height of frame to capture from camera.',

required=False,

default=480)

args = parser.parse_args()

run(args.model, int(args.maxResults),

args.scoreThreshold, int(args.numThreads), bool(args.enableEdgeTPU),

int(args.cameraId), args.frameWidth, args.frameHeight)


if _name_ == '_main_':

main()

Laptop:

Mouse Computer Keyboard+


Conclusion:
After completing my Internship at SPCAI (Sino-Pak Centre of Artificial Intelligence) I am able to work on any
project on python. I worked of TensorFlow and learned lots of thing so I can work on image processing in
future in machine learning and deep learning.

References:

https://github.com/tensorflow/examples/tree/a9265a997d0410c431a292e3553646b3b655ea1f/lite/example
s/image_classification/raspberry_pi

https://www.tensorflow.org/

Thanks

You might also like