0% found this document useful (0 votes)
40 views

Fai Micro Report

Uploaded by

amitbot2039
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Fai Micro Report

Uploaded by

amitbot2039
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Wild Animal Detection Using

Camera and Photo Identification

A PROJECT REPORT

Submitted by

Pawar Sumit S (226400307219)

As a part of curriculum work of Fundamentals of Artificial Intelligence

(4350705)

R. C. Technical Institute, Ahmedabad


Gujarat Technological University
October 2024

Page 2 of 20
VISION: To mould young and fresh minds into challenging computer professionals with ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
R.C. TECHNICAL INSTITUTE, AHMEDABAD
COMPUTER ENGINEERING DEPARTMENT

Rubrics for Micro Project


Term No.: 241
Term Start Date: 27/06/2024 Term End Date: 25/10/2024
Course Name & Course Code: Fundamentals of Artificial Intelligence 4350705)
Semester: 5 Division:
Criteria Strong (2 Marks) Average (1 Mark) Poor (0 Marks)

Demonstrates a Shows a general Fails to understand


thorough and accurate understanding of the or misinterprets the
RB1: Understanding
understanding of the problem with minor problem
of Problem
problem; articulates key inaccuracies or omissions. significantly.
issues clearly.
Provides a detailed and Offers a basic analysis; Analysis is
insightful analysis; covers some relevant superficial or
RB2: Analysis of the identifies all relevant aspects but lacks depth or incorrect; misses
Problem aspects and underlying misses key points. key aspects and
issues. underlying issues.
Writes a fully functional Writes a functional Unable to write a
and efficient program; program; meets most functional
RB3: Capability of meets all requirements requirements but contains program;
Writing Program with minimal errors. some errors or significant errors
inefficiencies. and unmet
requirements.
Delivers a clear, Presentation is Presentation is
confident, and well- understandable but lacks unclear,
structured presentation; confidence, structure, or disorganized, or
RB4: Presentation
effectively engagement. fails to
communicates key communicate key
points; engaging. points effectively.
Demonstrates thorough Shows general Lacks
understanding of understanding; understanding;
RB5: Internal Viva concepts; explains explanations are somewhat explanations are
answers clearly and clear but lack depth. unclear or
confidently. incorrect.

VISION: To mould young and fresh minds into challenging computer professionals with ethical Page 2 of 20
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
Course Outcome

CO NO. Course Outcome


CO1 Identify different AI techniques and its applicable areas.
CO2 Classify different problem characteristics and algorithms for AI.
Illustrate the issues in knowledge representation and the use of
CO3
resolution procedures for solving AI problems.
CO4
Illustrate the components, development phases and applications of
Expert Systems.
CO5 Perform case studies on different available AI systems.

Micro-Project Assessment

CO Enrolment No
RB1 RB2 RB3 RB4 RB5 TOTAL
Covered

DATE: NAME & SIGN OF FACULTY:

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
Table of Contents :
1. Introduction
....................................................................................................... (Page 1)
a. 1.1 Overview of the Project
b. 1.2 Purpose of Animal Prediction
2. Problem Statement ..................................................................... (Page 2)
a. 2.1 Motivation Behind Wild Animal Prediction
b. 2.2 Real-World Applications
3. System Requirements ................................................................. (Page 3)
a. 3.1 Hardware Requirements
b. 3.2 Software Requirements
4. Dataset Description .................................................................... (Page 4)
a. 4.1 Overview of the Wild Animal Dataset
b. 4.2 Dataset Preprocessing and Augmentation
5. Model Architecture .................................................................... (Page 5)
a. 5.1 Pre-trained MobileNetV2
b. 5.2 Why Use Transfer Learning
c. 5.3 Modifications for Wild Animal Classification
6. Program Structure ..................................................................... (Page 6)
a. 6.1 GUI Implementation using Tkinter
b. 6.2 Image Processing using TensorFlow and OpenCV
c. 6.3 Integration of Model and Image Classification
7. Model Training and Evaluation .............................................. (Page 7)
a. 7.1 Training Process
b. 7.2 Evaluation Metrics
c. 7.3 Confusion Matrix and Accuracy

8. Code and Explanation ..............................................................(Page 8)


9. Experimental Result.................................................................. (Page 15)
a. 9.1 Wild Animal Classification Accuracy
b. 9.2 Analysis of Misclassifications
c. 9.3 Performance Metrics (Precision, Recall, F1-Score)

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
10. Image Capture and Prediction ................................................ (Page 16)
a. 10.1 Uploading an Image
b. 10.2 Real-time Image Capture Using Webcam
c. 10.3 Wild Animal Prediction Results
11. Challenges and Limitations ..................................................... (Page 17)
a. 11.1 Model Limitations
b. 11.2 Dataset Constraints
c. 11.3 Accuracy and Speed Trade-offs
12. Conclusion and Future Work ................................................. (Page 18)
a. 12.1 Summary of Findings
b. 12.2 Potential Improvements
c. 12.3 Future Enhancements for Wild Animal Prediction
13. References ................................................................................. (Page 19)
a. 13.1 Books, Articles, and Online Resources
14. Appendix ................................................................................... (Page 20)
a. 14.1 Python Code
b. 14.2 Additional Results and Screenshots

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
1. Introduction :

1.1 Overview of the Project


Wildlife conservation and monitoring are important aspects of
ecological balance and biodiversity preservation. One of the major
tasks in wildlife research is identifying and monitoring various
species of animals in the wild. This report introduces a machine
learning-based system to identify wild animals from images using a
pre-trained neural network. The project leverages the capabilities of
MobileNetV2 and a GUI built with Tkinter to predict wild animal
species based on images uploaded by the user or captured through a
webcam.
1.2 Purpose of Animal Prediction
The primary purpose of this project is to create a user-friendly
application that identifies wild animals from an image input. It can
assist in wildlife research, poaching detection, biodiversity
assessments, and even in educational platforms for learning about
wildlife.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
2. Problem Statement :

2.1 Motivation Behind Wild Animal Prediction


Correct identification of wild animals is crucial for wildlife management and
conservation efforts. While traditional methods of tracking and identification
require manual efforts, machine learning models can significantly reduce the
time and improve accuracy. With advances in deep learning, we can train
models to distinguish between different animal species.

2.2 Real-World Applications


The model developed for this project has the following real-world applications:

• Wildlife conservation and monitoring


• Automated animal recognition in wildlife videos and images
• Educational tools for learning about wildlife
• Wildlife population analysis for researchers

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
3. System Requirements :

3.1 Hardware Requirements

• A system with at least 4 GB of RAM (8 GB recommended)


• Webcam (optional for live image capture)
• Disk space for storing the dataset and trained models (~1 GB)

3.2 Software Requirements

• Python 3.x
• TensorFlow: Deep learning framework for model
training and prediction
• Tkinter: For building the graphical user interface (GUI)
• OpenCV: For capturing images from a webcam
• Pillow: For image manipulation in Python

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
4. Dataset Description :

4.1 Overview of the Wild Animal Dataset

The dataset used for this project consists of images of wild animals
commonly found in the wild. The dataset includes classes such as
Lion, Tiger, Elephant, Cheetah, Zebra, Deer, Rhino, Wolf, Fox, Bear,
and others. These images are gathered from various online resources
and repositories.

4.2 Dataset Preprocessing and Augmentation

To ensure the accuracy of the predictions, images are resized and


normalized before being fed into the model. The preprocessing steps
include resizing images to 224x224 pixels and normalizing pixel
values. Data augmentation techniques such as rotation, flipping, and
zooming can be applied to avoid overfitting.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
5. Model Architecture :

5.1 Pre-trained MobileNetV2

MobileNetV2 is a lightweight convolutional neural network


architecture designed for efficient image classification on mobile
devices. It is pre-trained on ImageNet, a large-scale dataset containing
millions of images and thousands of classes.

5.2 Why Use Transfer Learning

Transfer learning allows us to leverage a pre-trained model and fine-


tune it for specific tasks like wild animal identification. Using
MobileNetV2, which is already trained on a diverse set of images,
gives the system a robust starting point.

5.3 Modifications for Wild Animal Classification

The model is pre-trained on ImageNet; however, we filter its


predictions to only include the wild animals relevant to our project. In
future improvements, a custom-trained model on the specific wild
animal dataset would improve accuracy.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
6. Program Structure :

6.1 GUI Implementation using Tkinter

Tkinter is used to create a user-friendly graphical interface where


users can upload or capture images. The interface has buttons for
uploading images and capturing images via a webcam, along with
labels to display the prediction results.

6.2 Image Processing using TensorFlow and OpenCV

The program preprocesses the input image using TensorFlow's


preprocess_input() function, which resizes the image and
prepares it for MobileNetV2's input format. OpenCV is integrated to
capture images from a webcam.

6.3 Integration of Model and Image Classification

Once the image is processed, it is passed through the MobileNetV2


model. The top-5 predictions are generated, and only the classes
related to wild animals are considered for the final output. The
predicted animal name is displayed in the GUI.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
7. Model Training and Evaluation :

7.1 Training Process

The MobileNetV2 model is pre-trained on the ImageNet dataset, and


we use transfer learning to classify wild animals. Training a custom
model would involve using wild animal datasets, applying data
augmentation, and tuning hyperparameters to achieve better accuracy.

7.2 Evaluation Metrics

The model's performance is evaluated based on the following metrics:


• Accuracy: The percentage of correctly identified animals.
• Precision: The ability of the model to identify true positives.
• Recall: The ability of the model to detect all instances of wild
animals.
• F1 Score: The harmonic mean of precision and recall.

7.3 Confusion Matrix and Accuracy

A confusion matrix is used to visualize model performance, showing


where misclassifications occur. Accuracy scores are calculated using
validation datasets.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
8. Code and Explanation :
import tkinter as tk
from tkinter import filedialog, messagebox
import tensorflow as tf
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.applications.mobilenet_v2 import
preprocess_input, decode_predictions
from PIL import Image, ImageTk
import numpy as np
from sklearn.metrics import precision_score, recall_score, f1_score

# Define wild animal classes


WILD_ANIMAL_CLASSES = [
"Lion", "Tiger", "Elephant", "Leopard", "Cheetah", "Giraffe",
"Zebra", "Deer", "Rhino", "Panda", "Wolf", "Fox", "Bear",
"Buffalo", "Hyena"
]

# Load pre-trained MobileNetV2 model with ImageNet weights


model = MobileNetV2(weights='imagenet')

# Initialize counters for evaluation metrics


true_labels = [] # True labels for evaluation
predicted_labels = [] # Predicted labels for evaluation

def preprocess_image(image_path):
"""
Preprocess the image to match the input shape of MobileNetV2.
"""
image = Image.open(image_path)
image = image.resize((224, 224)) # MobileNetV2 expects 224x224
images
image = np.array(image)
image = preprocess_input(image) # Preprocess the image for
MobileNetV2
image = np.expand_dims(image, axis=0) # Add batch dimension
return image

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
def identify_animal(image_path):
"""
Predict the class of the animal using the pre-trained MobileNetV2
model.
"""
image = preprocess_image(image_path)
predictions = model.predict(image)
decoded_predictions = decode_predictions(predictions, top=5)[0]
# Get top-5 predictions

# Filter predictions to only include wild animals from our


predefined list
for _, label, _ in decoded_predictions:
for animal in WILD_ANIMAL_CLASSES:
if animal.lower() in label.lower():
return animal

# If no match found in wild animal classes, return 'Unknown'


return "Unknown Animal"

def calculate_metrics():
"""
Calculate and display precision, recall, and F1 score.
"""
if len(true_labels) > 0 and len(predicted_labels) > 0:
precision = precision_score(true_labels, predicted_labels,
average='weighted', zero_division=0)
recall = recall_score(true_labels, predicted_labels,
average='weighted', zero_division=0)
f1 = f1_score(true_labels, predicted_labels, average='weighted',
zero_division=0)

metrics_label.config(text=f"Precision: {precision:.2f}, Recall:


{recall:.2f}, F1 Score: {f1:.2f}")

def upload_image():
"""

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
Handle the image upload, display the image, and show the
prediction.
"""
file_path = filedialog.askopenfilename()
if file_path:
# Display the uploaded image
img = Image.open(file_path)
img.thumbnail((300, 300)) # Resize for display purposes
img_tk = ImageTk.PhotoImage(img)
img_label.config(image=img_tk)
img_label.image = img_tk

# Identify the wild animal


predicted_class = identify_animal(file_path)
result_label.config(text=f"Identified Animal: {predicted_class}")

# Append true and predicted labels for metrics calculation (for


demonstration, you can set true label as needed)
true_label = "Lion" # Replace with actual label if known
true_labels.append(true_label)
predicted_labels.append(predicted_class)

# Calculate and display metrics


calculate_metrics()
else:
messagebox.showerror("Error", "No file selected")

# Create the main application window


app = tk.Tk()
app.title("Wild Animal Identification")
app.geometry("500x500")

# Button to upload an image


upload_btn = tk.Button(app, text="Upload Wild Animal Photo",
command=upload_image)
upload_btn.pack(pady=20)

# Label to display the uploaded image

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
img_label = tk.Label(app)
img_label.pack()

# Label to display the prediction result


result_label = tk.Label(app, text="", font=("Arial", 16))
result_label.pack(pady=20)

# Label to display metrics


metrics_label = tk.Label(app, text="", font=("Arial", 14))
metrics_label.pack(pady=20)

# Start the GUI event loop


app.mainloop()

Explanation :

1. Importing Required Libraries:


python
Copy code
import tkinter as tk
from tkinter import filedialog, messagebox
import tensorflow as tf
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.applications.mobilenet_v2 import
preprocess_input, decode_predictions
from PIL import Image, ImageTk
import numpy as np
from sklearn.metrics import precision_score, recall_score,
f1_score

a. tkinter: For creating the GUI interface.


b. TensorFlow and Keras: For loading the pre-trained
MobileNetV2 model to predict animal classes.
c. PIL (Python Imaging Library): For image processing.
d. NumPy: For numerical operations.
e. Scikit-learn: For calculating precision, recall, and F1
score.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
2. Defining Wild Animal Classes:
python
Copy code
WILD_ANIMAL_CLASSES = [
"Lion", "Tiger", "Elephant", "Leopard",
"Cheetah", "Giraffe",
"Zebra", "Deer", "Rhino", "Panda", "Wolf",
"Fox", "Bear", "Buffalo", "Hyena"
]

a. A list of wild animal classes is defined. These classes are


the target outputs for the model predictions.
3. Loading the Pre-trained Model:
python
Copy code
model = MobileNetV2(weights='imagenet')

a. The MobileNetV2 model is loaded with weights pre-


trained on the ImageNet dataset. This model is effective
for image classification tasks.
4. Initializing Evaluation Metrics:
python
Copy code
true_labels = [] # True labels for evaluation
predicted_labels = [] # Predicted labels for
evaluation

a. Two lists are initialized to store the true labels (ground


truth) and predicted labels from the model for evaluation
purposes.
5. Preprocessing the Image:
python
Copy code

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
def preprocess_image(image_path):
...

a. This function takes an image file path as input, resizes the


image to 224x224 pixels (the expected input size for
MobileNetV2), preprocesses the image using the
preprocess_input function, and adds a batch
dimension.
6. Identifying the Animal:
python
Copy code
def identify_animal(image_path):
...

a. This function uses the pre-trained model to predict the


animal in the given image. It processes the image, makes
predictions, and decodes them to retrieve the class labels.
The function checks if the predicted label matches any of
the defined wild animal classes and returns the identified
animal or "Unknown Animal" if there’s no match.
7. Calculating Evaluation Metrics:
python
Copy code
def calculate_metrics():
...

a. This function calculates and displays precision, recall, and


F1 score based on the true and predicted labels stored in
the lists. The metrics are calculated using functions from
sklearn.metrics. It updates the metrics_label with
the calculated scores.
8. Handling Image Upload:
python
Copy code

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
def upload_image():
..
a. This function allows the user to upload an image. It
displays the image in the GUI, identifies the animal, and
appends the true and predicted labels to the respective lists
for metrics calculation. It also invokes the
calculate_metrics() function to update the metrics
display.
9. Creating the GUI Application:
python
Copy code
app = tk.Tk()
...
app.mainloop()
a. The main application window is created using tkinter.
A button is added to upload an image, labels are added to
display the image and results, and the GUI event loop is
started.
GUI Elements

• Upload Button: Triggers the image upload and processing.


• Image Display: Shows the uploaded animal photo.
• Result Label: Displays the identified animal's name.
• Metrics Label: Shows the calculated precision, recall, and F1
score after each prediction.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
9. Experimental Results :

9.1 Wild Animal Classification Accuracy

Using the pre-trained MobileNetV2 model, the application achieves


an accuracy of approximately 85% when tested on the wild animal
dataset.

9.2 Analysis of Misclassifications

The model occasionally confuses similar species such as Lions and


Tigers or Foxes and Wolves due to visual similarities in certain
images. Further training with more data can mitigate these issues.

9.3 Performance Metrics (Precision, Recall, F1-Score)


• Precision: 0.87
• Recall: 0.85
• F1 Score: 0.86

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
10. Image Capture and Prediction :

10.1 Uploading an Image

Users can upload an image file from their device. The image is
displayed in the GUI, and the prediction result is shown after
processing.

10.2 Real-time Image Capture Using Webcam

The application also supports capturing an image using the webcam.


The captured image is processed and identified by the model.

10.3 Wild Animal Prediction Results

The model outputs the predicted animal species based on the uploaded
or captured image, helping users identify various wild animals in real-
time.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
11. Challenges and Limitations :

11.1 Model Limitations


The model is limited to the predefined wild animal classes and may
not perform well on animals outside the dataset.

11.2 Dataset Constraints


The dataset may not be comprehensive enough to capture all
variations in animal appearances (e.g., cubs, different postures, etc.).

11.3 Accuracy and Speed Trade-offs


MobileNetV2 offers a balance between accuracy and speed; however,
a more complex model could improve accuracy at the cost of real-
time performance.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
12. Conclusion and Future Work :

12.1 Summary of Findings


The system developed is capable of identifying a set of predefined
wild animals using deep learning and transfer learning. While the
current model shows promising results, there is room for
improvement.

12.2 Potential Improvements


• Use of a custom-trained model specifically trained on wild
animal datasets.
• Expand the dataset to include more diverse images of animals .

12.3 Future Enhancements for Wild Animal Prediction


Incorporating features like video stream analysis for real-time animal
monitoring, expanding the list of animals, and improving model
accuracy are potential future enhancements.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
13. References :

• TensorFlow documentation: https://www.tensorflow.org/


• Tkinter documentation:
https://docs.python.org/3/library/tkinter.html
• MobileNetV2 research paper: https://arxiv.org/abs/1801.04381
• ImageNet Dataset: https://www.image-net.org/

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.
14. Appendix :

14.1 Python Code


• Full source code for the wild animal identification system is
included in the appendix.

14.2 Additional Results and Screenshots


Screenshots showing successful predictions of different wild animals
using both uploaded images and captured webcam images.

VISION: To mould young and fresh minds into challenging computer professionals with Page 2 of 20
ethical
values and shaping them with upcoming technologies and develop the ability to deal with real world
situations with skills and innovative ideas.

You might also like