0% found this document useful (0 votes)
2K views49 pages

Blood Bank Management System

The document discusses requirements for developing an emotion detection system to help blind people understand others' emotions. It outlines the need to automate emotion recognition since blind individuals cannot rely on visual cues. The proposed system would use a single camera to detect facial expressions and provide output through vibration. It aims to address limitations of existing assistive technologies and improve independent living for the blind by helping them interpret emotions. Functional requirements include hardware, software, performance, safety, security and user needs. The system scope and context diagram are also defined to guide analysis and specification development.

Uploaded by

ahamed asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views49 pages

Blood Bank Management System

The document discusses requirements for developing an emotion detection system to help blind people understand others' emotions. It outlines the need to automate emotion recognition since blind individuals cannot rely on visual cues. The proposed system would use a single camera to detect facial expressions and provide output through vibration. It aims to address limitations of existing assistive technologies and improve independent living for the blind by helping them interpret emotions. Functional requirements include hardware, software, performance, safety, security and user needs. The system scope and context diagram are also defined to guide analysis and specification development.

Uploaded by

ahamed asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 49

Ex No: 1 Task 1 - Software Requirement Specification (SRS)

Preparation
Blood Bank Management System
Aim:
To generate SRS document for blood bank management system using Rational
Requisite Pro.

SRS Generation for Blood Bnak Management System

1.0 Introduction
The population of the world is multiplying with each coming year and so are the diseases and
health issues. With an increase in the population there is an increase in the need of blood. The
growing population of the world results in a lot of potential blood donors. But in spite of this
not more than 10% of the total world population participates in blood donation. With the
growing population and the advancement in medical science the demand for blood has also
increased. Due to the lack of communication between the blood donors and the blood
recipients, most of the patients in need of blood do not get blood on time and hence lose their
lives. There is a dire need of synchronization between the blood donors and hospitals and the
blood banks. This improper management of blood leads to wastage of the available blood
inventory. Improper communication and synchronization between the blood banks and
hospitals leads to wastage of the blood available. These problems can be dealt with by
automating the existing manual blood bank management system. A high-end, efficient, highly
available and scalable system has to be developed to bridge the gap between the donors and the
recipients and to reduce the efforts required to search for blood donors.

1.1 Purpose
The purpose of the blood bank management system is to simplify and automate the process of
searching for blood in case of emergency and maintain the records of blood donors, recipients,
blood donation programs and blood stocks in the bank.

1.2 Scope
The system is used for maintaining all the process and activities of blood bank management
system. The system can be extended to be used for maintaining records of hospital, organ
donation and other similar sectors. While developing the system, there shall be space for further
modification. There shall be a proper documentation so that further enhancement becomes easy.
As a whole the system is focused to work with blood bank management system and on
additional modification it can be also used as management systems of similar organizations.
1.3 Definitions, Acronyms and the Abbreviations
• HTML - Markup Language used for creating web pages.
• HTTP - Hyper Text Transfer Protocol.
• CSS - Cascading Style Sheets
• JS - JavaScript
• BS - Bootstrap
• PHP - Hypertext Preprocessor
• MYSQL - Structured Query Language

1.4References
Vikas Kulshreshtha, Sharad Maheshwari. (2011).”Blood Bank Management Information System
in India”, International Journal of Engineering,1,2, 260-263.
Rational Unified Process, Best Practices for Software Development Teams. (2012). Core
Workflows Retrieved from www.ibm.com/developerworks/rational/.../1251_bestpractices
Noushin Ashrafi, & Hessam Ashrafi. (2008). Object Oriented Systems Analysis and Design,
Pearson Higher Ed USA.
Lions Blood Bank & Research Foundation. (2012). Retrieved from
http://www.lionsbloodbank.net/
Blood Bank India. (2012). Retrieved from http://www.bloodbankindia.net

1.5 Technology
The technologies used for the development of the system are as follows:
1. Operating System: windows 8
2. Database Management System: Mysql
3. Programming Language: Python
4. Web-framework: bootsrap
5. Browser: Mozilla Firefox, Chrome.

1.6 Tools
• Rational Rose tool (for developing UML Patterns)
• Ecclipse
• xampp

1.7 Overview
SRS includes two sections overall description and specific requirements - Overall description
will describe major role of the system components and inter-connections. Specific
requirements will describe roles & functions of the actors.
2.0 Overall Description

2.1 Product Perspective


The system that is going to be developed is Blood Bank Management System (BBMS). This is
a web-based database application system that is to be used by the blood banks or blood centers
as a means to advertise the national wide blood donation events to the public and at the same
time allow the public to make online reservation and request for the blood. The system keeps
the record of all the donors, recipients, blood donation programs, rejected bloods. For internal
works and activities intranet is used and for interaction with public internet is used. This
system also has the ability to keep track of the donor's donation records and the blood stock in
the blood bank. This project intends to computerize the blood and donor management system
in a blood bank in order to improve the record management efficiency due to the grown size of
records of data. This system helps the patient to receive blood as soon as possible.

2.2 Software Interface


Front end: HTML, CSS, JavaScript

• HTML: HTML is used to create and save web document. E.g. Notepad/Notepad++
• CSS : (Cascading Style Sheets) Create attractive Layout
• Bootstrap : responsive design mobile friendly site
• JavaScript: it is a programming language, commonly use with web browsers.

Back end: PHP, MySQL

• PHP: Hypertext Preprocessor (PHP) is a technology that allows software developers to create
dynamically generated web pages, in HTML, XML, or other document types, as per client
request. PHP is open source software.
• MySQL: MySql is a database, widely used for accessing querying, updating, and managing
data in databases.

2.3 Hardware Interface


The server can be accessed by the client systems. The client systems have access to the
database in the server.

2.4 System Functions


• It is more faster to recognize the person in the opposite of the blind people.

• It give the output through different vibration.

• It recognize the face expression give them the result as whether they are sad or happy.

• The product which identify the person and provided the person details saved in system
database
• The product is capable of distinguishing the four emotion such as tongue out, neutral,
happiness, sadness and surprise.

Add the eligible application information to the database.

2.5 User Characteristics


• Blind people - They are the people who desires to use this product to know how the people
react to his/her conversation between the people.

2.6 Constraints
• If the face is covered then camera doesn’t recognize the expression of the face.

• The should capture the image and express the facial expression through different vibration but
it may annoy them at sometimes.

• The user must be careful while using the product.

• Much care is required.

2.7 Use Case Model Description


The use case model is a representation of the interaction between the users and the system. It
captures the goals of the users and the responsibility of the system to the users. It is a special
flow of events through the system. Grouping of use cases can manages the complexities and
reduce the number of use cases in the package. The use case model describes the uses of the
system and shows the courses of events that can be performed. A use case is an interaction
between user and system; it captures the goals of the user and the responsibility of the system to
its users. It defines what happens in the system when the use case is performed.

2.8 Assumptions and Dependencies


• The blind people must have basic knowledge of the product.

• The blind people should know about how the product works in the real life .

Result:
Thus, the software requirements specification for Placement Prediction System was
studied.
Ex .No: 2 Task 2 – Analysis & Problem Definition

2.1 Analysis & Requirement Collection

AIM
 To analyze and design a system for Emotion Detection System.
 Requirement analysis and collection is performed by the following contents.

TABLE OF CONTENT
1. OVERVIEW
1.1 Current System
1.2 Limitations of the Current System
1.3 Proposed System
1.3.1 Objectives of the Proposed System
2. FUNCTIONAL REQUIREMENT
2.1 System Requirements
2.1.1 Scope & Boundary
2.1.2 Context Diagram
3. SOFTWARE REQUIREMENTS SPECIFICATION
3.1 Hardware Requirements
3.2 Software Requirements
4. PERFORMANCE REQUIREMENTS
5. SAFETY REQUIREMENTS
6. USER REQUIREMENTS
6.1 Security
7. CONSTRAINTS

1. OVERVIEW

To improve the ability of people who are blind or have significant visual impairments to
independently access and understand the emotions. We propose a new framework using a single
camera to detect and recognize expression and give vibration as an output. This project is design
to help for the blind people to detect the emotion feeling of the other people.The importance of
being able to see appears self-evident not just for expressing emotions but also for the perception
of the expression of an emotion. Yet, a blind person does not have this sense for understanding
and interpreting the emotions of a third party.They learn to modulate their expressions according
to the results they seek. It follows that sighted people develop a structure for expressing their
emotions that the blind, deprived of these training opportunities, cannot easily acquire, whence
their difficulties in correctly proportioning on demand the intensity of an emotion.
1.1 Current System
Camera-based analysis of text and documents Here they proposed a camera-based
assistive framework to help blind persons to read text labels from cylinder objects in their daily
life. First, the object is detected from the background or other surrounding objects in the camera
view by shaking the object. Then we propose a mosaic model to unwrap the text label on the
cylinder object surface and reconstruct the whole label for recognizing text information. This
model can handle cylinder objects in any orientations and scales. The text information is then
extracted from the unwrapped and flatted labels. The recognized text codes are then output to
blind users in speech. Experimental results demonstrate the efficiency and effectiveness of the
proposed framework from different cylinder objects with complex backgrounds.

1.2 Limitation of the Current System


The existing system has some limitations that said as follows:
 It only helps to read the text or object.
 It won’t recognize when the object is shaked
 It only give result when the object is ideal
 Take more time to give result

2.2Proposed System
As mentioned above the problems with non-consistent data formats and individual reporting,
they aim to build a system that is aimed at helps for the blind people to recognize the
expression.the problems visually impaired persons experience in their daily lives, is the inability
to see non-verbal cues of conversation partners. In this project, a wearable assistive technology is
presented and evaluated which supports visually impaired persons with the recognition of facial
expressions of emotions. The wearable assistive technology consists of a camera clipped on
spectacles, emotion recognition software, and a vibrotactile..The Emotional detection for blind
people , capable of distinguishing the four emotion such as tongue out, neutral, happiness,
sadness and surprise. It helps the blind people to know how the people react.

2.2Objectives of the Proposed System

 To reduce complexity error


 Maintain security
 Avoid redundancy
 Giving accurate result
 User friendly
 It also recognize the people if they are in distance.
 Give result as audio or by different vibration
2. FUNCTIONAL REQUIREMENTS

2.1 System Requirements


Front end
i.Blind user
 Haptic input
 Audio input
ii. camera
 capture image
iii. Vibrator
 It gives result by different vibration

Back end
Tensor flow
 Train-model
 Test-model
 Analyze-data
 Classify-known/unknown

2.1.1 Scope & Boundary


Generating the Emotional detection for blind people. Our project has a big scope to do. It will
help the blind people to recognize the expression of the other person who talk with him. Based
on the expression it will show the result as whether they are happy or sad. We can store
information of identified person and the details are saved in system database .The new faces can
also be added to the database.
2.1.2 Context Diagram

3. SOFTWARE REQUIREMENTS SPECIFICATION


3.1 Hardware Requirements
1. CPU:Raspberry pi Processor
2. Memory: 2 GB
3. Cache: 2 MB
3.2 Software Requirements
1. Operating System: Windows 7 or Higher
2. Front End: Spyder
3. Method of connecting: Bluetooth and WiFi

4. PERFORMANCE REQUIREMENTS
Some performance requirements identified is listed below:
 It has to load, within the Industry Standard time.
 It has to support up to single Blind Person.

5. SAFETY REQUIREMENTS
The database may get crashed at any certain time due to virus or operating system failure.
Therefore, it is required to take the database backup.

6. USER REQUIREMENTS
Application will be accessed through a browser interface. The interface would be viewed best
using 1024*768 and 800*600 pixels resolution setting. The software would be fully compatible
with Microsoft internet explorer for version 6 and above. No user would be able to access any
part of the application without logging on to the system.
Software quality attributes:
The quality of the system is maintained in such a way so that it can be very user friendly to all
the users.
The software quality attributes are assumed as under:
 Accurate and hence reliable.
 Secured
 Fast speed

6.1 Security
Some of the factors that are identified to protect the software from accidental or malicious
access, use, modification, destruction, or disclosure are described below. Keep specific log or
history data sets
Assign certain functions to different modules
 Restrict communications between some areas of the program
 Check data integrity for critical variables
 Later version of the software will incorporate encryption techniques in the user/license
authentication process.
 Communication needs to be restricted when the application is validating the user or
license.

7. CONSTRAINTS
The System is of relatively shorter development cycle, uncomplicated functions and no technical
bottlenecks. Thus, the economic requirement of the System’s development can be expected to be
low. User interface is only in English, no other languages are much available. User can login
only using their authenticated user name and password. The internet connection used by the
organization must surely have a speed of 1gbps or higher since the navigation between the
questions will be done in acceptable time limit.

Result:

Thus, the requirements are analyzed for Emotion detection for blind people.
2.2 Proposed Problem Definition

AIM
To analyze and propose a problem definition for emotional detection for blind people

Simple Problem Statement for emotional detection for blind people


Abstract
Independent travel is a well known challenge for blind or visually impaired persons and also
the increasing availability of cost efficiency, high performance and portable digital imaging
devices has created a tremendous opportunity for supplementing traditional scanning for
document image acquisition. We propose a camera based visual assistance framework for text
reading, motion of objects and the feelings of persons etc.. It converts into a voice output to
help blind peoples. Thus we propose this system from a single camera-captured image as well
as more number of frames and highlight some sample applications under development and
feasible ideas for future development.

Problem Statement
Visually impaired person are around 285 million people globally are visually
impaired with 39 million blind and 246 million with low vision. Approximately 90% of these
people live in developing countries and 82% of blind people are aged 50 and above. An
individual is identified by his/her face. Face being the most important part, used for
distinguishing a person from another. Each face has different features and have different
characteristics of its own. So, face recognition plays a vital role in human behavior. Being able
to recognize the emotions of the people they feel will drastically improve their comprehensive.
Detecting emotions using emotion detection API or algorithm and conveying the information
to them. This can be further improved by using scene detection, etc… Conveying the
information can be tricky part. Connecting the detection system to a walking stick connected
with a vibrator, but this can annoy them. So we can by using refreshable Braille display as an
alternative

PROCEDURE FOR DETAILED PROBLEM STATEMENT


Detailed Problem statement with 4 parts
Part 1: Target Audience and Organization which develops the project, Advantages, benefits
Part 2: Detailed explanation of Overall System and Individual modules

Part 3: Individual Modules and report generation, Platform, Hardware and Software
requirements, Budget and duration and human resources.
Part 4: Limitations of existing system and proposed system benefits and deviation. Risk
Analysis and Risk Management and Testing.
Problem Definition:
Our target audience are blind people who have to walk daily in public. The will have a drastic
impact in their daily life. This will help them convey the emotion of people without which they
cannot feel.
The system has 2 more main modules, the smart walking stick and camera. The camera
will record the emotions and send it to the walking stick.
The walking stick uses a vibrator motor and aurdino to receive the input from the
camera which uses Raspherrypi to process the data.
Using head piece to cinvey the information as audio data. And using vibrator sequence
to convey emotion and obstacle data. By using the vibrator motor,the continuous vibrate output
may annoy the user and there may be a time long without proper optimization. And we use
Braille display as the alternative.

Result:
Thus, the problem definition for placement prediction system is analyzed.
Ex. No: 3 Task 3 – Overall Design (Modeling Techniques)

Task 3.1 - Study Of Uml Diagrams

UMLDIAGRAMS:

Use Case Diagram

Class Diagram

Activity Diagram

Sequence Diagram

Result:
Thus, the UML diagrams was studied.
Task 3.2 – UML Modeling

UML MODELING FOR EMOTION DETECTION FOR BLIND PEOPLE


Aim:
To design a system for Emotion detection for Blind people

TABLE OF CONTENT

1. Introduction
2. Usecase diagram
3. ClassDiagram

1. INTRODUCTION

The Unified Modeling Language (UML) is a language for specifying, visualizing, constructing,
and documenting the artifacts of software systems, as well as for business modeling and other non-
software systems. UML is graphical notation for modeling various aspects of software systems. It offers
a set of notations and rules for using the same. The main task is to create a simple, well documented and
easy to understand software model for the people. The UML modeling consist of Use case Diagram,
Class Diagram, Activity Diagram, Sequence Diagram, Collaboration Diagram, PackageDiagram.

SOFTWAREREQURIEMENTS:

1. Lucid chart

HARDWAREREQURIMENTS:

1. 128MBRAM
2. Pentium IIIProcessor

2. USE CASEDIAGRAM DESCRIPTION

A use case diagram at its simplest is a representation of a user's interaction with the system and
depicting the specifications of a use case. A use case diagram can portray the different types of users of a
system and the various ways that they interact with the system. This type of diagram is typically used in
conjunction with the textual use case and will often be accompanied by other types of diagrams as well.
Use case diagrams graphically depict system behavior (use cases). These diagrams present a high level
view of how the system is used as viewed from an outsider’s (actor’s) perspective. The purpose of use
case diagram is used to gather requirements of system, to get an outside view of system, identify internal
and external factors influencing the system, show the interaction among therequirements.
USE CASEDIAGRAM
CLASSDIAGRAM
Class diagrams are used to describe the structure of the system in terms of classes. Class
diagrams describe the system in terms of objects, classes, attributes, operations, and their
association. The class diagram is a static diagram. It represents the static view of an application.
Class diagram is not only used for visualizing, describing and documenting different aspects
of a system but also for constructing executable code of the software application.

Description

A class in an object oriented system provides a crisp abstraction of welldefinedset of


responsibilities. The class diagram is a static diagram. It represents the static view of an application.
The purpose of the class diagram is to analysis and design of the static view of an application and
describes responsibilities of asystem.

In the above diagram, a class consists of three parts:

 Class Operations(Methods):

Operations are shown in the thirdPartition


 The return type of a method is shown after the colon at the end
of the methodsignature.
 The return type of the method parameters are shown after
thecolon following the parametername

 Dependency:
 Methods: Capture image(), Detect image(),Train model(),Test
model(),analyse-data(),Classify-known/unknown,get haptic
input(),get audio input()
 Exists between two classes if changes to the definition of one
may cause changes to theothers
 The relationship is displayed as a dashed line with an openarrow.
CLASSDIAGRAM
ACTIVITY DIAGARM

SEQUENCE DIAGARM
Task 3.3 System Design

EMOTION DETECTION FOR BLIND PEOPLE

Result:
Thus, the overall design for Emotion detection for blind people is analyzed.
Ex. No: 4 Task 4- Development Strategies (Implementation / Coding)

Task 4.1 – Module Descriptions

Module 1 -

Module 2 –

Module 3 -
Task 4.2 – User Interface Design

Functions names:

Function 1() -

Function 2() –

Function 3() -
Task 4.3– Coding

Coding:

import cv2
import label_image

size = 4

classifier = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')

webcam = cv2.VideoCapture(0) #Using default WebCam connected to the PC.

while True:
(rval, im) = webcam.read()
im=cv2.flip(im,1,0) #Flip to act as a mirror

mini = cv2.resize(im, (int(im.shape[1]/size), int(im.shape[0]/size)))

detect MultiScale / faces


faces = classifier.detectMultiScale(mini)

for f in faces:
(x, y, w, h) = [v * size for v in f] #Scale the shapesize backup
cv2.rectangle(im, (x,y), (x+w,y+h), (0,255,0), 4)

sub_face = im[y:y+h, x:x+w]

FaceFileName = "test.jpg"
cv2.imwrite(FaceFileName, sub_face)

text = label_image.main(FaceFileName)
text = text.title()
font = cv2.FONT_HERSHEY_TRIPLEX
cv2.putText(im, text,(x+w,y), font, 1, (0,0,255), 2)

cv2.imshow('Capture', im)
key = cv2.waitKey(10)
if key == 27:
break

import argparse
import collections
from datetime import datetime
import hashlib
import os.path
import random
import re
import sys
import tarfile

import numpy as np
from six.moves import urllib
import tensorflow as tf

from tensorflow.python.framework import graph_util


from tensorflow.python.framework import tensor_shape
from tensorflow.python.platform import gfile
from tensorflow.python.util import compat

FLAGS = None

MAX_NUM_IMAGES_PER_CLASS = 2 ** 27 - 1

def create_image_lists(image_dir, testing_percentage, validation_percentage):


if not gfile.Exists(image_dir):
tf.logging.error("Image directory '" + image_dir + "' not found.")
return None
result = collections.OrderedDict()
sub_dirs = [
os.path.join(image_dir,item)
for item in gfile.ListDirectory(image_dir)]
sub_dirs = sorted(item for item in sub_dirs
if gfile.IsDirectory(item))
for sub_dir in sub_dirs:
extensions = ['jpg', 'jpeg', 'JPG', 'JPEG']
file_list = []
dir_name = os.path.basename(sub_dir)
if dir_name == image_dir:
continue
tf.logging.info("Looking for images in '" + dir_name + "'")
for extension in extensions:
file_glob = os.path.join(image_dir, dir_name, '*.' + extension)
file_list.extend(gfile.Glob(file_glob))
if not file_list:
tf.logging.warning('No files found')
continue
if len(file_list) < 20:
tf.logging.warning(
'WARNING: Folder has less than 20 images, which may cause issues.')
elif len(file_list) > MAX_NUM_IMAGES_PER_CLASS:
tf.logging.warning(
'WARNING: Folder {} has more than {} images. Some images will '
'never be selected.'.format(dir_name, MAX_NUM_IMAGES_PER_CLASS))
label_name = re.sub(r'[^a-z0-9]+', ' ', dir_name.lower())
training_images = []
testing_images = []
validation_images = []
for file_name in file_list:
base_name = os.path.basename(file_name)

hash_name_hashed = hashlib.sha1(compat.as_bytes(hash_name)).hexdigest()
percentage_hash = ((int(hash_name_hashed, 16) %
(MAX_NUM_IMAGES_PER_CLASS + 1)) *
(100.0 / MAX_NUM_IMAGES_PER_CLASS))
if percentage_hash < validation_percentage:
validation_images.append(base_name)
elif percentage_hash < (testing_percentage + validation_percentage):
testing_images.append(base_name)
else:
training_images.append(base_name)
result[label_name] = {
'dir': dir_name,
'training': training_images,
'testing': testing_images,
'validation': validation_images,
}
return result

def get_image_path(image_lists, label_name, index, image_dir, category):

if label_name not in image_lists:


tf.logging.fatal('Label does not exist %s.', label_name)
label_lists = image_lists[label_name]
if category not in label_lists:
tf.logging.fatal('Category does not exist %s.', category)
category_list = label_lists[category]
if not category_list:
tf.logging.fatal('Label %s has no images in the category %s.',
label_name, category)
mod_index = index % len(category_list)
base_name = category_list[mod_index]
sub_dir = label_lists['dir']
full_path = os.path.join(image_dir, sub_dir, base_name)
return full_path

def get_bottleneck_path(image_lists, label_name, index, bottleneck_dir,


category, architecture):

return get_image_path(image_lists, label_name, index, bottleneck_dir,


category) + '_' + architecture + '.txt'

def create_model_graph(model_info):
with tf.Graph().as_default() as graph:
model_path = os.path.join(FLAGS.model_dir, model_info['model_file_name'])
with gfile.FastGFile(model_path, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
bottleneck_tensor, resized_input_tensor = (tf.import_graph_def(
graph_def,
name='',
return_elements=[
model_info['bottleneck_tensor_name'],
model_info['resized_input_tensor_name'],
]))
return graph, bottleneck_tensor, resized_input_tensor

def run_bottleneck_on_image(sess, image_data, image_data_tensor,


decoded_image_tensor, resized_input_tensor,
bottleneck_tensor):

# First decode the JPEG image, resize it, and rescale the pixel values.
resized_input_values = sess.run(decoded_image_tensor,
{image_data_tensor: image_data})
# Then run it through the recognition network.
bottleneck_values = sess.run(bottleneck_tensor,
{resized_input_tensor: resized_input_values})
bottleneck_values = np.squeeze(bottleneck_values)
return bottleneck_values

def maybe_download_and_extract(data_url):
dest_directory = FLAGS.model_dir
if not os.path.exists(dest_directory):
os.makedirs(dest_directory)
filename = data_url.split('/')[-1]
filepath = os.path.join(dest_directory, filename)
if not os.path.exists(filepath):

def _progress(count, block_size, total_size):


sys.stdout.write('\r>> Downloading %s %.1f%%' %
(filename,
float(count * block_size) / float(total_size) * 100.0))
sys.stdout.flush()

filepath, _ = urllib.request.urlretrieve(data_url, filepath, _progress)


print()
statinfo = os.stat(filepath)
tf.logging.info('Successfully downloaded', filename, statinfo.st_size,
'bytes.')
tarfile.open(filepath, 'r:gz').extractall(dest_directory)

def ensure_dir_exists(dir_name):
if not os.path.exists(dir_name):
os.makedirs(dir_name)

bottleneck_path_2_bottleneck_values = {}
def create_bottleneck_file(bottleneck_path, image_lists, label_name, index,
image_dir, category, sess, jpeg_data_tensor,
decoded_image_tensor, resized_input_tensor,
bottleneck_tensor):

tf.logging.info('Creating bottleneck at ' + bottleneck_path)


image_path = get_image_path(image_lists, label_name, index,
image_dir, category)
if not gfile.Exists(image_path):
tf.logging.fatal('File does not exist %s', image_path)
image_data = gfile.FastGFile(image_path, 'rb').read()
try:
bottleneck_values = run_bottleneck_on_image(
sess, image_data, jpeg_data_tensor, decoded_image_tensor,
resized_input_tensor, bottleneck_tensor)
except Exception as e:
raise RuntimeError('Error during processing file %s (%s)' % (image_path,
str(e)))
bottleneck_string = ','.join(str(x) for x in bottleneck_values)
with open(bottleneck_path, 'w') as bottleneck_file:
bottleneck_file.write(bottleneck_string)

def get_or_create_bottleneck(sess, image_lists, label_name, index, image_dir,


category, bottleneck_dir, jpeg_data_tensor,
decoded_image_tensor, resized_input_tensor,
bottleneck_tensor, architecture):

label_lists = image_lists[label_name]
sub_dir = label_lists['dir']
sub_dir_path = os.path.join(bottleneck_dir, sub_dir)
ensure_dir_exists(sub_dir_path)
bottleneck_path = get_bottleneck_path(image_lists, label_name, index,
bottleneck_dir, category, architecture)
if not os.path.exists(bottleneck_path):
create_bottleneck_file(bottleneck_path, image_lists, label_name, index,
image_dir, category, sess, jpeg_data_tensor,
decoded_image_tensor, resized_input_tensor,
bottleneck_tensor)
with open(bottleneck_path, 'r') as bottleneck_file:
bottleneck_string = bottleneck_file.read()
did_hit_error = False
try:
bottleneck_values = [float(x) for x in bottleneck_string.split(',')]
except ValueError:
tf.logging.warning('Invalid float found, recreating bottleneck')
did_hit_error = True
if did_hit_error:
create_bottleneck_file(bottleneck_path, image_lists, label_name, index,
image_dir, category, sess, jpeg_data_tensor,
decoded_image_tensor, resized_input_tensor,
bottleneck_tensor)
with open(bottleneck_path, 'r') as bottleneck_file:
bottleneck_string = bottleneck_file.read()
# Allow exceptions to propagate here, since they shouldn't happen after a
# fresh creation
bottleneck_values = [float(x) for x in bottleneck_string.split(',')]
return bottleneck_values

def cache_bottlenecks(sess, image_lists, image_dir, bottleneck_dir,


jpeg_data_tensor, decoded_image_tensor,
resized_input_tensor, bottleneck_tensor, architecture):

how_many_bottlenecks = 0
ensure_dir_exists(bottleneck_dir)
for label_name, label_lists in image_lists.items():
for category in ['training', 'testing', 'validation']:
category_list = label_lists[category]
for index, unused_base_name in enumerate(category_list):
get_or_create_bottleneck(
sess, image_lists, label_name, index, image_dir, category,
bottleneck_dir, jpeg_data_tensor, decoded_image_tensor,
resized_input_tensor, bottleneck_tensor, architecture)

how_many_bottlenecks += 1
if how_many_bottlenecks % 100 == 0:
tf.logging.info(
str(how_many_bottlenecks) + ' bottleneck files created.')

def get_random_cached_bottlenecks(sess, image_lists, how_many, category,


bottleneck_dir, image_dir, jpeg_data_tensor,
decoded_image_tensor, resized_input_tensor,
bottleneck_tensor, architecture):
class_count = len(image_lists.keys())
bottlenecks = []
ground_truths = []
filenames = []
if how_many >= 0:
# Retrieve a random sample of bottlenecks.
for unused_i in range(how_many):
label_index = random.randrange(class_count)
label_name = list(image_lists.keys())[label_index]
image_index = random.randrange(MAX_NUM_IMAGES_PER_CLASS + 1)
image_name = get_image_path(image_lists, label_name, image_index,
image_dir, category)
bottleneck = get_or_create_bottleneck(
sess, image_lists, label_name, image_index, image_dir, category,
bottleneck_dir, jpeg_data_tensor, decoded_image_tensor,
resized_input_tensor, bottleneck_tensor, architecture)
ground_truth = np.zeros(class_count, dtype=np.float32)
ground_truth[label_index] = 1.0
bottlenecks.append(bottleneck)
ground_truths.append(ground_truth)
filenames.append(image_name)
else:
# Retrieve all bottlenecks.
for label_index, label_name in enumerate(image_lists.keys()):
for image_index, image_name in enumerate(
image_lists[label_name][category]):
image_name = get_image_path(image_lists, label_name, image_index,
image_dir, category)
bottleneck = get_or_create_bottleneck(
sess, image_lists, label_name, image_index, image_dir, category,
bottleneck_dir, jpeg_data_tensor, decoded_image_tensor,
resized_input_tensor, bottleneck_tensor, architecture)
ground_truth = np.zeros(class_count, dtype=np.float32)
ground_truth[label_index] = 1.0
bottlenecks.append(bottleneck)
ground_truths.append(ground_truth)
filenames.append(image_name)
return bottlenecks, ground_truths, filenames

def get_random_distorted_bottlenecks(
sess, image_lists, how_many, category, image_dir, input_jpeg_tensor,
distorted_image, resized_input_tensor, bottleneck_tensor):
class_count = len(image_lists.keys())
bottlenecks = []
ground_truths = []
for unused_i in range(how_many):
label_index = random.randrange(class_count)
label_name = list(image_lists.keys())[label_index]
image_index = random.randrange(MAX_NUM_IMAGES_PER_CLASS + 1)
image_path = get_image_path(image_lists, label_name, image_index, image_dir,
category)
if not gfile.Exists(image_path):
tf.logging.fatal('File does not exist %s', image_path)
jpeg_data = gfile.FastGFile(image_path, 'rb').read()
distorted_image_data = sess.run(distorted_image,
{input_jpeg_tensor: jpeg_data})
bottleneck_values = sess.run(bottleneck_tensor,
{resized_input_tensor: distorted_image_data})
bottleneck_values = np.squeeze(bottleneck_values)
ground_truth = np.zeros(class_count, dtype=np.float32)
ground_truth[label_index] = 1.0
bottlenecks.append(bottleneck_values)
ground_truths.append(ground_truth)
return bottlenecks, ground_truths

def should_distort_images(flip_left_right, random_crop, random_scale,


random_brightness):

return (flip_left_right or (random_crop != 0) or (random_scale != 0) or


(random_brightness != 0))
def add_input_distortions(flip_left_right, random_crop, random_scale,
random_brightness, input_width, input_height,
input_depth, input_mean, input_std):
jpeg_data = tf.placeholder(tf.string, name='DistortJPGInput')
decoded_image = tf.image.decode_jpeg(jpeg_data, channels=input_depth)
decoded_image_as_float = tf.cast(decoded_image, dtype=tf.float32)
decoded_image_4d = tf.expand_dims(decoded_image_as_float, 0)
margin_scale = 1.0 + (random_crop / 100.0)
resize_scale = 1.0 + (random_scale / 100.0)
margin_scale_value = tf.constant(margin_scale)
resize_scale_value = tf.random_uniform(tensor_shape.scalar(),
minval=1.0,
maxval=resize_scale)
scale_value = tf.multiply(margin_scale_value, resize_scale_value)
precrop_width = tf.multiply(scale_value, input_width)
precrop_height = tf.multiply(scale_value, input_height)
precrop_shape = tf.stack([precrop_height, precrop_width])
precrop_shape_as_int = tf.cast(precrop_shape, dtype=tf.int32)
precropped_image = tf.image.resize_bilinear(decoded_image_4d,
precrop_shape_as_int)
precropped_image_3d = tf.squeeze(precropped_image, squeeze_dims=[0])
cropped_image = tf.random_crop(precropped_image_3d,
[input_height, input_width, input_depth])
if flip_left_right:
flipped_image = tf.image.random_flip_left_right(cropped_image)
else:
flipped_image = cropped_image
brightness_min = 1.0 - (random_brightness / 100.0)
brightness_max = 1.0 + (random_brightness / 100.0)
brightness_value = tf.random_uniform(tensor_shape.scalar(),
minval=brightness_min,
maxval=brightness_max)
brightened_image = tf.multiply(flipped_image, brightness_value)
offset_image = tf.subtract(brightened_image, input_mean)
mul_image = tf.multiply(offset_image, 1.0 / input_std)
distort_result = tf.expand_dims(mul_image, 0, name='DistortResult')
return jpeg_data, distort_result

def variable_summaries(var):
with tf.name_scope('summaries'):
mean = tf.reduce_mean(var)
tf.summary.scalar('mean', mean)
with tf.name_scope('stddev'):
stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
tf.summary.scalar('stddev', stddev)
tf.summary.scalar('max', tf.reduce_max(var))
tf.summary.scalar('min', tf.reduce_min(var))
tf.summary.histogram('histogram', var)

def add_final_training_ops(class_count, final_tensor_name, bottleneck_tensor,


bottleneck_tensor_size):
with tf.name_scope('input'):
bottleneck_input = tf.placeholder_with_default(
bottleneck_tensor,
shape=[None, bottleneck_tensor_size],
name='BottleneckInputPlaceholder')

ground_truth_input = tf.placeholder(tf.float32,
[None, class_count],
name='GroundTruthInput')

layer_name = 'final_training_ops'
with tf.name_scope(layer_name):
with tf.name_scope('weights'):
initial_value = tf.truncated_normal(
[bottleneck_tensor_size, class_count], stddev=0.001)

layer_weights = tf.Variable(initial_value, name='final_weights')

variable_summaries(layer_weights)
with tf.name_scope('biases'):
layer_biases = tf.Variable(tf.zeros([class_count]), name='final_biases')
variable_summaries(layer_biases)
with tf.name_scope('Wx_plus_b'):
logits = tf.matmul(bottleneck_input, layer_weights) + layer_biases
tf.summary.histogram('pre_activations', logits)

final_tensor = tf.nn.softmax(logits, name=final_tensor_name)


tf.summary.histogram('activations', final_tensor)

with tf.name_scope('cross_entropy'):
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
labels=ground_truth_input, logits=logits)
with tf.name_scope('total'):
cross_entropy_mean = tf.reduce_mean(cross_entropy)
tf.summary.scalar('cross_entropy', cross_entropy_mean)

with tf.name_scope('train'):
optimizer = tf.train.GradientDescentOptimizer(FLAGS.learning_rate)
train_step = optimizer.minimize(cross_entropy_mean)

return (train_step, cross_entropy_mean, bottleneck_input, ground_truth_input,


final_tensor)

def add_evaluation_step(result_tensor, ground_truth_tensor):


with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
prediction = tf.argmax(result_tensor, 1)
correct_prediction = tf.equal(
prediction, tf.argmax(ground_truth_tensor, 1))
with tf.name_scope('accuracy'):
evaluation_step = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
tf.summary.scalar('accuracy', evaluation_step)
return evaluation_step, prediction

def save_graph_to_file(sess, graph, graph_file_name):


output_graph_def = graph_util.convert_variables_to_constants(
sess, graph.as_graph_def(), [FLAGS.final_tensor_name])
with gfile.FastGFile(graph_file_name, 'wb') as f:
f.write(output_graph_def.SerializeToString())
return

def prepare_file_system():
# Setup the directory we'll write summaries to for TensorBoard
if tf.gfile.Exists(FLAGS.summaries_dir):
tf.gfile.DeleteRecursively(FLAGS.summaries_dir)
tf.gfile.MakeDirs(FLAGS.summaries_dir)
if FLAGS.intermediate_store_frequency > 0:
ensure_dir_exists(FLAGS.intermediate_output_graphs_dir)
return

def create_model_info(architecture):

architecture = architecture.lower()
if architecture == 'inception_v3':
# pylint: disable=line-too-long
data_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
# pylint: enable=line-too-long
bottleneck_tensor_name = 'pool_3/_reshape:0'
bottleneck_tensor_size = 2048
input_width = 299
input_height = 299
input_depth = 3
resized_input_tensor_name = 'Mul:0'
model_file_name = 'classify_image_graph_def.pb'
input_mean = 128
input_std = 128
elif architecture.startswith('mobilenet_'):
parts = architecture.split('_')
if len(parts) != 3 and len(parts) != 4:
tf.logging.error("Couldn't understand architecture name '%s'",
architecture)
return None
version_string = parts[1]
if (version_string != '1.0' and version_string != '0.75' and
version_string != '0.50' and version_string != '0.25'):
tf.logging.error version_string, architecture)
return None
size_string = parts[2]
if (size_string != '224' and size_string != '192' and
size_string != '160' and size_string != '128'):
tf.logging.error(
size_string, architecture)
return None
if len(parts) == 3:
is_quantized = False
else:
if parts[3] != 'quantized':
tf.logging.error(
"Couldn't understand architecture suffix '%s' for '%s'", parts[3],
architecture)
return None
is_quantized = True
data_url = 'http://download.tensorflow.org/models/mobilenet_v1_'
data_url += version_string + '_' + size_string + '_frozen.tgz'
bottleneck_tensor_name = 'MobilenetV1/Predictions/Reshape:0'
bottleneck_tensor_size = 1001
input_width = int(size_string)
input_height = int(size_string)
input_depth = 3
resized_input_tensor_name = 'input:0'
if is_quantized:
model_base_name = 'quantized_graph.pb'
else:
model_base_name = 'frozen_graph.pb'
model_dir_name = 'mobilenet_v1_' + version_string + '_' + size_string
model_file_name = os.path.join(model_dir_name, model_base_name)
input_mean = 127.5
input_std = 127.5
else:
tf.logging.error("Couldn't understand architecture name '%s'", architecture)
raise ValueError('Unknown architecture', architecture)

return {
'data_url': data_url,
'bottleneck_tensor_name': bottleneck_tensor_name,
'bottleneck_tensor_size': bottleneck_tensor_size,
'input_width': input_width,
'input_height': input_height,
'input_depth': input_depth,
'resized_input_tensor_name': resized_input_tensor_name,
'model_file_name': model_file_name,
'input_mean': input_mean,
'input_std': input_std,
}

def add_jpeg_decoding(input_width, input_height, input_depth, input_mean,


input_std):
jpeg_data = tf.placeholder(tf.string, name='DecodeJPGInput')
decoded_image = tf.image.decode_jpeg(jpeg_data, channels=input_depth)
decoded_image_as_float = tf.cast(decoded_image, dtype=tf.float32)
decoded_image_4d = tf.expand_dims(decoded_image_as_float, 0)
resize_shape = tf.stack([input_height, input_width])
resize_shape_as_int = tf.cast(resize_shape, dtype=tf.int32)
resized_image = tf.image.resize_bilinear(decoded_image_4d,
resize_shape_as_int)
offset_image = tf.subtract(resized_image, input_mean)
mul_image = tf.multiply(offset_image, 1.0 / input_std)
return jpeg_data, mul_image

def main(_):

tf.logging.set_verbosity(tf.logging.INFO)

model_info = create_model_info(FLAGS.architecture)
if not model_info:
tf.logging.error('Did not recognize architecture flag')
return -1

maybe_download_and_extract(model_info['data_url'])
graph, bottleneck_tensor, resized_image_tensor = (
create_model_graph(model_info))

image_lists = create_image_lists(FLAGS.image_dir, FLAGS.testing_percentage,


FLAGS.validation_percentage)
class_count = len(image_lists.keys())
if class_count == 0:
tf.logging.error('No valid folders of images found at ' + FLAGS.image_dir)
return -1
if class_count == 1:
tf.logging.error('Only one valid folder of images found at ' +
FLAGS.image_dir +
' - multiple classes are needed for classification.')
return -1

do_distort_images = should_distort_images(
FLAGS.flip_left_right, FLAGS.random_crop, FLAGS.random_scale,
FLAGS.random_brightness)

with tf.Session(graph=graph) as sess:


jpeg_data_tensor, decoded_image_tensor = add_jpeg_decoding(
model_info['input_width'], model_info['input_height'],
model_info['input_depth'], model_info['input_mean'],
model_info['input_std'])

if do_distort_images:
# We will be applying distortions, so setup the operations we'll need.
(distorted_jpeg_data_tensor,
distorted_image_tensor) = add_input_distortions(
FLAGS.flip_left_right, FLAGS.random_crop, FLAGS.random_scale,
FLAGS.random_brightness, model_info['input_width'],
model_info['input_height'], model_info['input_depth'],
model_info['input_mean'], model_info['input_std'])
else:
cache_bottlenecks(sess, image_lists, FLAGS.image_dir,
FLAGS.bottleneck_dir, jpeg_data_tensor,
decoded_image_tensor, resized_image_tensor,
bottleneck_tensor, FLAGS.architecture)

(train_step, cross_entropy, bottleneck_input, ground_truth_input,


final_tensor) = add_final_training_ops(
len(image_lists.keys()), FLAGS.final_tensor_name, bottleneck_tensor,
model_info['bottleneck_tensor_size'])

evaluation_step, prediction = add_evaluation_step(


final_tensor, ground_truth_input)

merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter(FLAGS.summaries_dir + '/train',
sess.graph)

validation_writer = tf.summary.FileWriter(
FLAGS.summaries_dir + '/validation')

# Set up all our weights to their initial default values.


init = tf.global_variables_initializer()
sess.run(init)

for i in range(FLAGS.how_many_training_steps):

if do_distort_images:
(train_bottlenecks,
train_ground_truth) = get_random_distorted_bottlenecks(
sess, image_lists, FLAGS.train_batch_size, 'training',
FLAGS.image_dir, distorted_jpeg_data_tensor,
distorted_image_tensor, resized_image_tensor, bottleneck_tensor)
else:
(train_bottlenecks,
train_ground_truth, _) = get_random_cached_bottlenecks(
sess, image_lists, FLAGS.train_batch_size, 'training',
FLAGS.bottleneck_dir, FLAGS.image_dir, jpeg_data_tensor,
decoded_image_tensor, resized_image_tensor, bottleneck_tensor,
FLAGS.architecture)

train_summary, _ = sess.run(
[merged, train_step],
feed_dict={bottleneck_input: train_bottlenecks,
ground_truth_input: train_ground_truth})
train_writer.add_summary(train_summary, i)

is_last_step = (i + 1 == FLAGS.how_many_training_steps)
if (i % FLAGS.eval_step_interval) == 0 or is_last_step:
train_accuracy, cross_entropy_value = sess.run(
[evaluation_step, cross_entropy],
feed_dict={bottleneck_input: train_bottlenecks,
ground_truth_input: train_ground_truth})
tf.logging.info('%s: Step %d: Train accuracy = %.1f%%' %
(datetime.now(), i, train_accuracy * 100))
tf.logging.info('%s: Step %d: Cross entropy = %f' %
(datetime.now(), i, cross_entropy_value))
validation_bottlenecks, validation_ground_truth, _ = (
get_random_cached_bottlenecks(
sess, image_lists, FLAGS.validation_batch_size, 'validation',
FLAGS.bottleneck_dir, FLAGS.image_dir, jpeg_data_tensor,
decoded_image_tensor, resized_image_tensor, bottleneck_tensor,
FLAGS.architecture))

validation_summary, validation_accuracy = sess.run(


[merged, evaluation_step],
feed_dict={bottleneck_input: validation_bottlenecks,
ground_truth_input: validation_ground_truth})
validation_writer.add_summary(validation_summary, i)
tf.logging.info('%s: Step %d: Validation accuracy = %.1f%% (N=%d)' %
(datetime.now(), i, validation_accuracy * 100,
len(validation_bottlenecks)))

intermediate_frequency = FLAGS.intermediate_store_frequency

if (intermediate_frequency > 0 and (i % intermediate_frequency == 0)


and i > 0):
intermediate_file_name = (FLAGS.intermediate_output_graphs_dir +
'intermediate_' + str(i) + '.pb')
tf.logging.info('Save intermediate result to : ' +
intermediate_file_name)
save_graph_to_file(sess, graph, intermediate_file_name)

test_bottlenecks, test_ground_truth, test_filenames = (


get_random_cached_bottlenecks(
sess, image_lists, FLAGS.test_batch_size, 'testing',
FLAGS.bottleneck_dir, FLAGS.image_dir, jpeg_data_tensor,
decoded_image_tensor, resized_image_tensor, bottleneck_tensor,
FLAGS.architecture))
test_accuracy, predictions = sess.run(
[evaluation_step, prediction],
feed_dict={bottleneck_input: test_bottlenecks,
ground_truth_input: test_ground_truth})
tf.logging.info('Final test accuracy = %.1f%% (N=%d)' %
(test_accuracy * 100, len(test_bottlenecks)))

if FLAGS.print_misclassified_test_images:
tf.logging.info('=== MISCLASSIFIED TEST IMAGES ===')
for i, test_filename in enumerate(test_filenames):
if predictions[i] != test_ground_truth[i].argmax():
tf.logging.info('%70s %s' %
(test_filename,
list(image_lists.keys())[predictions[i]]))

save_graph_to_file(sess, graph, FLAGS.output_graph)


with gfile.FastGFile(FLAGS.output_labels, 'w') as f:
f.write('\n'.join(image_lists.keys()) + '\n')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--image_dir',
type=str,
default='',
help='Path to folders of labeled images.'
)
parser.add_argument(
'--output_graph',
type=str,
default='/tmp/output_graph.pb',
help='Where to save the trained graph.'
)
parser.add_argument(
'--intermediate_output_graphs_dir',
type=str,
default='/tmp/intermediate_graph/',
help='Where to save the intermediate graphs.'
)
parser.add_argument(
'--intermediate_store_frequency',
type=int,
default=0,
)
parser.add_argument(
'--output_labels',
type=str,
default='/tmp/output_labels.txt',
help='Where to save the trained graph\'s labels.'
)
parser.add_argument(
'--summaries_dir',
type=str,
default='/tmp/retrain_logs',
help='Where to save summary logs for TensorBoard.'
)
parser.add_argument(
'--how_many_training_steps',
type=int,
default=6000,
help='How many training steps to run before ending.'
)
parser.add_argument(
'--learning_rate',
type=float,
default=0.01,
help='How large a learning rate to use when training.'
)
parser.add_argument(
'--testing_percentage',
type=int,
default=10,
help='What percentage of images to use as a test set.'
)
parser.add_argument(
'--validation_percentage',
type=int,
default=10,
help='What percentage of images to use as a validation set.'
)
parser.add_argument(
'--eval_step_interval',
type=int,
default=10,
help='How often to evaluate the training results.'
)
parser.add_argument(
'--train_batch_size',
type=int,
default=100,
help='How many images to train on at a time.'
)
parser.add_argument(
'--test_batch_size',
type=int,
default=-1,
)
parser.add_argument(
'--validation_batch_size',
type=int,
default=100,
)
parser.add_argument(
'--print_misclassified_test_images',
default=False,

action='store_true'
)
parser.add_argument(
'--model_dir',
type=str,
default='/tmp/imagenet',
)
parser.add_argument(
'--bottleneck_dir',
type=str,
default='/tmp/bottleneck',
help='Path to cache bottleneck layer values as files.'
)
parser.add_argument(
'--final_tensor_name',
type=str,
default='final_result',
)
parser.add_argument(
'--flip_left_right',
default=False,
action='store_true'
)
parser.add_argument(
'--random_crop',
type=int,
default=0,
)
parser.add_argument(
'--random_scale',
type=int,
default=0,
)
parser.add_argument(
'--random_brightness',
type=int,
default=0,
)
parser.add_argument(
'--architecture',
type=str,
default='inception_v3',
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)

Program Screenshots:
Result:
Thus the System is implemented successfully
Ex.No: 5 Task 5 – Testing Strategies

Task 5.1 – Study of Testing Types using Test Plan Document

1. Introduction
Purpose
Scope
References
2. Review requirement and Design
Review requirement
Review system architecture
3. Features to be tested
4. Features not to be tested
5. Approach
Kind of test
Data and Database Integrity Testing
System testing
Performance Testing
Load Testing
Test Strategy
Checklist of unit test
Unit testing
Smoke test
Data and Database Integrity Testing
System Testing
Performance Testing
Load Testing
6 Suspension criteria & Resumption requirements
7. Environmental Needs
Tools
Software
Hardware
8. Schedule
9. Acceptance criteria
10. Resources

1.Introduction

Purpose
This document describes the plan for testing the Emotion Detection for blind people. This Test Plan
document supports the following objectives: Identify Emotion Detection for blind people project
information and its components that should be tested. List the recommended test requirements
(highlevel).Recommend and describe the testing strategies. Identify the required resources, provide an
estimate of the test efforts, and detail testing schedule. List the deliverable elements of the test
activities.
Scope
This Test Plan applies to unit test, integration test and system test that will be conducted on the
Emotion Detection for blind people. It is assumed that unit testing already provided thorough black
box testing through extensive coverage of source code and testing of all module interfaces. This Test
Plan applies to test all requirements of the Emotion Detection for blind people as defined in the Vision
and Scope Document, Use-case specification, and software requirement specification document.

References
Vision and Scope document Business Plan and SRS document

2.Review requirement and Design


Review Requirement
Original requirement defined by our team is that our system only contains 8 use cases. You can see
in the original use case model below.
The detail of these use cases is described in SRS document. Therefore, we will not do it again in this
document. However, according to recommendations from the staff, we will improve our use cases
functionality. In this document, we only introduce the changes on requirement that our team has been
made. The following is the updated use case model.

3.Features to be tested
We will perform testing on use case specification, functional requirement, and non-functional
requirement of all use cases and functions. They include
Capture image
Delete image
Classify known/unknown
Get haptic input
Train model
Test mode
Get audio input
Analyze data

4.Features not to betested


Because we will test all features of the system we have been defined, there is no feature that will not be
tested.

5.Approach
Kind oftest
The tests below base on the use case specifications, functional requirements, and non-functional
requirements which have been identified as the targets for testing besides, we also show the kinds of
test which our team intend to perform.

Data and Database IntegrityTesting


Data integrity and database integrity test techniques verify that data is being stored by the system in a
manner where the data is not compromised by updating, restoration, or retrieval processing. This type of
testing is intended to uncover design flaws that may result in data corruption, unauthorized data access,
lack of data integrity across multiple tables, and lack of adequatetransaction performance. The database,
data files, and the database or data file processes should be tested as a subsystem within the application.

System Testing
System testing of software is testing conducted on a complete, integrated system to evaluate the
system's compliance with its specified requirements. They includes the following functions
Capture image
Delete image
Classify known/unknown
Get haptic input
Train model
Test mode
Get audio input
Analyze data

Performance Testing
Performance Testing covers a broad range of engineering or functional evaluations where a material,
product, or system is not specified by detailed material or component specifications: Rather,
emphasis is on the final measurable performance characteristics.

Load Testing
Load testing is the process of creating demand on a system or device and measuring its response.

Test Strategy
The Test Strategy presents the recommended approach to the testing of the software applications. The
previous section on Test Requirements described what kinds of test will be tested. This part describes
how they will be performed.
The main considerations for the test strategy are the techniques to be used and the criterion for
testing to be completed. However, before starting the system test (functional and non- functional
requirements testing), we must perform unit test for each unit of the system (fields, methods, classes,
and components) and make sure that all unit must pass the check list of unit test.

Checklist of unit test


Verify the input data length specified in the NumPy database Verify the input data format specified
in each form, classes, and interaction with database
String format
Integer number format
Special character
Empty field
Null
Test write
Test write null field
Test write read
Doing this kind of checking help us to decrease the number of simple test cases

Unit Testing
According to the system architecture, we have to test all entities, Python table, struts actions.

Data and Database Integrity Testing

The data and data processing should be Ensure Database access methods and
tested as separate systems. These systems processes function properly and without data
should be tested without the applications corruption.
(as the interface to the data).
Additional research into the DBMS needs to
be performed to identify the tools / techniques
that may exist to support the testing identified
below. Test Objective
Technique Invoke each database access method and
process, seeding each with valid and invalid
data (or requests for data). Inspect the
database to ensure the data has been
populated as intended, all database events
occurred properly, or review the returned data
to ensure that the correct data was retrieved
(for the correct reasons)
Completion Criteria All database access methods and processes
function as designed and without any data
corruption.
Special Considerations Testing may require a DBMS development
environment or drivers to enter or modify data
directly in the databases. Processes should be
invoked manually.
Small or minimally sized databases (limited
number of records) should be

System Testing
Testing of the application should focus on Ensure proper application navigation, data
any target requirements that can be traced entry, processing, and retrieval.
directly to use cases (or business
functions), and business rules. The goals of
these tests are to verify proper data
acceptance, processing, and retrieval, and
the appropriate implementation of the
business rules. This type of testing is based
upon black box technique, which is,
verifying the application (and its internal
processes) by interacting with the
application via the GUI and analyzing the
output (results). Identified below is an
outline of the testing recommended for
each application. Test Objective
Technique Execute each use case, use case flow, or
function, using valid and invalid data, to
verify the following: The expected results
occur when valid data is used. The
appropriate error / warning messages are
displayed when invalid data is used. Each
business rule is properly applied.
Completion Criteria All planned tests have been executed. All
identified defects have been addressed.
Special Considerations Access to the Emotion Detection for blind
people and the existing System is
required.
Load Testing
Load testing measures subjects the system- Verify System Response time for
under-test to varying workloads to designated transactions or business cases
evaluate the system's ability to continue to under varyingworkload conditions.
function properly under these different
workloads. The goal of load testing is to
determine and ensure that the system
functions properly beyond the expected
maximum workload. Additionally, load
testing evaluates the performance
characteristics (response times, transaction
rates, and other time sensitiveissues).
NOTE: Transactions below refer to
"logical business transactions".
These transactions are defined as
specificfunctions that an end user of the
system is expected to perform using the
application, such as add or modify a given
contract.
Test Objective

Technique Use tests developed for Business Cycle


Testing. Modify data files (to increase the
number of transactions) or the tests to
increase the number of times each
transaction occurs.
Completion Criteria Multiple transactions / multiple users:
Successful completion of the tests without
any failures and within acceptable time
allocation.
Special Considerations Load testing should be performed on a
dedicated machine or at a dedicated time.
This permits full control and accurate
measurement. The databases used for load
testing should be either actual size, or
scaled equally.

6.Suspension criteria and resumption requirements


Suspension Criteria
Three use cases have more than 2 major errors or fours minor errors, then the build is not acceptable
and the testing is suspended.
Resumption Requirements
All major errors & and at least 70% of minor errors that have been found in previous iteration are
fixed.
7.EnvironmentalNeeds
7.1Tools Tool
Project Management Microsoft Project
Microsoft Word
Microsoft Excel
DBMS tools NumPy

Software
Documentation tool Microsoft word 2007
Scheduling tool Microsoft project 2007
IDE Spyder
Statistical tool Microsoft excel 2007
Microsoft Express Web Designer
DBMS NumPy
Operating system Windows 10,
Ubuntu

7.Schedule
The testing activities and milestones are dependent on the development iterations. The
Construction Phasewill be split into 3 iterations. Each iteration contains a full test cycle of test
planning, designing, development, execution, and evaluation. Refer to the Software
Development Plan and the Iteration Plans for the master schedule and Construction Phaseplan
that shows the development iterations.

The following table shows the Test Milestones, start date, and end date as planned.

Milestone Task Start Date End Date


Iteration C1: Review 3 1st October 14th October
Test Planning Test Design
Test Development Test
Execution Test Evaluation

Iteration C2: Review 4 15st October 1st November


Test Planning Test Design
Test Development Test
Execution Test Evaluation

8.Acceptance criteria
Satisfy all features will be tested as above lists. Placement Prediction System can run smoothly.
Provide a product with functions as requirements, help customer how to use the product easily. And
satisfy the following conditions:
 Successful completion of all tasks as documented in the test schedule.Quantity of medium- and
low-level defects must be at an acceptable level as determined by the software testing project
team lead. User interfaces for all features are functionally complete.
 Installation documentation and scripts are complete and tested. Development code
reviews are complete, and all issues addressed.
 All high-priority issues have been resolved. All outstanding issues pertinent to this
release are resolved and closed.
 All current code must be under source control, must build cleanly, the build process
must be automated, and the software components must be labeled with correct
version numbers in the version control system.
 All high-priority defects are corrected and fully tested prior to release.
 All defects that have not been fixed before release have been reviewed by project
stakeholders to confirm that they are acceptable.
 The end user experience is at an agreed acceptable level. Operational procedures
have been written for installation, set up, error recovery, and escalation.
 There must be no adverse effects on already deployed systems.

9.Resources
This section presents the recommended resources for testing the Placement Prediction System, their
main responsibilities, and their knowledge or skill set. Roles and responsibilities This table shows the
staffing assumptions for the test activities.

Worker Specific Responsibilities/Comments


Test Manager Provides management oversight
Responsibilities: Provide technical
direction Acquire appropriate resources
Test Designer Identifies, prioritizes, and implements test
cases Responsibilities: Generate test plan
Generate Test Suite Evaluate effectiveness
of test effort
System Tester Executes the tests, Responsibilities:
Execute tests Log results Recover from
errors Document defects

Ensures test environment and assets are


Test System Administrator managed and maintained. Responsibilities:
Administer test management system Install /
manage worker access to test systems
Implementer Implement test cases and packages.
Responsibilities: Create the test class and
packages implemented in the test site

Database Administration Database Ensures test data (database) environment


Manager and asserts are managed

Designer Identifies and defines the operations,


attributes, and associations of the test classes
Responsibilities:
System Resources
The following table sets forth the system resources for the testing the Emotion Detection For Blind
People.

Resource Description
Image Database Simulated
database
1 Local PCs Local network
(connected via computers
LAN)

Result:
Thus, the study of test case using test plan document is implemented successfully.
Task 5.2- Test Case Generation
EMOTIONAL DETECTION FOR BLIND PEOPLE

Test case USER_ACTION INPUT ACTUAL ACHIEVED OUTPUT


Number OUTPUT

TC1 HAPPY Detect the facial If they are Successful


express of the happy then it
person by the show it as
camera happy

TC2 SAD Detect the facial If they are sad Successful.


express of the then it show it
person by the as sad
camera

TC3 TONGUE OUT Detect the facial It shows the Successful


express of the tongue out
person by the expression
camera

TC5 NEUTRAL Detect the facial If the person Successful


express of the is neutral then
person by the it show as
camera neutral

TC6 SUPRISE Detect the facial If the person Successful


express of the get suprise
person by the then it show
camera the output as
suprise

Result:
Thus, Test case is generated for Emotional detection for blind people.

You might also like