An Agri vigilance System based on Computer Vision and Deep Learning

In an agricultural-based country like India, farming and farming activities play a vital role in the growth of the economy as it is the main source of GNI (Gross National Income). This dependence of GNI on agriculture makes it important to address the issues faced by the farmers. The main area of concern for farmers revolves around crops and livestock. Precise farming techniques like cattle counting and crop disease detection are the need of the hour. The introduction of computer vision and deep learning has enabled us to make improvements in farming techniques. To accomplish this, a computer vision-based system is proposed which will be implemented using ResNet and YOLOv3-tiny. The proposed system will take images and videos as input and run them on the inference. The output will be updated in the database and the farmer will be notified in case of any inconsistency. The detailed report can be accessed by government agencies. The system will increase efficiency in farming processes like crop monitoring, livestock tracking, crop disease detection by providing fast and efficient solutions for the problems faced by the farmers.


Introduction
Our civilization started with agriculture, and it continues to play a significant role in providing humans with basic necessities like food, fodder, and raw materials. Agriculture has been instrumental in sustaining and driving the country's economy as it provides employment opportunities and helps in rural development. Especially in an agricultural-driven country like India, farming is the backbone of India's economic system, where about 60% of the population depend directly on farming as a livelihood. This dependence of national income on cultivation necessitates addressing the problems faced by the farmers. Issues such as an increase in food prices, malicious activity on the farm, and no significant development in crop production have come to light. The two principal problems that demand urgent attention are crop disease detection and cattle monitoring. Diseased crops can drastically reduce the quality and quantity of crops. If this continues on a larger scale, it could lead to scarcity of food. Therefore, it becomes vital to identify unhealthy plants at the initial stages to save the yield from ruining. At present, the crops are manually checked periodically for the presence of diseases. This task is time-consuming and can prove inefficient if not done properly. The aim is to automate the process of crop disease detection. The objective is to reduce manual labour by leveraging computer vision and deep learning technologies in farming activities. Hence, we propose a Resnet based architecture to detect and identify some common crop diseases with near-perfect accuracy [1] [2].
Furthermore, considering that there has been an increase in the illegal theft or killing of animals, the farmers need to know the number of cattle grazing in their field. By keeping an accurate count of the cattle helps the farmer to know whether their cattle are within the boundaries of the farm or not. The counting of individual animals manually over acres of farmlands is difficult and prone to human errors. The proposed system uses the YOLOv3-tiny model, which will help farmers monitor their livestock and keep track of the number of cattle on their farms [13][14][15][16][17][18][19][20][21][22]. There will be a notable enhancement in farm productivity and improvement in the overall efficiency of agricultural practices by catering to these problems. In [3], the authors have compared AlexNet and SqueezeNet architecture for the detection of diseases in Tomato plants.

Literature Survey
They have chosen 10 different classes for their study from the 'Plant village dataset'. Both the CNN architecture performed well, although the performance of Alexnet was slightly better. Further, they suggested that these neural networks can be added to the robot [4] for real time disease detection capability.
To increase the prediction accuracy, we need to have a robust network so that network could learn various features and classify accordingly. But training deep neural networks sometimes lead to vanishing gradient problems due to which the network may perform poor. In [5], the study has been done to address the degradation problem due to vanishing gradient. It has been suggested that the shortcut connections can be introduced in the network which will enable the network to retain the information and hence can perform well. These shortcuts are essentially Identity mapping and introducing them in the network does not increases any extra parameter. quad-copter drone. The animal detection task was benchmarked with three lightweight object detection algorithms that are suitable for on-board implementation since their potential detection speed is less than 1 second per image. The animal counting was based on frame-based detections in combination with point tracks obtained by a KLT tracker. [8] In [9], The authors presented their research on using deep learning to detect cattle. They put 15 different CNN architectures to the test, looking at things like low illumination, excessive brightness, blur, and so on. NasNet Large produced the best results in terms of accuracy, with the Xception architecture producing very high accuracies with a fraction of NasNet's training times. They suggested using YOLO to draw a bounding box around the subject as the future work.
In [10], The authors evaluated the performance of Faster RCNN, YOLOv3, and SSD for cattle detection and counting. Across a range of scenarios, average precision scores of 86%, 91%, 95% of bounding box and 84%, 90%, 94% for mask, as well as counting accuracy of 90%, 92%, 94% and recall of 91%, 95%, 96% were detected. The results presented indicate that Mask R-CNN could be utilized in practical settings as a method of livestock detection and counting using a quadcopter.
It can be observed that in the case of crop diseases, Resnet based architecture has proved to be very efficient for achieving more than the desired accuracy. However, the architecture is a bit computationally heavy. The network size can be decreased by using various optimization techniques like pruning and at the same time preserving its robustness. Additionally, the systems for monitoring the cattle proposed by various researchers used CNN-based models which delivered good results, but performance decreased in case of huge clusters or when motion was detected.

Problem Definition
Agriculture in India faces many challenges in terms of productivity, reliable detection and accurate identification of crop diseases, and labour shortage. The system will detect and identify the diseased crops, and the user will be notified via a message. The system will keep an accurate count of the livestock to prevent illegal killing or theft of cattle of particular farmland.
The aim is to automate and increase the efficiency of the agriculture processes.

Proposed System Overview and Methodology
The proposed system will strengthen the agricultural practices by eliminating the problems faced by the farmers -monitoring the health of the crop and cattle management. The model will function in two modes -plant disease detection and cattle monitor. The user will have to select the mode for which they want the information. According to the mode selected, the pre-processed image will be passed either through the disease detector or cattle count detector. In crop disease detection mode, the images of the leaves will be taken as input. It will give the type of disease as output if any. In cattle count mode, the system will give the count of the cattle as output from the input images.
The disease detector is based on ResNet, which is a CNN-based architecture. Unlike normal CNN, it contains residual blocks that help in retaining the information of the image when passed through the network. ResNet is a model that is pre-trained on ImageNet Database. A pre-trained model helps get higher accuracy by just using a small amount of data, which saves time. In disease detector mode, the pre-processed image will undergo segmentation. The region of interest (ROI) from the segmented image will be localized. The final step is to classify whether a plant is healthy or not. If the plant is infected, then it will identify the type of disease.  Transfer learning is used for training the model for our use-case. Using a pre-trained model is beneficial because it saves a lot of training time. Pre-trained Resnet architecture trained on ImageNet -which is a huge dataset comprising of different image categories, is taken as starting base model. This is because we wanted the model to retain its feature extraction knowledge which it has learned on the ImageNet dataset. At the end of model architecture various layers such as convolution layer, batch normalization, and finally fully connected dense layers are stacked to finetune it for our purpose. After training the model is integrated into the system for inferencing. An image of plant leaves is to be fed to the system. This image will be reshaped into 256*256 pixels and given to the model for classification. The model gives out the class of images. The cattle count detector is implemented using YOLOv3. The architecture of YOLOv3 can be seen in figure 3 below. YOLOv3-tiny is used because it gives better accuracy compared to other algorithms. In cattle count mode, the pre-processed image will undergo segmentation. The next step is feature extraction for cattle detection. After that, the inference will run, and it will give bounding boxes for the cattle. Finally, the cattle will be counted based on the number of bounding boxes.

Figure. 3 YOLOv3 Architecture
We have created our own dataset consisting of around 50 images that contain plenty of cattle. We are considering four types of cattle i.e., cows, buffalos, sheep, and camels. Individual animal from each image is extracted and labelled for training. This dataset is randomly divided into train and test in the ratio of 90/10. For training, we will be using the YOLOv3-Tiny model -a variant of Darknet. YOLO is an object detection algorithm that is fast and accurate as a Single Shot MultiBox (SSD). We are using YOLOv3-Tiny and not YOLOv3 because it requires less computation, and it is good for embedded devices like Raspberry-pi. It applies a single neural network to the full image, and then divides the image into regions and predicts bounding boxes and probabilities for each region. We retrain the already trained model for our data. After every 1000 epoch of training weights will be updated and saved into the file. After training, the model is integrated into the system for inferencing. An image or video frame can be passed to the model where the segmentation will take place. The model will divide images into different segments of images. These individual segments will be labeled into a class. The model then returns a plethora of bounding boxes that are then reduced through Non-max Suppression, a type of filtering. This results in fairly accurate detection of different classes. As an output, we will get all the detected objects along with the class labels, confidence score and location of the bounding box in a form of a list. The resultant data from either mode will then be updated into the database.
The user will request the database for the required data, and the database will respond to the user request.  For Plant Disease detection, our model gave almost 99% accuracy. The model summary is given in Table 1 above. Previously, many authors have got similar accuracy, but none of them have used augmented data. Our training method used artificially augmented data that makes our model ready to use on real-world images. Machine learning and deep learning models are as good as the data on which they are trained and for their performance, they require the type of data on which they are trained on. The dataset which we have used contains a single leaf image in each image file, and that too on the background which is easily distinguishable from the foreground object (i.e., leaf). But in the real world, we can't expect to get such an image. Our use case is images from drones i.e., the system will be getting images containing several leaves with a background containing some more vegetation. To make the system work with such images, we artificially augmented the images to produce similar conditions and used those images to train our model. The proposed system will be able to work in the real world reliably. We already got the validation accuracy of 99% i.e., similar to that of training accuracy, and several tests on real-world images also show a good prediction as seen in figure 4. For cattle count detection, our main task was to correctly detect the position, height and width of the box around the animal present in the image. For this, our model was correctly able to detect these parameters with an accuracy of 73.2319%.

Result and Analysis
Previously, authors narrowed down their focus on counting only one type of animal, but we have considered 4 types of animals where along with good detection accuracy, we can classify the detected animal and provide the count of each animal present. Other studies show that researchers used a four-step-approach to count cattle with a large dataset which gave them good accuracy in detecting the cattle and non-cattle. With our model, we got close enough results in detecting the animal from its surrounding with little false positives after training on an extremely small-sized custom dataset as seen in figure 5.

Figure.5 Cattle detection
Our model was able to process 6-7 images/frames per second with an estimated cattle count of +-3 to the true value per dozen when the animals were scattered around in the field. The error rate increases when cattle were close to each other i.e., when animals in the image were overlapping each other. The analysis showed that our single model performed better than most of the previous works even against all of them combined.

Conclusion
The proposed system shows how computer vision and deep learning can help eliminate the problems faced by farmers by monitoring their livestock and crop health. The system will enhance agricultural productivity and improve the overall efficiency of agricultural practices. The farmers will be able to receive updates regarding the inconsistencies in their crops or cattle count by using this system. The system will serve as an aid to farmers enabling fast and efficient recognition of plant diseases and assist in keeping track of their cattle. The government agencies will be able to get regular updates regarding the crop health data, which was traditionally done by visiting the farm once a year.