The Challenges of Growing
With constantly changing environmental conditions, farmers are kept on their toes, adapting to every situation. With areas spanning hundreds of acres, this is never easy. The agricultural industry must keep watch over a myriad of conditions, including sunlight and weather, migratory patterns of birds and insects, and unforeseen issues, such as a disease outbreak. Additionally, with dwindling resources on the planet, sustainability is an important concern; the agricultural industry is being asked to produce more and use less.
Agriculture 4.0 or smart farming is the evolution of agriculture. Taking advantage of advancements brought about by IoT (Internet of Things) technology, the modern farm is connected 24/7. Sensors monitor almost every aspect of the farm, from moisture levels in the soil to abnormal sounds in livestock, generating a vast amount of data. Machines are better than humans at sifting through terabytes of data; however, machines have to be taught what to look for. This is done through machine learning.
The Basics of Machine Learning
Machine learning (ML) is a field of artificial intelligence in which machines are programmed to emulate the way a human brain learns. The ultimate goal is for machines to learn and perform tasks without explicitly being programmed to do so. With ML, machines can perform tasks like recognizing objects in an image, understanding text written in a natural language, or identifying sounds.
However, training a machine is not an easy task. While humans can rely on a lifetime of experience to recognize and identify imagery and sound, machines are starting from scratch. Training a machine requires data, the more the better! Programmers select an ML model and supply the data, and the machine gets to work learning from and identifying patterns in the data. To improve results, the model and data can be tweaked. Data should be selected to avoid biases. After training, data with known information can be used to test how well the training worked.
There are three different categories of ML:
Supervised ML models use labeled datasets for their training. For example, all of the cars in a set of images are labeled. After the machine is trained using the labeled images, it would be able to recognize cars in images that are unlabeled.
Unsupervised ML models use unlabeled datasets and the machine tries to find patterns. Unsupervised ML can be used to discover new patterns or trends, such as the behavior of online shoppers or migratory patterns in animals.
Reinforcement ML models use a rewards-based system. In a reinforcement ML system, the machine is told whether its decisions are right or wrong. Over time, this teaches the machine what actions it should take in different situations.
ML with Edge Impulse
Edge Impulse is a software platform that helps developers design for embedded ML applications. Edge Impulse Studio allows developers to choose from a library of ML algorithms, which are extensible and customizable. Its tools are geared towards the manipulation of datasets and include interfaces for visualization and analysis. Training also takes place in Edge Impulse Studio, where results can be analyzed and datasets modified for additional training. Once training is complete, the application can be deployed to a variety of microcontrollers, CPUs, or smart phones. Developers can create, train, and deploy most applications using Edge Impulse Studio without writing a single line of code. However, the success of the application depends on the quality of the training data.
ML in Agriculture 4.0
Many of the challenges that farmers face can be approached with data-driven solutions, with machine learning analyzing the vast amounts of data generated by sensors in the field. Computer vision can be used for plant identification, with AI trained to differentiate between weeds and the legitimate crop. Detecting trends in growth vs. soil moisture can help in determining irrigation cycles. Pests can be detected with a combination of growth patterns and object detection with computer vision. Supply chain management can also improve with machine learning.
The following are example applications in agriculture that use machine learning, developed using Edge Impulse.
In recent times, technology has made it possible for farms to grow massive amounts of food; however, the amount of water being used is correspondingly massive. In many cases, the water is unnecessary and wasted. ML is used, in this project by Evan Rust, to optimize irrigation, making the process more cost-efficient and sustainable.
Figure 1: AI-managed crop irrigation - detecting soil moisture
Source: Edge Impulse
The dataset consisted of 25 total samples, each one having a timestamp, soil moisture reading, battery level, temperature, and humidity. A Keras neural network was trained on this dataset to output the label it thinks corresponds with the sensor readings, either “water” or “don’t water”. The accuracy achieved with this method was 100%.
Deploying the trained model is straightforward; Edge Impulse has the ability to export a model as an Arduino library. This system can be further expanded with a solenoid water valve that can be controlled by the Arduino, automatically watering plants when needed.
The fields on an industrial farm are enormous, and, as such, often in remote locations. Because of this, robots are starting to be employed to perform tasks like crop picking and weeding. For such tasks, it is imperative that the robot be able to differentiate between types of plants. Attaching a high resolution digital camera allows the robot to see the size and shape of the plants, and ML teaches the robot how to identify them.
Figure 2: Crop irrigation robot
Adam Taylor from Aduivo recently designed a robot prototype with a computer vision system designed to classify different types of plants. The robot is developed by Robotic Systems Ltd. and is designed to image and analyze crops, as well as perform spraying operations. The robot travels at 3mph when spraying and slows down when imaging and analyzing.
Because of the potential long distances and remote locations found in industrial agriculture, a wired connection to a power supply can be difficult to set up. For a robot, battery power makes the most sense, however, in order to prolong battery life, power consumption must be kept to a minimum. Connectivity should also be wireless.
Figure 3: Creating impulse in Edge Impulse Studio
The development board used was a Sony Spresense, which has a built-in GPS antenna and is able to connect to a 5MP camera. The camera is used to capture images of the crops, while the GPS antenna records where the plants are located. The ML application that classifies the plants was created in Edge Impulse. For this prototype, wheat, corn, and sugar were the target crops. The training dataset was downloaded from Kaggle, an ML community. After training, the application was deployed to the development board for in the field testing.
Disease outbreaks in livestock can be devastating, and can often lead to the loss of thousands, if not millions of animals. One recent example was 2022’s bird flu outbreak, where millions of chickens had to be culled. Any illnesses need to be detected as early as possible, so that sick animals can be isolated, protecting the remainder of the herd or flock from becoming infected.
Figure 4: Livestock monitoring block diagram
To tackle this issue, hardware hacker Clinton Oduor came up with a solution for detecting the early stages of respiratory disease in pig populations using off-the-shelf devices and Edge Impulse. The onboard microphone of an Arduino NANO 33 BLE Series was used to collect audio samples, with the primary goal to detect the sounds of coughing. An Arduino MKR FOX 1200 enabled low power wireless communication, and the device was placed in a custom plastic casing and mounted in a pigsty.
Figure 5: Respiratory disease detection in livestock
The main challenge of this project is differentiating the sound of a cough hidden underneath the sounds of hundreds of pigs snorting and squealing. Audio clips of healthy pigs, as well as the sounds of pigs coughing were uploaded to Edge Impulse. An MFCC (mel-frequency cepstral coefficients) processing block extracted the important features from the audio data. MFCCs are used in many ML models for training on audio data. The MFCC features are then passed them to the neural network classifier. Training showed 99.7% classification accuracy, meaning the device was ready to be installed at a pig farm for real world testing.
The agricultural industry uses quite a bit of water, but accidentally leaving the water running could have disastrous consequences. The Running Faucet Detector by ML enthusiast Naveen Kumar is a project on a decidedly smaller scale, but some of the concepts could be adapted to the agricultural industry.
Figure 6: Running faucet detector
The onboard microphone of the NXP i.MX RT1010 Evaluation Kit was used to capture the sounds of a faucet, with water running and without. Fifteen minutes of audio data was captured and classified as a faucet running and miscellaneous background noises. The important features were extracted using an MFCC preprocessing block and passed on the learning block with the neural network classifier. The model was found to have an 89.3% accuracy in classifying the sound of a running faucet. The model was deployed to the development board, where a buzzer sounds if the faucet is left running for longer than a predetermined time.
With Industry 4.0 and Agriculture 4.0 in mind, audio classification with ML can be adapted for a wide range of uses. Detecting running water and pigs coughing are just two example applications. Sounds can also be used for predictive maintenance in machinery, and even used to indicate changes in the wind and weather.
Summing up: Making Agriculture Smarter
The growth of IoT is bringing about big changes to the agricultural industry. In the past, farms have relied on human senses to evaluate conditions, however, with the size of an industrial farm, 24/7 monitoring of every square inch would be impossible. The connectivity that IoT brings enables sensors to take the place of human eyes, ears, smell, and touch. Now, with advancements in AI and ML, devices can also do some of the work that human brains do, classifying sights, sounds, and smells, making predictions, and even making decisions on what to do next. Edge Impulse makes AI accessible, by reducing the learning curve for developing and deploying ML models to devices in the field, no matter what you may be growing!