Farm Object Detection3
Farm Object Detection3
by
Dr.G.Neelima
Department of computer science & engineering
Acharya Nagarjuna University
i
DECLARATION
I hereby declare that the entire thesis work entitled " An Efficient Multi-Task Convolutional
Neural Network For Dairy Farm Object Detection and Segmentation" is being submitted
Acharya Nagarjuna University, in partial fulfillment of the requirement for the award of the
Carried out under the supervision of DR.G.Neelima Department of Computer Science &
I further declare that the Project, either in part or full, has not been submitted earlier by me or
ii
ACHARYA NAGARJUNA UNIVERSITY
NAGARJUNA NAGAR, GUNTUR.
Department of Computer Science & Engineering.
CERTIFICATE
iii
External Examiner
ACKNOWLEDGEMENTS
Undertaking this Project has been a truly life-changing experience for me and it would not have been
possible to do without the support and guidance that I received from many people.
I would like to first say a very big thank you to my supervisor Dr.G.Neelima for all the support and
encouragement he gave me. Her friendly guidance and expert advice have been invaluable throughout
all stages of the work. Without her guidance and constant feedback this Project work not have been
achievable.
I would also wish to express my gratitude to Dr.G.Neelima for extended discussions and valuable
I am thankful to and fortunate enough to get constant encouragement, support and guidance from all
Teaching staffs of Department which helped us in successfully completing our project work. Also, I
would like to extend our sincere regards to all the non-teaching staff of the department for their timely
support.
I must also thank my parents and friends for the immense support and help during this project. Without
their help, completing this project would have been very difficult.
iv
ABSTRACT
The precise classification of animal breeds from image data is instrumental in real-time animal
monitoring within forest ecosystems. Traditional computer vision methods have increasingly fallen
short in accuracy due to the rapid progression of technology. To address these limitations, more
advanced methodologies have emerged, significantly improving the accuracy of image classification,
recognition, and segmentation tasks. The advent of "deep learning" has revolutionized various fields,
particularly in object identification and recognition. Animal breed categorization is an important job
in the field of image processing, and this research attempts to create a unique deep learning-based
model for this purpose. Efficient and accurate object recognition has been an important topic in the
field of computer vision systems. Object recognition is concerns with determining the identity of an
object being observed in the image from a set of known labels. With the advent of deep learning with
neural network techniques, the accuracy for object detection has increased drastically. Animal
recognition system is implemented using Convolution Neural Network (CNN) for classification. CNN
model of the system is based on our own architecture. Kaggle animal-10 and monkey species dataset
with 10 animals as cat, chicken,
v
TABLE OF CONTENTS
TITLE PAGE NO
DECLARATION Ii
CERTIFICATE iii
ACKNOWLEDGEMENT iv
ABSTRACT v
Chapter 1: Introduction
1.1 Overview 1
Literature Survey 7
SYSTEM ANALYSIS 9
PROJECT PLANNING 11
vi
4.2 Non Functional Requirements 14
4.4 Algorithms 17
4.4.1 CNN 17
4.4.3 RESNET152V2 18
4.4.4 XCEPETION 20
4.4.5 INCEPTION 21
4.5 Python 23
Chapter 5: Methodology
Methodology 29
vii
6.2.3 Activity diagram 51
Source code 53
Chapter 8: SystemTesting
10.1 Conclusion 69
viii
CHAPTER 1
INTRODUCTION
1
Introduction
1.1 Overview
Animal recognition is one of the major and important fields in computer vision. Animal recognition is
concerns with determining the identity of an animal being observed in the image from a set of known
labels. Generally, the animal recognition algorithms implement a binary pattern classification task[1].
That means, given an input image is divided in blocks and each block is transformed into a feature.
Features from the animal that belongs to a certain class are used to train a certain classifier. Then, when
given a new input image, the classifier will be able to decide if the sample belongs to certain class or
not.
Image classification is one of the common and basic tasks in computer vision, and it has drawn a lot
of attention in recent years. Data transfer in the form of images is one of the most convenient forms of
presenting information for users. Images transmitted in can have background noise, distortion,
occlusion, etc. Noise reduce image quality and can lead to erroneous interpretation of useful
information. Noisy images are difficult to analyze both programmatically and by humans. Efficient
and reliable monitoring of wild animals in their natural habitats is essential to inform conservation and
management decisions regarding wildlife species, migration patterns, habitat protection, and is
possible, rehabilitation and grouping species of same animals together. Processing a large volume of
images and videos captured from camera traps manually is extremely expensive, time-consuming and
monotonous. This presents a major obstacle to scientists and ecologists to monitor wildlife in an open
environment. Images captured in a field represent a challenging task while classifying since they
appear in a different pose, cluttered background, different lighting and climatic conditions, human
photographic errors, different angles, and occlusions. All these challenges necessitate an efficient
algorithm for classification with most optimum accuracy. Convolutional neural network is a special
algorithm of artificial neural networks and deep learning, aimed at effective image processing. The
name of the network architecture is due to the presence of convolution operation. Convolution consists
in that each fragment of the image is multiplied by convolution matrix, the result is summed and written
to the analogous position of the output image. The work of a convolutional neural network is usually
interpreted as a transition from specific image features to more abstract details, and further to even
more abstract details, up to highlighting high-level concepts. Convolutional Neural Network is a deep
learning algorithm which can take an input image, assign importance to various aspects in the image
and be able to differentiate one from another. Convolutional Neural Networks are typically used for
2
image classification and recognition because of its high accuracy. Convolutional Neural Networks are
also much more flexible and can adapt to the new incoming data as the dataset matures. Classification
using convolutional neural network can also be applied to object detection. In recent years, multilayer
neural networks have been used successfully in classification, pattern recognition, learning.This
system uses Deep Learning techniques with convolutional neural network [2], and large labeled
datasets to address the problem of automated animal identification in the images. A convolutional
neural network (CNN, or ConvNet) is a type of feed-forward artificial neural network in which the
connectivity pattern between its neurons is inspired by the organization of the animal visual cortex.
They have wide applications in image and video recognition, recommendation systems and natural
language processing. It take in an input image, assign learnable weights and biases to various
aspects/objects in the image and will be able to differentiate one from the other. The pre-processing
required in a ConvNet is much lower as compared to other classification algorithms in terms of features
sizes. While in primitive methods filters are hand-engineered, with enough training, ConvNets have
the ability to learn these filters/characteristics.
The objective of this project is to develop a robust and accurate Animal Species Classification System
using Convolutional Neural Networks (CNN). With the increasing availability of large-scale datasets
containing images of various animal species, there is a growing need for automated systems that can
accurately identify and classify these species. The goal is to leverage the power of deep learning,
specifically CNNs, to create a model capable of distinguishing between different animal species based
on input images.
Large and Diverse Dataset: The project requires a comprehensive dataset that includes images of
various animal species with diverse backgrounds, poses, and lighting conditions. Acquiring and
preprocessing such a dataset is a critical challenge.
Model Generalization: Developing a CNN architecture that generalizes well to unseen data is crucial.
The model should be able to recognize patterns and features that are common across different species,
ensuring its effectiveness in real-world scenarios.
Model Interpretability: While achieving high accuracy is important, understanding how the model
3
makes decisions is equally vital, especially in applications where interpretability is crucial, such as
wildlife conservation. The project should explore methods for interpreting CNN predictions.
Data Augmentation: Implementing effective data augmentation techniques to artificially increase the
diversity of the training dataset is necessary. This helps improve the model's ability to handle variations
in input images.
Class Imbalance: Addressing potential class imbalances in the dataset is important to ensure that the
model does not exhibit biases toward more prevalent species and maintains high accuracy across all
classes.
Model Development: Design and implement a CNN architecture for animal species classification.
Experiment with various architectures, hyperparameters, and optimization techniques to achieve high
accuracy.
Data Preprocessing: Develop robust preprocessing pipelines to handle challenges such as image
resizing, normalization, and data augmentation.
Evaluation Metrics: Define appropriate evaluation metrics for assessing the model's performance,
considering factors such as precision, recall, and F1 score.
Interpretability: Investigate methods for interpreting the CNN model's decisions, providing insights
into which features contribute to classification.
User Interface (Optional): Create a user-friendly interface that allows users to upload images for
classification, providing a practical application for the developed model.
4
1.5 Objective of the project
The objective of animal detection in farms using Convolutional Neural Networks (CNNs) can be
summarized as follows:
To develop a system that can automatically monitor animals on farms without the need for constant
human supervision. This helps farmers keep track of the health, behavior, and whereabouts of their
livestock more efficiently. To enable early detection of issues such as animal health problems,
injuries, or distress. By identifying these issues promptly, farmers can take timely intervention
measures, potentially preventing more serious problems and improving animal welfare.
To optimize resource allocation on farms by providing insights into animal distribution and
behavior. For example, knowing the exact location of animals can help farmers make informed
decisions about feeding, watering, and managing grazing areas more efficiently.To contribute to
increased productivity and profitability on farms by reducing losses due to animal health issues,
theft, or predation. By accurately monitoring and managing their livestock, farmers can maximize the
yield and quality of agricultural products.
To promote better animal welfare practices by ensuring that animals receive adequate care and
attention. By monitoring their behavior and health status, farmers can identify and address any
welfare concerns promptly, leading to happier and healthier animals.To empower farmers with data-
driven insights into their operations. By analyzing patterns in animal behavior and interactions,
farmers can make more informed decisions about breeding, stocking densities, and other aspects of
farm management.
support environmental sustainability by helping farmers implement more efficient and sustainable
farming practices. By optimizing resource use and minimizing waste, such systems can contribute to
reducing the environmental footprint of livestock farming operations.
Overall, the objective of animal detection in farms using CNNs is to leverage advanced technology
to improve the efficiency, productivity, and welfare of livestock farming operations while also
promoting sustainability and responsible stewardship of natural resources.
5
CHAPTER 2
LITERATURE SURVEY
6
LITERATURE SURVEY
EITEL, A., J. T. SPRINGENBERG, L. D. SPINELLO, M. RIEDMILLER and W. BURGARD.
Multimodal Deep Learning for Robust RGB Recognition. In: 2015
Zhang et al. [5] detect heads of animals like tiger, cat, dog, cheetah, etc. by using shape and texture
features to improve image retrieval. The approach relies on prominent ‘pointed’ ear shapes in frontal
poses which makes it sensitive to head-pose variations. These approaches rely on identifying different
parts of the animal to detect and track an individual but are likely to fail in case of occlusion or
significant pose change.
IEEE/RSJ, International Conference on Robots and Systems (IROS). Hamburg:IEEE, 2015, pp.
681–687. ISBN978 1.DOI:10.1109/IROS.2015.7353446
Hung Nguyen et al. (DSAA, 2017) [6] attempted to automate the wild-life monitoring by using CNN,
but on a much smaller scale and with only 3 classes. They used only 55 000 image for training and
achieve a 90.4% accuracy.
Verma, Gyanendra & Gupta, Pragya. (2018). Wild Animal Detection Using Deep Convolutional
Neural Network.
In this paper, wildlife monitoring and analysis through animal detection. The images obtained from
camera-trap consist of highly cluttered images that hinder the detection of animal resulting in low-
detection rates. In this detection model using DCNN features provides accuracy of 91.4% on standard
camera-trap dataset that contains 20 species of animals with around 1000 image sequence for each
species.
"Deep neural networks for acoustic novelty detection: Towards the application to bioacoustic
monitoring of the Amazon rainforest" by Kahl et al. (2017):
This paper explores the use of CNNs for bioacoustic monitoring of the Amazon rainforest, focusing
on the classification of animal species based on their vocalizations.
"Convolutional neural networks for automated annotation of wildlife imagery" by Norouzzadeh et al.
(2018):
The authors propose a CNN-based approach for automated species classification in camera trap
images, demonstrating its effectiveness in identifying various animal species.
7
"Deep learning for ecologists: Using convolutional neural networks for automated camera trap
image classification" by Beery et al. (2018):
The paper discusses the application of CNNs for automating the classification of camera trap images,
providing insights into the challenges and opportunities in using deep learning for wildlife monitoring.
"A deep learning approach to identify and count wildlife in aerial images" by Tabak et al. (2019):
This study employs CNNs to identify and count animals in aerial images, showcasing the potential of
deep learning in large-scale wildlife monitoring projects.
"A deep learning approach for automated detection and classification of vocalizations in field
recordings" by Xie et al. (2020):
This paper explores the use of CNNs for the automated detection and classification of animal
vocalizations in field recordings, contributing to the field of bioacoustics.
"Deep learning for automatic identification of animal species in camera trap images" by
Norouzzadehet al. (2018):
The authors present a comprehensive framework for automatic species identification in camera trap
images using CNNs.
8
CHAPTER 3
SYSTEM ANALYSIS
9
SYSTEM ANALYSIS
System analysis for animal detection in farms using Convolutional Neural Networks (CNNs)
involves breaking down the process into various stages to understand and design an effective system.
Here's an outline of such an analysis:
Problem Definition:
Clearly define the problem: Detecting animals in farm environments using CNNs.
Specify the types of animals to be detected (e.g., cows, sheep, chickens).
Identify the environment conditions (e.g., varying lighting, weather conditions).
Data Collection and Preprocessing:
Gather a large dataset of farm images containing animals.Label the images with bounding boxes or
segmentation masks indicating the location of animals.Preprocess the images (e.g., resizing,
normalization) to make them suitable for input to the CNN.
Model Selection:
Choose an appropriate CNN architecture for object detection tasks. Common choices include:
• YOLO (You Only Look Once)
• Faster R-CNN (Region-based Convolutional Neural Networks)
• SSD (Single Shot MultiBox Detector)
• RetinaNet
• Consider pre-trained models and fine-tuning if data is limited.
Model Training:
Split the dataset into training, validation, and test sets.
Train the CNN using the training set.
Tune hyperparameters such as learning rate, batch size, and optimizer.
Evaluation Metrics:
Choose appropriate evaluation metrics such as precision, recall, F1-score, and mean Average
Precision (mAP) for object detection tasks.
Evaluate the model's performance on the validation and test sets.
Model Optimization:
Optimize the model for inference speed and accuracy.
10
Consider techniques like pruning, quantization, and model compression to reduce the model size
and inference time.
Experiment with different architectures and hyperparameters to improve performance.
Deployment:
Deploy the trained model to the farm environment.
Integrate the model with farm surveillance systems or drones if applicable.
Monitor the model's performance in real-world conditions and update as necessary.
Maintenance and Updates:
Regularly update the model with new data to adapt to changing conditions and environments.
Monitor for drift in performance and retrain the model as needed.
Stay informed about advancements in CNN architectures and techniques for object detection.
Ethical Considerations:
Consider the ethical implications of deploying such a system, including potential impacts on
animal welfare and privacy.
Ensure the responsible use of data collected by the system.
Clearly state what you aim to achieve with the animal detection system. This could include
monitoring animal health, detecting intruders, optimizing feeding processes, etc.Define the
boundaries of the project. Determine which types of animals you want to detect, the environment
(indoor, outdoor), and any specific conditions or constraints.Gather relevant data for training the
detection system. This may include images or videos of animals in farm environments. Consider
factors like lighting conditions, weather, and diversity of animals.Annotate the collected data with
appropriate labels indicating the presence and location of animals. This is crucial for supervised
learning approachesChoose appropriate sensors and cameras based on the farm environment and
requirements.Decide on the software tools and frameworks for building and deploying the detection
system. This could include TensorFlow, PyTorch, OpenCV, etc.
11
Select a suitable deep learning architecture for object detection. Options include Faster R-CNN,
YOLO (You Only Look Once), and SSD (Single Shot Multibox Detector).Train the selected model
using the annotated dataset. Fine-tune the model to adapt to farm-specific conditions if
necessaryIntegrate the trained model into the farm's infrastructure, including camera systems, data
processing pipelines, and any existing farm management software.Conduct thorough testing to ensure
the detection system performs accurately under various conditions. Evaluate its performance in
detecting different types of animals and in different lighting and weather conditions.Deploy the animal
detection system in the farm environment. Ensure proper setup and calibration of cameras and
sensors.Establish procedures for monitoring and maintaining the system. Regularly update the model
with new data to improve accuracy and adaptability.Ensure compliance with relevant regulations and
standards governing animal welfare, data privacy, and environmental protection.Consider ethical
implications such as the impact on animal behavior, privacy concerns, and potential biases in the
detection systemContinuously monitor the performance of the detection system in real-world farm
conditions. Collect feedback from farm operators and make adjustments as needed. Evaluate the
impact of the system on farm operations, such as improvements in efficiency, animal welfare, and
overall productivity.Document the project thoroughly, including the design, implementation, and
performance evaluation.
12
CHAPTER 4
FEASIBILITY STUDY
13
FEASIBILITY STUDY
Requirements are the basic constrains that are required to develop a system. Requirements are
collected while designing the system.
4. 1 Functional requirements
The software requirements specification is a technical specification of requirements for the software
product. It is the first step in the requirements analysis process. It lists requirements of a particular
software system. The following details to follow the special libraries like sk-learn, pandas, numpy,
matplotlib and seaborn.
Software Requirements:
Operating System : Windows
Tool : Anaconda with Jupyter Notebook
14
Hardware requirements:
Processor : Pentium IV/III
Hard disk : minimum 80 GB
RAM : minimum 2 GB
Conducting a feasibility study for animal detection in farms is essential to assess the viability and
potential success of the project. Here's a structured approach to conducting such a feasibility study:
2. Market Analysis:
Market Need: Analyze the market need for animal detection systems in farms. Identify any existing
solutions and their limitations.
Competitor Analysis: Evaluate competitors offering similar solutions. Determine their strengths,
weaknesses, market share, and pricing strategies.
3. Technical Feasibility:
Data Availability: Assess the availability and quality of data needed for training the detection models.
Determine if sufficient annotated data is available or can be collected.
Technology Stack: Evaluate the suitability of existing technologies such as deep learning models,
sensors, cameras, and image processing algorithms for animal detection in farm environments.
Integration: Determine the feasibility of integrating the detection system with existing farm
infrastructure such as cameras, sensors, and management software.
4. Economic Feasibility:
Cost-Benefit Analysis: Estimate the costs involved in developing, deploying, and maintaining the
animal detection system. Compare these costs with the expected benefits such as improved
productivity, reduced losses, and operational efficiency gains.
15
Return on Investment (ROI): Calculate the potential ROI of implementing the detection system over
a specific time period. Consider factors such as increased revenue, cost savings, and improved resource
utilization.
5. Operational Feasibility:
Farm Compatibility: Assess the compatibility of the detection system with different types of farms
(e.g., livestock farms, poultry farms).
Ease of Use: Evaluate the usability of the system for farm operators. Consider factors such as user
interface design, training requirements, and ease of maintenance.
Scalability: Determine if the detection system can scale to accommodate farms of different sizes and
configurations.
7. Risk Analysis:
Identify Risks: Identify potential risks and challenges associated with implementing the detection
system, such as technical challenges, data privacy concerns, and market acceptance.
Mitigation Strategies: Develop mitigation strategies to address identified risks and minimize their
impact on the project's success.
16
4.4 Algorithms
4.4.1 CNN Convolutional Neural Network
Convolutional Neural Networks (CNNs) have revolutionized the field of image recognition and
classification, and their application extends beyond human subjects to include the identification and
categorization of animal species. One prominent use of CNNs in animal species classification is in
wildlife conservation efforts. Researchers and conservationists employ CNNs to analyze images and
videos captured by camera traps, drones, or other monitoring devices in natural habitats. The CNNs
can automatically detect and classify different animal species based on their unique features, markings,
and behavioral patterns.
In the realm of biology and ecology, CNNs play a crucial role in automating the process of species
identification. Traditionally, scientists relied on manual observation and analysis, which was time-
consuming and prone to errors. With CNNs, vast amounts of data can be processed quickly and
accurately, allowing for the identification of various animal species based on subtle characteristics
such as fur patterns, coloration, and body shapes. This not only enhances the efficiency of research but
also contributes to a better understanding of biodiversity and ecological dynamics.
CNNs are also utilized in the monitoring and management of livestock. By employing CNN-based
image recognition systems, farmers and veterinarians can identify individual animals, track their health
and behavior, and implement targeted interventions. This technology aids in preventing the spread of
diseases, optimizing breeding programs, and enhancing overall farm productivity.
Moreover, CNNs facilitate the automated analysis of underwater imagery for marine species
classification. Marine biologists can use CNNs to process images from underwater cameras and
identify different species of fish, coral, and other marine organisms. This application of CNNs in
marine biology contributes to our knowledge of underwater ecosystems, helping to monitor and
preserve marine biodiversity.
17
4.4.2. Transfer Learning
Transfer learning has proven to be a powerful technique in the field of animal species classification,
leveraging pre-trained neural network models to enhance the performance of classifiers on new and
diverse datasets. In the realm of computer vision, particularly image classification, transfer learning
allows models to leverage knowledge gained from one task and apply it to another. This approach is
highly beneficial in the context of animal species classification, where obtaining large labeled datasets
can be challenging and time-consuming.
One key advantage of transfer learning in animal species classification is the ability to utilize pre-
trained models on general image recognition tasks. Models such as ResNet, Inception, or VGG, trained
on massive datasets like ImageNet, have learned generic features that can be valuable across various
domains. By fine-tuning these models on a specific animal dataset, the neural network can adapt its
knowledge to recognize distinctive features and patterns relevant to different species. This process
significantly reduces the need for extensive labeled data specific to the target task, making it more
feasible to apply machine learning techniques to wildlife conservation efforts.
Furthermore, transfer learning facilitates the adaptation of models to varying degrees of data
availability for different species. In cases where data for certain species are scarce, transfer learning
enables the knowledge gained from abundant data of other species to be transferred, improving the
classification accuracy for less-represented classes. This adaptability is crucial for building robust
models capable of handling the inherent imbalances in wildlife datasets.
Another aspect where transfer learning excels in animal species classification is its efficiency in
training. Pre-trained models have already learned low-level features that are common across different
datasets, allowing the fine-tuning process to focus on higher-level, species-specific features. This not
only speeds up training but also enhances the model's ability to generalize well to unseen data, a crucial
factor in real-world applications where new species may be discovered or data may come from diverse
sources.
4.4.3 ResNet152V2
ResNet152V2, a powerful deep neural network architecture, has proven to be highly effective in
various computer vision tasks, including animal species classification. Its remarkable performance can
be attributed to its deep structure, which enables the model to learn intricate features and patterns from
18
complex images. In the context of animal species classification, ResNet152V2 offers several
advantages that contribute to its success.
Firstly, ResNet152V2's depth allows it to capture hierarchical features at different abstraction levels.
This is crucial in animal species classification, where distinct characteristics and subtle details may be
spread across multiple layers of an image. The network's ability to automatically extract relevant
features aids in discriminating between different species based on visual cues, such as coloration,
morphology, and patterns.
Secondly, ResNet152V2 employs residual connections, which facilitate the training of very deep
networks. The residual connections mitigate the vanishing gradient problem, enabling more efficient
and effective training. In animal species classification, where datasets can be diverse and extensive,
the ability of ResNet152V2 to handle deep architectures is particularly beneficial for learning complex
relationships within the data.
Moreover, the pre-trained weights of ResNet152V2 on large-scale image datasets, such as ImageNet,
serve as a valuable starting point for transfer learning. By fine-tuning the model on a specific animal
species classification dataset, the network can leverage its prior knowledge to adapt and specialize in
recognizing features relevant to different species. This transfer learning approach is especially
advantageous when working with limited annotated data for specific animal species.
ResNet152V2 has demonstrated its effectiveness in animal species classification through its deep
architecture, residual connections, pre-trained weights, and batch normalization. These features
collectively empower the model to learn intricate patterns and relationships within images, making it
a robust solution for recognizing and categorizing diverse animal species based on visual
characteristics.
19
4.4.4 XCEPTION
Using the Xception model for animal detection on farms can be a promising approach due to its
effectiveness in image classification tasks. Xception is a deep convolutional neural network
architecture that has shown excellent performance on various computer vision tasks, including image
classification, object detection, and feature extraction. Here's how you could apply Xception for animal
detection on farms
Gather a diverse dataset of farm animal images captured from cameras or sensors placed around the
farm. Ensure the dataset covers various lighting conditions, angles, and backgrounds to make the
model robust.
Preprocess the collected images by resizing them to a consistent resolution and normalizing pixel
values to improve model convergence. Augment the dataset with techniques like rotation, flipping, and
cropping to increase the model's generalization ability.
Utilize transfer learning by initializing the Xception model with pre-trained weights on a large dataset
like ImageNet.Fine-tune the model on the farm animal dataset to adapt it to the specific features and
characteristics of farm animals.
Split the dataset into training, validation, and testing sets to evaluate the model's performance.Use
metrics such as accuracy, precision, recall, and F1-score to assess the model's ability to detect farm
animals.
Deploy the trained Xception model onto the farm's infrastructure, considering factors like
computational resources and latency requirements.Implement real-time inference to process incoming
images or video streams from farm cameras.
Monitor the deployed model's performance over time and retrain it periodically with new data to
ensure its accuracy and reliability.Implement mechanisms for handling model drift and concept drift
caused by changes in the farm environment or animal behavior.
Integrate the animal detection system with existing farm management software to provide farmers
with insights into animal presence, movement, and behavior. Enable alerts and notifications to be sent
to farmers when unusual activities or events are detecte
Design the system to scale seamlessly as the farm grows or additional sensors are added. Ensure the
flexibility to incorporate new features or adapt to changes in farm operations and infrastructure.
Implement security measures to protect sensitive data collected by the animal detection system.
Ensure compliance with regulations regarding data privacy and handling of farm animal
information.
20
4.4.5 INCEPTION
Inception, or specifically Inception-v3, is a convolutional neural network (CNN) architecture that has
been widely used for image classification tasks, including object detection. When applied to animal
detection on farms, Inception can play a significant role in accurately identifying and localizing
animals within images captured by cameras or sensors. Here's how Inception can be utilized in the
context of animal detection on farms:
Inception-v3 is capable of extracting high-level features from images using its deep convolutional
layers. These features capture various patterns and textures present in the images, which are essential
for distinguishing different types of animals and their surroundings.
Pre-trained versions of Inception-v3 are often available, trained on large-scale image datasets like
ImageNet. Transfer learning can be employed by fine-tuning the pre-trained Inception model on a
smaller dataset containing images specific to the farm environment and the types of animals present.
Transfer learning allows the model to leverage knowledge learned from general image recognition
tasks and adapt it to the specific characteristics of farm animal detection.
Inception-v3, like other CNN architectures, is capable of not only classifying images but also
localizing objects within them. This localization capability can be useful for detecting animals'
positions within farm scenes, enabling precise tracking and monitoring.
Inception-v3 is designed to detect multiple objects within a single image simultaneously. This
capability is beneficial for farms where multiple animals may be present in a single frame captured by
the camera.
The model can identify and classify each animal individually, providing valuable information about
the types and quantities of animals present in the farm environment.
Inception-v3 can be integrated into existing farm monitoring systems to automate the process of
animal detection and reduce manual labor.
By deploying Inception-v3 on edge devices or cloud platforms, farms can achieve real-time or near-
real-time animal detection, allowing prompt response to any detected anomalies or events.
Inception-v3 offers a balance between computational efficiency and accuracy, making it suitable for
deployment on resource-constrained devices commonly used in farm environments.
The model architecture is scalable, allowing farms to process large volumes of image data efficiently,
even as the farm scales up in size or complexity.
Inception-v3 can be continually improved and fine-tuned as more data becomes available and as the
farm environment changes over time.
21
Regular retraining of the model with new data ensures that it remains accurate and reliable in
detecting animals under varying conditions and scenarios.
In summary, Inception-v3 can serve as a powerful tool for animal detection on farms, offering robust
performance, scalability, and the ability to adapt to diverse farm environments and animal species. By
leveraging its features through transfer learning and integration with farm monitoring systems, farms
can enhance their operational efficiency, productivity, and animal welfare.
4.4.6 TensorFlow and Convolutional Neural Network
TensorFlow, an open-source machine learning library, and Convolutional Neural Networks (CNNs)
have proven to be powerful tools in the field of animal species classification. This advanced technology
enables researchers and conservationists to automate the process of identifying and categorizing
different species based on images.
Firstly, TensorFlow provides a flexible and efficient platform for building, training, and deploying
machine learning models, making it an ideal choice for implementing CNNs.
CNNs are particularly well-suited for image classification tasks due to their ability to automatically
learn hierarchical features from input images. These features are crucial in capturing the unique
characteristics and patterns associated with various animal species.
In the context of animal species classification, a CNN's architecture typically includes convolutional
layers that specialize in detecting local patterns and hierarchical feature extraction. These layers are
followed by pooling layers to reduce dimensionality and flatten the learned features. TensorFlow
simplifies the implementation of such architectures, allowing researchers to focus on the design and
optimization of the model rather than low-level details.
Moreover, TensorFlow's compatibility with GPUs and TPUs enhances the training speed of CNNs,
enabling the processing of large datasets efficiently. This is essential in animal species classification,
where diverse datasets encompassing various habitats, lighting conditions, and species are crucial for
building robust models. TensorFlow's distributed computing capabilities also facilitate scaling up the
training process to handle vast amounts of data.
In the actual application of TensorFlow and CNNs to animal species classification, the model is trained
on labeled datasets containing images of different species. During training, the CNN learns to
recognize distinctive features and patterns that distinguish one species from another. Transfer learning
techniques can also be employed, leveraging pre-trained models on large datasets and fine-tuning them
for specific animal species classification tasks. The trained model can then be used to classify new,
22
unseen images, aiding researchers, conservationists, and wildlife monitoring programs in identifying
and tracking various animal species efficiently.
The combination of TensorFlow and Convolutional Neural Networks revolutionizes animal species
classification by providing a powerful, scalable, and efficient solution. This technology not only
automates the identification process but also contributes to conservation efforts, wildlife monitoring,
and ecological research by providing accurate and timely insights into the diverse world of animal
species. The continuous advancements in machine learning and deep learning, coupled with the
versatility of TensorFlow, ensure that these tools will remain at the forefront of efforts to understand
and protect Earth's biodiversity.
4.5 Python
Python is a widely used general-purpose, high level programming language. It was created by Guido
van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with
an emphasis on code readability, and its syntax allows programmers to express their concepts in fewer
lines of code.
Python is a programming language that lets you work quickly and integrate systems more efficiently.
There are two major Python versions: Python 2 and Python 3. Both are quite different.
23
Simple
● Closer to English language;Easy to Learn
● More emphasis on the solution to the problem rather than the syntax
Embeddable
● Python can be used within C/C++ program to give scripting capabilities for the program’s user.
Robust:
● Exceptional handling features
● Memory management techniques in built
24
Pandas are also able to delete rows that are not relevant, or contains wrong values, like empty or NULL
values. This is called cleaning the data.
4.5.2.2 Numpy
NumPy is a Python library used for working with arrays.
It also has functions for working in domain of linear algebra, fourier transform, and matrices.
NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely.
NumPy stands for Numerical Python.
In Python we have lists that serve the purpose of arrays, but they are slow to process.
NumPy aims to provide an array object that is up to 50x faster than traditional Python lists.
The array object in NumPy is called ndarray, it provides a lot of supporting functions that make
working with ndarray very easy.
Arrays are very frequently used in data science, where speed and resources are very important.
NumPy is a Python library and is written partially in Python, but most of the parts that require fast
computation are written in C or C++.
3.5.2.3 matplotlib
Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
Matplotlib was created by John D. Hunter.
Matplotlib is open source and we can use it freely.
Matplotlib is mostly written in python, a few segments are written in C, Objective-C and Javascript
for Platform compatibility.
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-
platform data visualization library built on NumPy arrays and designed to work with the broader SciPy
stack. It was introduced by John Hunter in the year 2002. One of the greatest benefits of visualization
is that it allows us visual access to huge amounts of data in easily digestible visuals. Matplotlib consists
of several plots like line, bar, scatter, histogram, etc
4.5.2.4 seaborn
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface
for drawing attractive and informative statistical graphics.
25
seaborn is a library for making statistical graphics in Python. It provides a high-level interface to
matplotlib and integrates closely with pandas data structures. Functions in the seaborn library expose
a declarative, dataset-oriented API that makes it easy to translate questions about data into graphics
that can answer them. When given a dataset and a specification of the plot to make, seaborn
automatically maps the data values to visual attributes such as color, size, or style, internally computes
statistical transformations, and decorates the plot with informative axis labels and a legend. Many
seaborn functions can generate figures with multiple panels that elicit comparisons between
conditional subsets of data or across different pairings of variables in a dataset. seaborn is designed to
be useful throughout the lifecycle of a scientific project. By producing complete graphics from a single
function call with minimal arguments, seaborn facilitates rapid prototyping and exploratory data
analysis. And by offering extensive options for customization, along with exposing the underlying
matplotlib objects, it can be used to create polished, publication-quality figures.
4.5.2.4 tensorflow
TensorFlow is an open-source library for fast numerical computing.
It was created and is maintained by Google and was released under the Apache 2.0 open source license.
The API is nominally for the Python programming language, although there is access to the underlying
C++ API.
Unlike other numerical libraries intended for use in Deep Learning like Theano, TensorFlow was
designed for use both in research and development and in production systems, not least of which
is RankBrain in Google search and the fun DeepDream project.
It can run on single CPU systems and GPUs, as well as mobile devices and large-scale distributed
systems of hundreds of machines.
4.5.2.4 keras
Keras runs on top of open source machine libraries like TensorFlow, Theano or Cognitive Toolkit
(CNTK). Theano is a python library used for fast numerical computation tasks. TensorFlow is the most
famous symbolic math library used for creating neural networks and deep learning models.
TensorFlow is very flexible and the primary benefit is distributed computing. CNTK is deep learning
framework developed by Microsoft. It uses libraries such as Python, C#, C++ or standalone machine
learning toolkits. Theano and TensorFlow are very powerful libraries but difficult to understand for
creating neural networks.
26
Keras is based on minimal structure that provides a clean and easy way to create deep learning models
based on TensorFlow or Theano. Keras is designed to quickly define deep learning models. Well,
Keras is an optimal choice for deep learning applications.
Features
● Keras leverages various optimization techniques to make high level neural network API easier
and more performant. It supports the following features −
● Consistent, simple and extensible API.
● Minimal structure - easy to achieve the result without any frills.
● It supports multiple platforms and backends.
● It is user friendly framework which runs on both CPU and GPU.
● Highly scalability of computation.
Benefits
● Keras is highly powerful and dynamic framework and comes up with the following advantages
● Larger community support.
● Easy to test.
● Keras neural networks are written in Python which makes things simpler.
● Keras supports both convolution and recurrent networks.
● Deep learning models are discrete components, so that, you can combine into many ways.
27
CHAPTER 5
METHODOLOGY
28
METHODOLOGY
Animal Recognition algorithm (image classifier) is deep learning model which takes images (or a batch
of the image) from user, process it and gives numeric values (probabili At last, it gives output what the
image contains using features that it have learned during training phase. In other words, the output is
a class label (cat , cow , horse etc.).
In figure 4.1, training images and test images are passed to pre-processing module. Pre-processed
matrix is then passed in convolution Neural Network architecture where operations such as
convolution, max pooling, flatten happens. After flattening, all training data are passed in fully
connected layer where classification and optimization was done. At last, all weights and biases were
saved into a .h5 files to predict animals later. But in testing phase, test images were used to test the
system with same architecture
The term "CNN" typically refers to Convolutional Neural Networks, a type of deep
learning algorithm commonly used in computer vision tasks like image recognition. In the context of
animal detection on farms, CNNs can be employed to identify and classify animals based on images
or video footage.
Here's a simplified overview of how CNNs might be used for animal detection on farms:
29
1. Data Collection: Gather a dataset of labeled images containing various animals commonly found on
farms (e.g., cows, chickens, pigs).
2. Data Preprocessing: Resize, normalize, and augment the images to ensure consistency and improve
the model's ability to generalize.
3. Model Architecture: Design a CNN architecture. This usually involves a series of convolutional
layers, pooling layers, and fully connected layers. The convolutional layers extract features from the
images.
4. Training: Use the labeled dataset to train the CNN. During training, the model learns to recognize
patterns and features that distinguish different animals.
5. Validation and Testing: Evaluate the model on a separate set of data it has never seen before
(validation set) to ensure it's not overfitting. Then, test it on a completely new dataset (test set) to assess
its real-world performance.
6. Fine-tuning and Optimization: Adjust hyperparameters, model architecture, or other factors based
on validation results to improve performance.
7. Deployment: Once satisfied with the model's performance, deploy it on the farm. This might involve
using specialized hardware or integrating it into existing farm management systems.
8. Real-time Inference: The deployed model can now process live video feeds or images from cameras
on the farm and make real-time predictions about which animals are present.
Remember, the success of such a system depends on factors like the quality and diversity of the training
data, the chosen architecture, and the suitability of the model for the specific farm environment.
Additionally, it's crucial to consider ethical and privacy implications when implementing
such technologies.
In a Convolutional Neural Network (CNN) used for animal detection on farms, there are several types
of layers that work together to process and analyze images. Here are the key layers commonly used in
a CNN:
30
1. Input Layer: This layer takes in the raw image data. Each neuron in this layer represents a pixel
value.
2. Convolutional Layers: These layers are responsible for extracting features from the input images.
They apply a set of filters (also called kernels) to the input, which helps identify patterns like edges,
corners, and textures.
3. Activation Function: Usually applied after each convolutional layer, an activation function
introduces non-linearity into the model, allowing it to learn more complex relationships. Common
activation functions include ReLU (Rectified Linear Unit), Sigmoid, and Tanh.
4. Pooling Layers: Pooling layers downsample the spatial dimensions of the feature maps produced by
the convolutional layers. This reduces the computational load and focuses on the most important
features. Max pooling and average pooling are common techniques.
5. Fully Connected Layers (or Dense Layers): These layers connect every neuron in the current layer
to every neuron in the previous and subsequent layers. They are typically found at the end of the
network and are responsible for making predictions based on the extracted features.
6. Flatten Layer: Before transitioning from convolutional layers to fully connected layers, a Flatten
layer is used to convert the multidimensional feature maps into a one-dimensional vector.
7. Dropout Layer (Optional): Dropout is a regularization technique where randomly selected neurons
are ignored during training. This helps prevent overfitting.
8. Output Layer: The final layer of the CNN provides the output of the network. In animal detection,
it might consist of neurons corresponding to different classes of animals (e.g., cow, pig, chicken), and
typically employs a soft max activation function to convert the network's outputs into probability
scores.
These layers work together through forward propagation during training, where the model learns to
recognize patterns and features relevant to animal detection. It's worth noting that the specific
architecture and the number of layers can vary depending on the complexity of the task and the size
31
and quality of the dataset available. Additionally, techniques like transfer learning can be employed to
leverage pre-trained models for similar tasks.
In the above example ,the detected animal is dog and the dog image is converted into matrix and the
following operations is done on that matrix , i.e Convolution and Max Pooling .These are the
operations that are used to identify the features and patterns of the dog image. After these operations
are done the matrixes size will become smaller and it is passed to fully connected layer. In this layer
we will get the matrix and that matrix is compared with the dataset with in the system .if both are
matched ,then it will give the output as a dog.
5.1. Dataset
Since Convolution Neural network is Supervised Machine Learning technique, a large amount of
labeled data (images) are needed for the purpose of training. The datasets were obtained from Kaggl
and WSID-100[5] repository. From kaggle repository, Animal-10 dataset[3] and Monkey species[4]
were used and rest of the data were taken from WSID-100 having similar feature as Kaggle dataset.
All together 2000 images were taken for each class. For testing, 200 images were taken. Thus, the
dataset classes consist of elegant, chicken, cow, sheep, dog, cat, horse, monkey, squirrel and spider
with 2000 images per class and a total of 20000 images were taken
32
5.2 Pre-processing
Image pre-processing is the method to enhance image or extract some useful information. For pre-
processing images, pre-processing module was used. In pre-processing module, images were read from
directory, 3D images were converted into grayscale by using weighted or luminosity method/
algorithm as it is easy to compute and system learn from geometry, images were reshaped into 200 *
200 sizes using LINEAR Interpolation and each image was normalized by divided with maximum
channel values i.e. 255 to convert values into float32.
33
5.4. Machine learning algorithms
The objective of this work is to analyze the possibilities offered by machine learning algorithms as
tools for rain forecasting as an alternative to classical forecasting methods. For this, the following
algorithms were applied: KNN, decision tree, random forest, and neural networks. The algorithms are
described below.
Data Collection:
Image Data:
Gather a dataset of images containing various animals commonly found on farms, such
as cows, sheep, chickens, etc. These images should cover different angles, lighting conditions, and
poses to ensure robustness.
Labeling:
Annotate the images with corresponding labels indicating the animal species present in each
image
Feature Extraction:
Image Preprocessing:
Preprocess the images to standardize their size, color, and orientation. This step helps
in reducing the impact of variations in image characteristics.
Feature Extraction:
Extract relevant features from the preprocessed images. These features could include color
histograms, texture descriptors, or deep learning-based features extracted from pre-trained
convolutional neural networks (CNNs).
34
Model Training:
k-NN Classifier:
Train a k-NN classifier using the extracted features from the labeled images. In the k-
NN algorithm, the class of an unlabeled image is determined by a majority vote among its k nearest
neighbors in the feature space.
Parameter Tuning:
Experiment with different values of k and distance metrics (e.g., Euclidean distance,
cosine similarity) to optimize the classifier's performance.
Evaluation Metrics:
Evaluate the performance of the k-NN classifier using standard evaluation metrics such
as accuracy, precision, recall, and F1-score.
Cross-Validation:
Employ techniques like k-fold cross-validation to assess the generalization performance
of the classifier and mitigate overfitting.
Deployment:
Continuous Improvement:
Data Augmentation:
Continuously augment the training dataset with new images to improve the classifier's
robustness and generalization ability.
35
Model Updates:
Periodically retrain the k-NN classifier with updated datasets or fine-tune its parameters
to adapt to changing farm conditions and requirements.
Feedback Loop:
Gather feedback from farm operators to identify areas for improvement and adjust the
detection system accordingly.
Ethical Considerations:
Privacy:
Ensure that the surveillance system respects the privacy of farm animals and adheres to
ethical guidelines regarding data collection and usage.
Bias Mitigation: Take measures to mitigate biases in the classifier that may disproportionately affect
certain animal species or farm environments.
By following these steps, k-NN can be effectively utilized for animal detection on farms, helping to
improve livestock management, enhance farm security, and streamline farm operations.
36
elements are equally distributed in different classes. In this sense, when generating a decision tree, it
is preferred to choose the variable with the smallest possible Gini index as the root element.
37
of input–output. In this sense, according to the direction of the information in the neural network, they
can be classified as either a [48] Feedforward network (unidirectional information flow) or a recurrent
network (information flow in both directions using loops and delays. Finally, the learning algorithm
in a network specifies how to apply the weights that depend on the learning paradigm (it depends on
the information available to the network, so that it can be supervised if the expected output is known
or unsupervised if the expected output is not known), the learning rules, and the type of learning
algorithm (they can be based on error minimization, based on random parameters, based on
competitive strategies, or based on Hebb’s law). Although the learning process (setting the weights) is
complex, it has the advantage that, once learned, the network keeps the weights.
(1)
where:
TP: True Positive. Result in which the model correctly predicts the positive class.
FP: False Positive. Result in which the model incorrectly predicts the positive class.
TN: True Negative. Result in which the model correctly predicts the negative class.
FN: False Negative. Result in which the model incorrectly predicts the negative class.
2. Kappa statistic
It measures the agreement between two examiners in their corresponding classifications of N elements
into C mutually exclusive categories. In the case of machine learning, it refers to the actual class and
the class expected by the model used. It is calculated as follows:
38
Where:
Pr (a) is the observed relative agreement between observers, and Pr (e) is the hypothesized probability
of agreement by chance, using the observed data to compute the probabilities that each observer
randomly ranks each category. If raters fully agree, then κ = 1. If there is no agreement between raters
other than what would be expected by chance (as defined by Pr (e)), then κ = 0.
3. Logarithmic Loss
It is the negative average of the log of corrected predicted probabilities for each instance. It is
calculated as follows:
(3)
where:
N is the number of samples.
M is the number of classes.
yij, indicates if the sample i belongs to the class j or not.
pij, indicates the probability that the sample i belongs to the class j.
4. Error
The error gives an indication of how far the predictions are from the actual output. There are two
formulas: Mean Absolute Error (MAE) and Mean Squared Error (MSE). It is calculated as follows:
(4)
(5)
where:
N corresponds to the total number of samples.
𝑦𝑘 corresponds to the class indicated by the classification model.
𝑦𝑘̂^ corresponds to the actual class.
39
5. Sensitivity
The sensitivity of a model (or the ratio of true positives) measures the proportion of correctly classified
positive examples. The total number of positives is the sum of those that were correctly classified and
those that were incorrectly classified. It is calculated as follows:
(6)
where:
TP: True Positive. Result in which the model correctly predicts the positive class.
TN: True Negative. Result in which the model correctly predicts the negative class.
FN: False Negative. Result in which the model incorrectly predicts the negative class.
6. Specificity
The specificity of a model (or the ratio of true negatives) measures the proportion of correctly classified
negative examples. The total number of negatives is the sum of those that were correctly classified and
those that were incorrectly classified. It is calculated as follows:
(7)
where:
TP: True Positive. Result in which the model correctly predicts the positive class.
FP: False Positive. Result in which the model incorrectly predicts the positive class.
TN: True Negative. Result in which the model correctly predicts the negative class.
7. Precision
Precision is defined as the proportion of examples classified as positive that are actually positive. That
is, when a model predicts values as positive. It is calculated as follows:
(8)
where:
TP: True Positive. Result in which the model correctly predicts the positive class.
TN: True Negative. Result in which the model correctly predicts the negative class.
40
FN: False Negative. Result in which the model incorrectly predicts the negative class.
8.
Recall
Recall is defined as the number of correctly classified positives over the total number of positives. This
formula is the same as that for sensitivity. It is calculated as follows:
(9)
where:
TP: True Positive. Result in which the model correctly predicts the positive class.
FP: False Positive. Result in which the model incorrectly predicts the positive class.
TN: True Negative. Result in which the model correctly predicts the negative class.
9. F-measure
F-measure is a measure of model performance that combines precision and recall into a value called
F-measure (also called F1 score or F-score). This measure combines precision and recall using
harmonic averaging, which is used for ratios. This type of averaging is used instead of arithmetic, since
precision and recall are expressed as proportions between 0 and 1, which can be interpreted as ratios.
It is calculated as follows:
41
CHAPTER 6
SYSTEM DESIGN
42
SYSTEM DESIGN
In neural networks, convolutional neural network is one of the main categories used for images
recognition, images classifications. In 1995, Yann LeCun and Yoshua Bengio introduced the concept
of convolutional neural networks to classify the image successfully and for recognizing handwritten
control numbers by Lenet-5 [2]. LeCun’s convolutional neural networks [11] are organized in a
sequence of alternating two types of layers S-layers and C-layers, called convolution and subsampling
with one or more fully connected layers (FC) in the ends.
Convolutional Neural Networks are a special kind of multi-layer neural networks, they follow the path
of its predecessor neocognitron in its shape, structure, and learning philosophy [3]. Traditionally,
neural networks convert input data into a one-dimensional vector [4], and they have the ability to
perform both feature extraction and classification. The input layer receives normalized images with
the same sizes [2]. Each input image will pass through a series of convolution layers with filters
(Kernels), Pooling, fully connected layers (FC) and apply activation function to classify an object with
probabilistic values. Figure 5.1 shows a complete flow of CNN to process an input image and classifies
the objects based on values [10].
43
Here in this project the system architecture includes the following:
Data Collection:
Cameras or sensors placed strategically across the farm capture images or data about the animals.
Ddrones or satellite imagery can also be used for larger farms.
Data Preprocessing:
Raw data from cameras or sensors may need preprocessing to enhance quality and reduce noise.
Image data might require resizing, normalization, or augmentation.
2. Deployment:
Deploy the trained model onto the farm's infrastructure, which could be on-site servers, edge
devices, or cloud platforms.
Consider the computational resources available and choose a deployment option accordingly.
3. Real-time Inference:
Process the incoming data (images or sensor readings) through the deployed model in real-time
to detect animals.
Make use of efficient algorithms and hardware optimizations to achieve low latency.
4. Post-processing:
Analyze the results of the detection to filter out false positives and refine the output.
Aggregate data over time to identify patterns in animal behavior.
44
the system.
Generate reports summarizing animal counts, movements, or health conditions over specific
periods.
6. Integration with Farm Management Systems:
Integrate the animal detection system with existing farm management software or IoT platforms for
centralized monitoring and control.
Allow farmers to access detection results and insights through user-friendly interfaces, including
mobile apps or web dashboards.
7. Feedback Loop:
continuously collect feedback from users and monitor system performance.
Incorporate mechanisms for retraining the detection model with new data to adapt to changing
environmental conditions or animal behaviors.
There are several types of UML diagrams, each serving a specific purpose and focusing on different
aspects of the system being modeled. Some common types of UML diagrams include:
45
1. Use Case Diagram: Illustrate the interactions between users (actors) and the system, showing the
various use cases or functionalities of the system.
2. Class Diagrams: Describe the static structure of the system by representing classes, their attributes,
methods, and relationships.
3. Sequence Diagrams: Show the interactions between objects or components in the system over time,
depicting the sequence of messages exchanged.
4. Activity Diagrams: Represent the flow of activities or processes within the system,showing the
sequence of actions and decision points.
5. State Machine Diagrams: Model the dynamic behavior of a single object or entity, showing the
different states and transitions it can undergo.
6. Deployment Diagrams: Illustrate the physical deployment of system components and their
relationships, indicating how the software and hardware are distributed across different nodes.
7. Component Diagrams: Describe the components, interfaces, and dependencies of the system,
focusing on the organization and structure of the software components.
8. Package Diagrams: Show the organization and dependencies between packages or namespaces in
the system, providing a high-level view of the system's architecture.
These diagrams, among others, help stakeholders understand different aspects of the system being
modeled, facilitating communication, analysis, design, and implementation throughout the software
development lifecycle.
46
6.2.1 Use Case diagram
A use case diagram in the Unified Modeling Language (UML) is a type of behavioral diagram defined
by and created from a Use-case analysis. Its purpose is to present a graphical overview of the
functionality provided by a system in terms of actors, their goals (represented as use cases), and any
dependencies between those use cases. The main purpose of a use case diagram is to show what system
functions are performed for which actor. Roles of the actors in the system can be depicted.
The above diagram is used to describe about the animal detection in farms using convolutional
neural networks. In this diagram the user has to login into the application the system has
preprocessor and covert into binary format and detect the edges and features of the image.
After the preprocessing of the image the system sends the result of the image to the user.
47
Identify Actors
1.Farm Operator:
The primary user who interacts with the animal detection system to monitor livestock,
detect intruders, or manage farm operations.
2.Animals:
Though not active users, animals are entities that the system interacts with through detection
processes.
3.System Administrator:
Responsible for managing and maintaining the animal detection system, including
updates, configurations, and troubleshooting.
Define Use Cases:
The system detects movement or unusual activity near the farm perimeter
using surveillance cameras.If an intruder or predator is detected, the system triggers an
alarm and sends an alert to the farm operator.The farm operator receives the alert, views
live camera feeds, and takes necessary steps to address the threat, such as contacting
authorities or activating deterrents.
Specify Use Case Details
1.Preconditions:
Conditions that must be true before a use case can be executed, such as the
availability of camera feeds and sensor data.
2.Postconditions:
Desirable outcomes or states after the execution of a use case, such as sending an
alert to the farm operator or recording detection events in the system log.
49
3.Exceptions:
Possible deviations or errors that may occur during use case execution, such as loss of
camera connectivity or false alarms triggered by environmental factors.
Sequence diagram:
50
➢ User collects all the animal images
➢ User divides images as training and testing data and stores in the data storage
➢ Then creates a CNN model
➢ In cnn we have different modules
➢ Pooling layer
➢ Relu layer
➢ Convolutional layer
➢ Activation layer
➢ Full connecting layers
➢ CNN MODEL is used to extract all the features of all the images
➢ It is used to train the model
➢ It generates the report performance
➢ It predicts the images
➢ And it is used to transform the matrix format into the picture format
➢ The resultant picture will send to the users
51
Activity diagrams are graphical representations of workflows of stepwise activities and actions
with support for choice, iteration and concurrency. In the Unified Modeling Language, activity
diagrams can be used to describe the business and operational step- bystep workflows of
components in a system. An activity diagram shows the overall flow of control.
The process begins when the system is activated, either manually by the user or automatically
based on a predefined schedule or trigger.
The system initiates the process by capturing data from sensors, cameras, or other monitoring
devices installed on the farm.
Raw data is preprocessed to enhance quality and prepare it for analysis. This may include steps
such as noise reduction, normalization, and image enhancement.
The preprocessed data is fed into the animal detection model, which identifies and localizes
animals within the captured images or sensor readings.
This stage involves running the detection algorithm on the data and obtaining detection results.
The detection results undergo post-processing to filter out false positives, refine the output, and
aggregate data over time.
This step may involve analyzing the detected animals' movements, behavior patterns, and
health conditions.
Based on the detection results and analysis, the system makes decisions regarding any actions
that need to be taken.
For example, if unusual activity is detected, the system may trigger alerts or notify farm
personnel.
If abnormal behavior or events are detected, the system generates alerts to notify relevant
stakeholders, such as farmers or farm managers.
Additionally, the system may generate reports summarizing detection results and insights for
further analysis.
52
CHAPTER 7
SOURCE CODE
53
SOURCE CODE:
import os import keras
# Data Viz
plotly.express as px
Callbacks
Learning Models
Path
Names
\n{class_names}")
Distribution : \n{class_dis}")
import plotly.express as px
plt.figure(figsize=(10,5))
54
sns.barplot(x=class_names, y=class_dis) plt.grid()
plt.show()
vertical_flip=True,rotation_range=20,validation_split=0.2)
# Load data
plt.title(title)
plt.axis('off')# It's time to understnad the dataset by plotting it's contents. def
get_random_data(data):
plt.figure(figsize=(20,20)) i=1
# Plot it
plt.subplot(5,5,i)
i+=1
plt.show()
55
resnet152V2 = Sequential([ base_model,GAP(), Dense(256, activation='relu'), Dropout(0.2)
# # Compile resnet152V2.compile(loss='sparse_categorical_crossentropy',
optimizer='adam',metrics=['accuracy']) # # Callbacks
cbs = [
+ ".keras", save_best_only=True)
callbacks=cbs
# # Pretrained Model
# # Model
activation='softmax')], name=name)
# # Compile
inception.compile(loss='sparse_categorical_crossentropy',optimizer='adam', metrics=['accuracy']) # #
Callbacks
cbs = [
+ ".keras", save_best_only=True)
callbacks=cbs}
56
CHAPTER 8
SYSTEM TESTING
57
SYSTEM TESTING
Testing is the approach of seeking to comprehend each feasible fault or weak point in an
attempt product. It gives a manner to test the capability of components, sub assembles,
gatherings and/or an ended product it's far the manner of exercise software program with the
stanch of verifying that software program device stumble upon its requirements and consumer
potentials and does now no longer fail in an unacceptable manner. There are diverse forms of
check. Each check kind addresses a specific checking out requirement.
Here are some key points to consider when documenting testing in your project:
1.Test Plan: Describe the overall test plan for your project. This includes the objectives,
scope, and approach of testing. Outline the different types of testing you performed, such as
functional testing, integration testing, and user acceptance testing.
2.Test Cases: Provide a list of test cases that cover different scenarios and functionalities of
your application. Each test case should include a description of the scenario, the expected
outcome, and the steps to reproduce the test.
You can categorize test cases based on different modules or features of the Application
1.Test Environment: Specify the test environment in which the testing was conducted.
Include details about the hardware, software, and dependencies required for testing. This
helps ensure that others can replicate the testing environment if needed.
2.Test Execution: Describe how the tests were executed, including the tools and frameworks
used for test automation, if applicable. Provide details on any test data or test scenarios that
were specifically used during testing. Mention any issues or challenges encountered during the
testing phase and how they were resolved.
58
3.Test Results: Document the results of the tests, including any discrepancies or bugs identified
during testing. If possible, provide screenshots or logs that demonstrate the test results. Include
information on how the identified issues were addressed, whether through bug fixes, code
modifications, or other means.
4.Coverage: Mention the code coverage achieved during testing, indicating the percentage
of code that was tested. This can help assess the thoroughness of your testing efforts.
5.Performance and Load Testing: If you conducted performance or load testing, provide
details about the test scenarios, metrics measured (e.g., response time, throughput), and
the performance thresholds 53 defined for your application.
6.User Acceptance Testing: If user acceptance testing was performed, highlight the
involvement of end users or stakeholders, and summarize their feedback and satisfaction with
the application.
7.Regression Testing: Mention any regression testing that was performed to ensure that new
changes or fixes did not introduce new issues or break existing functionality.
8.Known Issues: Document any known issues or limitations of the application that were
identified during testing but were not addressed. Include any workarounds or plans for future
improvements.
59
8.2 TYPES OF TESTS
• Unit Testing
• Integration Testing
• Functional Testing
• System Testing
• Security Testing
• Performance Testing
• Regression Testing
• Stress Testing
• Acceptance Testin
60
8.2.1 UNIT TESTING
Unit testing out accommodates the layout of check instances that authenticate that the inner
software good judgment is functioning properly, and that software inputs yield legitimate
outputs. end branches and inner code glide ought to be validated. It is the trying out of
particular software program devices of the application. It's miles achieved after the success of a
man or woman unit earlier than integration.
8.2.2 IMTEGRATION TESTING
Integration checks are designed to check unified software program additives to adjust in the
event that they basically run as one software. Testing is occasion pushed and is greater
disturbed with the primary final results of monitors or fields. Integration checks decide that
even though the additives have been personally satisfaction, as proven via way of means of
efficiently unit trying out, the grouping of additives is specific and consistent.
61
Output: recognized classes of application outputs must be exercised.
62
8.2.7 SYSTEM TESTING:
This ensures the software is free of potential vulnerabilities, known flaws and security loopholes
that might affect the user system and data. Security testing is generally conducted through
penetration testing.
63
CHAPTER 9
RESULTS AND DISCUSSIONS
64
9.1 Dataset
Since Convolution Neural network is Supervised Machine Learning technique, a large amount
of labeled data (images) are needed for the purpose of training. The datasets were obtained
from Kaggle and WSID-100[5] repository. From kaggle repository, Animal-10 dataset[3] and
Monkey species[4] were used and rest of the data were taken from WSID-100 having similar
feature as Kaggle dataset. All together 200 images were taken for each class. For testing, 5
images were taken. Thus, the dataset classes consist of elegant, chicken, cow, sheep, dog, cat,
horse, monkey, squirrel and spider with 200 images per class and a total of 200 images were
taken
65
9.3 Exploratory Data Analysis
66
67
CHAPTER 10
CONCLUSION AND FUTURE SCOPE
68
10.1 Conclusion
Based on the results of the project, it can be concluded that training a ResNet152V2 model on
the animal-10 dataset can achieve high accuracy in classifying different animals. The model
was able to achieve an accuracy of 90.39% on the validation set, which is a good performance.
Additionally, the results of the model predictions on sample images show that it is able to
When comparing my work with the original project, it can be seen that both achieved similar
results in terms of accuracy and model architecture. However, the original project used the
entire dataset while I used only 10% of it. This means that the original project had a larger and
more diverse dataset, which could have contributed to the better accuracy achieved. Nonetheless,
working on a smaller dataset allowed me to learn and experiment with the model in a shorter
time frame.
Overall, the project demonstrates the effectiveness of using pre-trained models like
ResNet152V2 for image classification tasks, and highlights the importance of having a large and
69
10.2 future scope
The future scope of animal detection in farms using Convolutional Neural Networks (CNNs) is
promising, with several potential advancements and applications on the horizon. Here are some
areas of future development and opportunities for CNN-based animal detection systems in farm
environments:
Fine-grained Classification:
Enhance CNN models to perform fine-grained classification of animal breeds or species. This
capability can provide more detailed insights into the composition and distribution of animals
on the farm.
Behavior Analysis
Develop CNN models capable of analyzing animal behavior patterns and identifying abnormal
behaviors indicative of health issues or distress. This can aid in early detection of diseases and
improve animal welfare.
Multi-modal Sensing:
Integrate CNN-based animal detection with other sensing modalities, such as audio or
environmental sensors, to capture a more comprehensive understanding of farm conditions and
animal interactions.
Real-time Monitoring:
Improve the speed and efficiency of CNN models to enable real-time monitoring of animal
activities and events on the farm. This can facilitate prompt decision-making and intervention
by farmers.
Edge Computing:
Explore edge computing techniques to deploy lightweight CNN models directly on farm
monitoring devices or edge devices. This reduces latency and bandwidth requirements,
enabling faster and more efficient animal detection and analysis.
70
Robotic Systems:
Integrate CNN-based animal detection with robotic systems for autonomous monitoring and
management of livestock. Robots equipped with cameras and CNN models can navigate the
farm environment and perform tasks such as counting, tracking, and herding animals.
Long-range Sensing:
Develop CNN models capable of analyzing long-range sensing data, such as satellite imagery or
drone footage, to monitor large-scale farms and remote areas more effectively.
Multi-task Learning:
Investigate multi-task learning approaches to train CNN models for simultaneous detection of
multiple animal attributes, such as species, age, gender, and health status.
Transfer Learning:
- Explore transfer learning techniques to adapt pre-trained CNN models to new farm
environments or animal species with minimal labeled data. This accelerates model development
and deployment in diverse farm settings.
71
Regulatory Compliance:
Ensure compliance with regulatory frameworks governing animal welfare, data privacy, and
environmental sustainability in the development and deployment of CNN- based animal
detection systems.
72
REFERENCES
[3] https://www.kaggle.com/alessiocorrado99/animals10
[8] Verma, Gyanendra & Gupta, Pragya. (2018). Wild Animal Detection Using Deep
Convolutional Neural Network. 10.1007/978-981
73
information processing systems. 2012.
[13] Simonyan, Karen, and Andrew Zisserman. ”Very deep networks for large-scale
image recognition.” arXiv preprint arXiv: 1409.1556(2014)
[15] Tito Burghardt, Janko Calic, “Real time face detection and tracking of animals”,
IEEE Seminar on Neural Network applications in Electrical Engineering, vol.12, no.6, pp.1228-
1235, 2006.
[16] Umit Cacar, Murvet Kirci, “Scorenet : Deep cascade score-level fusion for
unconstructed ear recognition.”, IET Transaction on Biometrics, vol.2, no.3, pp.215- 224, 2019.
[17] Alexander Loos, Andrea Ernst, “Detection and identification of chimpanzee faces
in the wild.”,IEEETransaction on Unified Automatic Imagebased Face Detection, vol.7, no.4,
pp.847-852, 2012.
[18] Dalila Cherifi, Fateh Cherfauoui, “Fusion of face recognition methods at score
level.”, BioSMARTTransaction on Global and Local Methods of Possible Fusions, vol.5, no.2,
pp.289-297.
74