Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Journal of Physics: Conference

Series

PAPER • OPEN ACCESS You may also like


- CCSDS-MHC on Raspberry Pi for
Raspberry Pi-Embedded Intelligent Control Lossless Hyperspectral Image
Compression
System for Irrigation and Fertilization Based on N A A Samah, N R M Noor, E A Bakar et
al.

deep learning - Implementation of vibration signals


receiving unit on Raspberry single-board
computers
To cite this article: Weibing Jia and Zhengying Wei 2023 J. Phys.: Conf. Ser. 2504 012034 V A Faerman, A V Tsavnin and S A
Andreev

- Implementation of Attendance System


Using Raspberry Pi
A P Sujana and A Y Prastyawan
View the article online for updates and enhancements.

This content was downloaded from IP address 106.51.8.242 on 09/02/2024 at 09:29


ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

Raspberry Pi-Embedded Intelligent Control System for


Irrigation and Fertilization Based on deep learning

Weibing Jia1,2[0000-0001-9676-5152], Zhengying Wei2[0000-0001-5820-8734]


1
Shaanxi Pengyun Machinery Automation Technology Co., Ltd ., NO. 1 Fangyi Rd,
Xi’an, Shaanxi Province, 710038, P.R. China
2
The State Key Laboratory for Manufacturing Systems Engineering, Xi’an Jiaotong
University, Xi’an, Shaanxi Province, 710049, P.R. China
*
Corresponding author’s e-mail: zywei@xjtu.edu.cn

Abstract. More than two-thirds of freshwater consumed worldwide are used for irrigation, and
the existing control system for irrigation and fertilization is not intelligent and efficient enough.
It is necessary to improve the utilization efficiency of irrigation water and fertilizer, and the
intelligent level of irrigation and fertilization system. We have built tomato fertilizer deficiency
and fertilization decision model based on leaf images and deep learning, this paper develops an
Raspberry Pi-embedded intelligent control system for irrigation and fertilization based on
previous deep learning models. The system included sensors, image acquisition, control part,
control panel and remote control, the type of main hardware and sensors were selected, and the
circuit of the system were designed. The C language is used to compile the source code of the
deep learning framework, and the Python language is used to compress the deep learning
model. The result shows that the compression rate of the deep learning model can reach 36.7%
and the decision-making time can be shortened by 36% under the condition of ensuring the
model accuracy. The Raspberry Pi-embedded intelligent control system can help farmers
improve the utilization efficiency of irrigation and fertilizer.

1. Introduction
The eater consumption for agricultural irrigation is the largest among all production departments in
China, and China is the country with the largest consumption of fertilizer in the world. At the same
time, agricultural irrigation has the disadvantages of uneven distribution of time and space, prominent
contradiction between supply and demand, low utilization efficiency and waste. These shortcomings
further aggravate the shortage of water resources in China. In order to improve the utilization
efficiency of irrigation and fertilization, many irrigate water and fertilizer demand laws and prediction
models have been established, the intelligent irrigation and fertilization controller, control technology
and systems were developed.
Gmez-Chabl et al. [1] developed the irrigation and fertilizer pump control system by using Internet
of Things technology, machine learning algorithm and embedded technology, the system can improve
the efficiency of irrigation water use. Wang et al. [2] developed an irrigation control system based on
Arduino controller by measuring environmental temperature and soil humidity through corresponding
sensors. Kansara et al. [3] used automated technology (AT) command to transmit data collected by
environmental and soil sensors to SIM900A module, which made decisions and sent the remote
control commands for irrigation and fertilization after receiving the data, it can help farmers realize

Content from this work may be used under the terms of the Creative Commons Attribution 3.0 licence. Any further distribution
of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.
Published under licence by IOP Publishing Ltd 1
ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

remote control of irrigation and fertilization. Zhu Jiangbo et al. [4] developed an intelligent platform
for peanut particle image classification using improved neural network image classification algorithm
and support vector machine feature extraction algorithm, which based on Zynq SoC embedded
platform and (Field Programmable Gate Array) FPGA hardware acceleration method. The
experimental results show that the platform has excellent classification accuracy. Shi Xiang et al. [5]
established an irrigation and fertilization control system based on STM32 chip, the system includes the
farmer, control station and the controller. In order to realize variable irrigation, the crop
evapotranspiration is determined by fuzzy decision using the remote sensing data. Wei Leilei et al. [6]
developed a fast and efficient water and fertilizer irrigation control model based on STM32 controller
and the Simulink tool, and realized the automation and accuracy of embedded water and fertilizer
irrigation system by adopting fuzzy PID control method and gray decision-making method.
In general, water-saving irrigation control has made great progress in both theory and technology,
and related systems and equipment can basically realize water-saving irrigation. However, in the
embedded development of precision control system for field and greenhouse irrigation water and
fertilizer, the independent research and development ability of related technologies and systems is
weak, which is mainly reflected in the low precision of irrigation and fertilization decision-making and
control algorithm, and the low integration degree of decision control model and irrigation and
fertilization system. Therefore, the rapid development controller and decision algorithm and fusion
method still need further research.
Based on the images of tomato leaf, we have built a deep learning model for tomato leaf region
segmentation and region information extraction [7]. In order to further improve the integration of the
deep learning model and the irrigation and fertilization system, and improve the intelligent level of the
irrigation and fertilization control system, this paper, The Raspberry Pi-embedded intelligent control
system for irrigation and fertilization based on deep learning were developed. The main research and
development work includes: embedded system hardware and circuit design, hardware type selection
and system circuit design, embedded environment deployment, deep learning model migration and
model compression.

2. System Hardware and Circuit Design

Figure 1. The Control System Block Diagram


An Raspberry Pi-embedded irrigation and fertilization control system based on deep learning was
constructed, and the framework of control system is shown in Figure 1, it mainly includes deep
learning fertilizer identification models, environmental parameter sensors, irrigation control hardware
and remote control. These training and optimization of the deep learning fertilizer recognition models
have been completed in the early stage. This paper studies that the model is transplanted to the
embedded control system. Its software functions include image acquisition module and intelligent
recognition module. The image acquisition module contains a control chip and a camera. The external

2
ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

camera of the control chip collects crop leaf images, and inputs the images into the deep learning
fertilizer model to achieve the classification of crop leaf deficiency and leaf segmentation. These
sensors acquisition part includes temperature sensor, humidity sensor, water flow meter, pressure
sensor, Conductivity of electricity (EC) and PH sensor, etc. to obtain the information of irrigation site.
The on-site control mainly adopts the signal output of Raspberry Pi to control the electric valve, head
pump and frequency converter. The remote monitoring computer connects Raspberry Pi through
secure shell (SSH) protocol or virtual network console (VNC) technology, and remotely controls the
irrigation and fertilization process through Raspberry Pi.
Due to the limited computing and storage capacity of commonly used single chip computers, and
the difficulty in obtaining the low-level development authority of programmable logic controller (PLC)
controllers, the deep learning model cannot be embedded into these two controllers, resulting in the
low level of intelligence of the irrigation and fertilization system developed based on conventional
controllers. The controller model selected in this paper is Raspberry Pi 4B, the main frequency of this
controller reaches 1.5GHz, with 4G RAM and 400MHz Video Core IV GPU. The soil moisture sensor,
flow meter and pressure sensor measure the soil moisture, water transmission pipeline pressure and
flow, and transmit the detected analog signal to the controller through the AD module. When irrigation
and fertilization are required, the digital signal output by the controller is converted and transmitted to
the frequency converter through the DA module, and the frequency of the water pump is controlled by
adjusting the signal output to the frequency converter, the system realizes the regulation of irrigation
pipeline pressure and flow. At the same time, the controller outputs digital signals to the relay, which
controls the solenoid valve to achieve accurate control of fertilizer application. The models of relevant
hardware components are shown in Table 1:
Table 1. The main hardware type selection
Hardware type Product type Hardware type Product type

Controller Raspberry Pi 4B Relay Wave share relay


Soil sensor MS10 Electromagnetic value 2W-160-15
Flow meter YF-S201 Frequency changer A600-2S0015G
Pressure gauge DJ-01 Touch screen 13 inch HDMI
AD/DA module High precision AD/DA board Pump XKJ-804S

3. Migration and Deployment of Deep Learning Models


Many intelligent systems based on deep learning and artificial intelligence have been reported [8-10],
the relevant irrigation and fertilization system only have the automatic control functions. However, the
intelligent level of agricultural irrigation and fertilization control system is not high enough, the deep
learning model trained in the computer is based on the X86 architecture, and its instruction set is
Complex Instruction Set, while the Raspberry Pi's CPU is based on the ARM architecture, and its
instruction set is Reduced Instruction Set Computing, which is a method that executes fewer types of
computer instructions. The architectures of the two CPUs are different, and the deep learning model
trained by the computer cannot be directly applied to the Raspberry Pi-embedded system, and the
environment deployment work in the development of the embedded system is required.
The environment compilation of the deep learning model in the embedded system is compiled with
C language. The source code of the deep learning model can be compiled into binary files and then
installed in the embedded system. The software development of the control system including the
OpenCV environment deployment and the Pytorch deep learning environment deployment, the
detailed configuration process is as follows.

3
ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

3.1. OpenCV environment deployment


The control system uses the classic machine vision code library Opencv, which can provide many
image processing tool libraries, these libraries can also call camera images well. The source code of
the OpenCV were download from the official website(https://opencv.org/), which including the core
source code OpenCV.zip and attachment code OpenCV_contrib.Zip, use the sudo apt get update
command, update the software source and installation package, and install developer tools including
cmake. The tools and third-party libraries required by the OpenCV in this paper are shown in Table 2.
Table 2. The tools and third-party libraries for the OpenCV
Tools & libraries Introduce Tools & libraries Introduce

Build-essential C/C++ environment Libpng12-dev PNG image kit


Cmake Source code compilation Libavcodec-dev Video streaming I/O
Git Remote warehouse Libavformat-dev Video streaming I/O
Pkg-confit Concise compilation Libswscale-dev Video streaming I/O
Libjeg8-dev JPEG image toolkit Libv41-dev Video streaming I/O
Libtiff5-dev Tif image toolkit Gtk2.0 Graphics toolkit
Libjasper-dev JPEG image toolkit Libatlas-base-dev Optimization function

When the deployment of the OpenCV dependent environment and relevant tools is completed,
create a compilation target in the source code folder using the cmake tools. After creating a new build
folder, select the compilation method, installation directory and additional modules loaded, and then
use the sudo make command to compile. This process may take a long time, two hours later, the deep
learning fertilizer recognition model in the article was successfully complied to obtain binary files.
The compiled binary file is installed using the sudo make install command. After the installation is
successful, we use the Raspberry Pi to call the OpenCV library and test the RGB channel separation of
tomato leaf images, as shown in Figure 2, the results indicate that the separation was complete, which
indicating that the OpenCV environment is successfully deployed.

Figure 2. The channel separation of tomato plant leaf by Raspberry Pi.

3.2. Pytorch Deep Learning Environment Deployment


The Python deep learning framework is a major deep learning framework, which is lightweight,
flexible and easy to use. It was widely used in natural language processing and machine vision
applications. The FCN model was used to segment blade image and background, and the model was
training uses the Python deep learning framework in the paper. The deployment of FCN model is
similar to the deployment process of the OpenCV environment. Before the Python environment, it
need to compile the source code in the C language, The Python source code were downloaded from

4
ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

the website(https://pytorch.org/), and the dependency tools and third-party libraries that need to be
installed for FCN model are shown in Table 3:
Table 3. The tools and third-party libraries for the FCN
Tools & libraries Introduce

Numpy Matrix operation library


Torchvision Image datasets, common AI models,
image manipulation
Libopenblas-dev C++ matrix operation library
Cython3 Python-C language interface
Libatlas-base-dev Math library
Libblas-dev Math library
Yaml Data representation library
Setuptools Python library management tool
Wheel Wheel file management library
Pillow Python image processing library

When these dependency libraries were installed, the official Python source code files were
download using the git command, The wheel environment file package were compiled using the
command of python3 setup.py bdist_wheel. These installation process also takes about five hours. The
Python environment deployment is completed after installing the compiled file. After the deployment
of Python and related dependent environments is completed, the FCN deep learning model were
migrated to the Raspberry Pi controller. The migrated model is used for static segmentation of blade
images. The successful segmentation of the image indicates that the embedded model environment
deployment and model migration have been completed.

4. Deep Learning Model Compression


The CNN model was used for tomato leaf pictures classification, and the full convolution network was
used to each pixel classification. The operation of both the FCN and CNN models requires a large
amount of computer memory, which means that the control system requires a central processing unit
with high computing performance, and the computing power of the supporting hardware and the
read/write speed of the memory are also required high performance. The CPU of the Raspberry Pi 4B
was ARM Cortex-A72 1.5GHz, it can be known through experiments that the results of the CNN
model can be output in real time, while the results of the FCN model can be output after a delay of 20s.
Therefore, it is necessary to perform model compression for the FCN model. Wei Yue et al. [7]
pointed out that the redundancy of most deep learning models is concentrated in the deep learning
layer, so the compression of the models is to prune the deep network layer.

Figure 3. The VGG16 model structure.

5
ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

The base networks of two deep learning models in this paper are VGG16, the base network
structure diagram of the VGG16 is shown in Figure 3. This study mainly tailors the basic network
layer of the FCN model and verifies the performance of the trimmed model.
The VGG16 network has five convolution blocks, and the naming method is "convolution block
number-convolution layer number in the block". In this study, the name of the second convolution
layer in the third convolution block was named Conv3-2. The Inter-layer clipping starts from the
deepest Conv5-3 convolution layer, and clipping layer by layer to the shallow layer, one more layer is
clipped each time until the Conv4-1 convolution layer. The total pruning group have 6 groups, a total
of 7 groups with the original model without pruning. The model size, mIou, mPA, and operation time
of deep learning models with different structures were compared, the performance statistical results of
different compression models are as follows shown in Table 4.
Table 4. The performance statistical results of different compression models
Pruning Stratege Size (M) Ratio (%) mIoU mPA Time (s)

1 / 71.1 / 0.91 0.94 12.6


2 Trim to 5-3 layers 62.1 87.3 0.91 0.94 11.2
3 Trim to 5-2 layers 53.1 74.7 0.90 0.92 11.0
4 Trim to 5-1 layers 44.1 62.0 0.91 0.92 10.8
5 Trim to 4-3 layers 35.1 49.3 0.89 0.91 9.3
6 Trim to 4-2 layers 26.1 36.7 0.90 0.92 8.1
7 Trim to 4-2 layers 17.1 24.1 0.87 0.86 7.7

According to the above table, the size of the model gradually decreases and the operation time
decreases accordingly with the layer-by-layer pruning of the convolution layer. At the same time, the
model performance parameters of both the mIou and mPA decrease to varying degrees. In the control
group, the size of the original model of the first group is 71.1M, and the calculation time of a single
image of the embedded system is 12.6s. When the seventh group is trimmed to 4-1 layers, the model
size is the smallest among seven models, and the compression rate is 24.1%, the minimum operation
time of a single image was 7.7s. The corresponding mIoU and mPA are 0.84 and 0.86, respectively,
these are 0.07 and 0.08 smaller than the data of original model, respectively, and the model accuracy is
seriously reduced, the result shows that the 4-1 convolution layer has a significant impact on the
model performance. The FCN model of group 6 has constructed 4-2 convolution layer, the mIoU and
mPA of the model are 0.90 and 0.92, respectively, which are 0.01 and 0.02 lower than those of the
original model, respectively. The ratio of the model size compression is 36.7%, but the running speed
of the model was increased by 35.7%. This drop of model accuracy is within acceptable limits, and the
model size and computation time are significantly reduced.
In general, the deep learning model has a large number parameters in the deep layer, while some
parameters of the deep model have little impact on the performance of the model, so some parameters
and convolution layers of the model are redundant, this result is consistent with the conclusion drawn
by Wei Yue[11]. For different data sets, different model compression strategies can be used to
eliminate unnecessary parameters in the model, and lightweight deployment of deep learning models
can be realized in embedded systems.

5. Conclusions
Based on tomato fertilizer deficiency classification and fertilization decision model based on leaf
images and deep learning, an Raspberry Pi-Embedded intelligent control system for irrigation and
fertilization based on deep learning was developed, which mainly completes the following tasks:

6
ICCBDAI-2022 IOP Publishing
Journal of Physics: Conference Series 2504 (2023) 012034 doi:10.1088/1742-6596/2504/1/012034

1) Main hardware type of control system was selection, which including camera, sensors, head
water pump, frequency converter, solenoid valve. The circuit of control system were designed, which
mainly includes the main waterway circuit connection design and AD/DA module.
2) The application of deep learning model in the controller is completed. The mainly specific
methods of the Opencv and Python environment deployment are described, and the OpenCV and
third-party libraries for two deep models were installed. The source code of these two models were
complied using the C language, and the model environment and migrated were successfully deployed.
3) In order to solve the problems of slow running speed, poor real-time performance and high
computing pressure of deep learning recognition model, the relationship between model compression
and accuracy is studied. The model space compression ratio is 36.7%, and the computing speed is
increased by 35.7%, which makes the deep learning model run faster and more accurately in the
controller.
The research object of this control system is tomato, later research can build deep learning models
for different crops and study different types of fertilizer deficiency. At the same time, the compression
method of deep learning model needs further research.

Acknowledgments
The authors wish to thank the other team-mates for useful comments and discussions. We would also
like to thank the anonymous reviewers for their comments. The work was partially supported by the
Shaanxi Province Key Research and Development Project [2022ZDLNY03-032].

References
[1] Gómez-Chabla R, Real-Avilés K, Morán C, et al. 2019.IoT applications in agriculture: a
systematic literature review[M]: ICT for Agriculture and Environment,2019.
[2] Wang E, Attard S, Linton A, et al. Development of a closed-loop irrigation system for
sugarcane farms using the Internet of Things[J]. Computers and Electronics in
Agriculture,2020,172.
[3] Kansara K, Zaveri V, Shah S, et al. Sensor based automated irrigation system with IOT: a
technical review[J].2015,6(6):5331-5333.
[4] Zhu jiangbo, Research on image classification algorithm of granular crops based on embedded
platform[D]. Harbin Institute of Technology,2019.
[5] Xiang Shi, Development of variable rate irrigation system based on uav remote sensing and
ground monitoring data[D]. Northwest A&F University,2020.
[6] Leilei Wei, Zhengying Wei, Yubin Zhang,et al. The rapid development of fertilizer irrigation
controller baded on MBD[J]. Water Saving irrigation, 2017(7):124-129.
[7] Weibing Jia, Haoran Wei, Zhengying Wei. Tomato fertilizer deficiency classification and
fertilization decision model based on leaf images and deep learning[C]. International
Conference on Computer, Artficial Intelligence, and Control Engineering(CAICE 2022),
doi:10.1117/12.2640974.
[8] N. Bharathiraja, Pydimarri Padmaja, S. B. Rajeshwari, Jagadish S. Kallimani, Ahmed Mateen
Buttar, T. Bheema Lingaiah, "Elite Oppositional Farmland Fertility Optimization Based
Node Localization Technique for Wireless Networks", Wireless Communications and
Mobile Computing, vol. 2022, Article ID 5290028, 9 pages, 2022.
[9] Bharathiraja N,Ravindhar N V, Joel John M, Pradeepa K , Gopirajan PV, & Nagu, B. . (2021).
Predictive analysis of agricultural crops in cloud computing using sensor networks. Solid
State Technology, 63(2S), 5461-5477.
[10] Bharathiraja, N. , Shobana, M. , Manokar, S. , Kathiravan, M. , Irumporai, A. , & Kavitha, S. .
(2023). The smart automotive webshop using high end programming technologies.
[11] Yue Wei, Shichao Chen, Fenghua Zhu, et al. Pruning Method for Convolutional Neural
Network Models Based on Sparse Regularization[J]. Computer Engineering,
2021,47(10):61-66.

You might also like