Animal Detection in Machine learning
ANIMAL DETECTION BY PYTHON PACKAGE DETECTO
INTRODUCTION
Humans can easily detect and identify objects present in an image. The human visual system is fast and accurate and can perform complex tasks like identifying multiple objects and detect obstacles with little conscious thought. With the availability of large amounts of data, faster GPUs, and better algorithms, we can now easily train computers to detect and classify multiple objects within an image with high accuracy
ABOUT PROJECT
DETECTO -OBJECT DETECTION:
Detecto is a Python package that allows you to build fully-functioning computer vision and object detection models with just 5 lines of code. Inference on still images and videos, transfer learning on custom datasets, and serialization of models to files are just a few of Detecto’s features. Detecto is also built on top of PyTorch, allowing an easy transfer of models between the two libraries.
Using the Detecto package detected the animals for 3 classes as tiger elephant and panda Here the step begins with object collection
Note : As the detecto is a package built on top of PyTorch with TensorFlow took lot of time for training as because of my laptop configuration was not that much high as only I have chosen 3 class images for animal detection
STEP 1:
OBJECT DATA SET COLLECTION
Here is the data set for the three animals I have collected as follows
Remember you should have at least 75 images in each class
Here by downloading the images 75 for each class as tiger elephant and pandas from google. I have used the download all images extension to download the bulk amount of images which is available in chrome as the extensions shown below as
Save all the images in single folder and name it (for example: save all images)
STEP 2:
Selecting and labelling the images
The next step involves to read the image in the xml format for training it with some specific algorithm as the Software called Labellmg which is available open source to convert the images with respect to the xml file.
Here select the open dir to open the folder that the images have been downloaded as the data set

Now click the Create Read box option to draw a box where the animal is exactly on and classify them it prompts to save the xml file to be saves click save to proceed further
Click save to proceed and repeat it for all images the xml file will be saved on the images folder one by one in order
The created Xml file stored with next to respective location where images found
The xml file consists of image details as its height, weightage, depth position placed etc. as below
Step 3
SETUP DETECTO WITH PYTHON AND WORKING
I am using anaconda for this as it follows to install do pip in Anaconda prompt to install Detecto package (or) You can also use Google Colab for this if you have no GPU in your computer specified as the pytorch needs gpu to process the images
Now all is set let’s work on jupyter notebook further
Open the ipynb file where you have saved the images folder
First import the detecto package then save the images (the image dataset with xml files) to the variable Give the class to be in the images to be detected and finally train the model. It will take some time to train the model
Now testing the model with a image
Here is the image Which is not used in training the images with tiger and elephant now can see whether it predicts correctly
This is following code to detect the image
Here the read_image function reads the image stores in image variable the predict function =returns the values in 3 format respectively labels as no of class got from the image boxes as the coordinates the object detected and finally score is confidence score of the image whether it is prese t in that image. The output will be
As you can see the prediction results had correctly predicted the noisy of repeating the class due the low no of images used for training also the background noise present in the image but we got the correct results as the first list tells the class present in the image the tensor tells the coordinates predicted with object at last the tensor tuple consists of confidence level score as when it is higher then 0.75 the possibility of presence of image is high in it. For the above image it is correctly predicted.
Saving the model as the file and using later can be done it will help you when reuse of the object detection whenever is possible
The first command saves the model as the pth file in your local system The second command is used when it is reused again for the use.
WEB APPLICATION DEVELOPEMENT BY PYTHON FLASK:
Flask is a lightweight WSGI web application framework. Werkzeug and Jinja and has become one of the most popular Python web application frameworks
Final Deployment results:
Video demo:https://youtu.be/kxUfXvpMSMs



















Comments
Post a Comment