Detection system of dead and sick chickens in large scale farms based on artificial intelligence

: With the continuous enrichment of scientific and technological means, the production of most chicken farms has been able to achieve automation, but for the dead and sick chickens in the farm, there is no automatic monitoring step, only through continuous manual inspection and discovery. In the face of this problem, there are many solutions to identify dead and sick chickens through sound and image, but they can not achieve the ideal effect. In this paper, a sensor detection method based on artificial intelligence is proposed. This method 1) The maximum displacement of chicken activity is measured by fastening a foot ring on each chicken, and the three-dimensional total variance is designed and calculated to represent the chicken activity intensity. 2) The detection terminal collects the sensing data of foot ring through ZigBee network. 3) The state of chicken (dead chicken and sick chicken) can be identified by machine learning algorithm. This method of artificial intelligence combined with sensor network not only has high recognition rate, but also can reduce the operation cost. The practical results show that the accuracy of the system to identify dead and sick chickens is 95.6%, and the cost of the system running for 4 years can be reduced by 25% compared with manual operation.


Introduction
Nowadays, in modern chicken farms, the supply of feed and water, the collection of eggs and chicken manure, the control of temperature and wind speed, etc. have been automated. But for the detection of dead chickens and sick chickens, it still uses manual regular inspection and inspection. If dead chickens and sick chickens are not checked and cleared in time, it will cause great harm and loss. On the one hand, according to medical knowledge, two hours after the normal death of the chicken, the muscle and blood began to breed bacteria, five hours later, the number of bacteria multiplied, which will cause great harm. If the abnormal death caused by infectious diseases, it may lead to cross infection between chickens, if not cleared in time, the chicken farm will suffer huge economic losses. On the other hand, the chicken epidemic, especially the avian influenza epidemic, is still an important factor to inhibit the development of China's poultry industry. There is no effective treatment and prevention method for the avian influenza epidemic. Once the outbreak of the epidemic, only through a large number of slaughtering to prevent the spread of the epidemic, causing huge losses to farmers. It is an important way to reduce economic losses to find out the epidemic situation in time and take countermeasures as soon as possible [1][2][3]. The manual inspection of dead and sick chickens is a trivial and meticulous work, and it will have a serious impact on the health of workers if they travel in the poor environment for a long time. Therefore, the development of an automatic detection system for dead and sick chickens is of great significance to reduce the labor intensity of workers, improve work efficiency and improve the working environment of workers [4,5].
With the development of information processing technology, artificial intelligence technology and Internet of things technology, it has a profound impact on the traditional way of livestock breeding in the past. Wang et al. [6] reviewed the monitoring technology of poultry behavior and physiological information, Wang et al. [7] studied the method of identifying sick chicken by broiler feces, and Liu et al. [8] designed the method of detecting sick chicken by abnormal sound of broiler, Aydin [9] carried out computer vision research on lameness of broilers, Cedric et al. [10] studied the early detection and prediction system of sick birds through machine vision system, Aydin [11] used three-dimensional vision camera system to automatically evaluate the inactivity level of broilers.
The above research is aimed at the artificial intelligence method of chicken feces, sounds, images, etc., but because of large-scale chicken farms, chickens live in a narrow space in chicken cages, so it is not easy to obtain the characteristics of chicken feces, sounds, images and other characteristics. There are many questions about information noise, which leads to low recognition rate, so it can only stay in the theoretical research of ideal environment, It is difficult to be practical. Not only that, but also the implementation cost.
In view of the shortcomings of artificial detection of dead and sick chickens and the difficulty of identifying dead and sick chickens, this paper proposes a detection method of dead and sick chickens based on artificial intelligence. This method measures the maximum displacement and three-dimensional total variance of the chicken by fastening a foot ring on each chicken, and identifies the state of the chicken by machine learning method, so as to identify the dead chicken and sick chicken. Through the wearable multi-sensor system to detect the shape of animals, there are also related studies in the intelligent farm [12][13][14]. In this paper, the foot ring of chicken adopts 6-axis MPU6050 sensor to calculate the three-dimensional displacement of chicken with high precision (the precision is several centimeters). The detection terminal displays the activity state of each chicken through wireless ad hoc network with foot ring. The detection terminal is connected to the system through network, so as to realize the automatic detection of dead and sick chicken.
The contributions and innovations of this paper are summarized as follows: • The system architecture of dead and sick chicken characteristic analysis and detection.
• The calculation method of three-dimensional total variance of chicken was put forward.
• The realization principle of foot ring and detection terminal.
• Research on machine learning recognition method of chicken activity state. The rest of the paper is organized as follows. In the second section, the analysis and system architecture of the detection system for dead and sick chickens are carried out. In the third section, the calculation method of three-dimensional total variance is proposed, and the implementation principle of foot ring and detection terminal is introduced. In the fourth section, the machine learning recognition method of chicken activity state is proposed. The fifth section is the comparative analysis of experiment and results, and the sixth section is the conclusion.

Analysis on characteristics of dead and sick chickens
The characteristics of dead chicken should be analyzed first. The previous methods of artificial experience analysis include: • Feel your temperature. The thigh roots of sick chickens are hot and cold, and the crowns are hot; The thigh root of healthy chicken is cold and hot, the comb is not hot.
• Check the skin color. The muscle of sick chicken is thin, stiff and inelastic, and the skin color is dark red; The skin color of healthy chicken is reddish, and the muscle is plump and elastic.
• Look at the anus. In addition, the anus is dark red, and its feces are mostly white or yellow green. The villi near the anus of healthy chickens are clean and dry, and the anus is moist and reddish, and its feces are semi-solid.
• Look at your eyes. The eyes of diseased chickens are dull, weeping, or there are cheese like secretions around the eyes, and the eyes of individual chickens will become longer; Healthy chicken has bright eyes and flexible eyeballs.
• Listen to the sound. At 3-5 o'clock in the morning, when you listen to the chicken's voice quietly, the sick chicken will make a slight "hiss" call, or even no sound, and there will also be a similar frog's purr, scream, or strange cry; Healthy chickens make loud, clear calls.
• We should pay attention to behavior. Sick chicken spirit is dispirited, the pace is unsteady, the appetite is weak, also is not willing to move to eat the material, if the chicken died, will not move; Healthy chicken is lively and active, with strong legs and feet, and willing to move to eat.
In the process of raising chickens, we can find the dead chickens as early as possible by analyzing the characteristics of chicken flock from the above six aspects. However, for large-scale breeding of chickens, the number of chickens is very large and dense. There are hundreds of thousands or even millions of chickens. If they pass the artificial detection, it will cost huge human and financial resources. Suppose that in the narrow space of chicken cage, it is not easy to obtain the accurate information of chicken's sound, image, temperature and other characteristics through the detection method from the above 1)-5), and there is also information noise; It is a good choice to judge whether the chicken is sick or dead by the detection method of 6) and the behavior of the chicken obtained by the sensor. There have been relevant researches, which use acceleration sensors to judge people's behavior. Jia et al. [15] have studied people recognition based on walking acceleration information segmentation, and Zhang et al. [16] have studied gait recognition based on acceleration. Therefore, starting from this idea, the architecture of the whole system is designed.

System architecture
In modern chicken farms, chickens are very concentrated, for example, a breeding room for 40,000 chickens, a chicken cage with a size of about 60 cm * 60 cm * 50 cm, and 8 chickens need to be cultured, as shown in Figure 1. It is still a little difficult to find dead sick chickens automatically in such a small space. Through the analysis of the characteristics in Section 2.1, it is a good choice to adopt the acceleration measurement technique.
Single chicken cage size  The status of the LED light indicates the activity status of the chicken, as shown in Table 1. The management personnel can not only see the status of the chicken at the scene and judge the dead chicken through the LED light in front of the chicken cage, but also find the dead chicken through the system software or app remotely. According to the above requirements, the dead chicken detection system is designed, which can realize on-site detection and remote detection. The framework of the system is shown in Figure 3. The hardware part of the system is mainly composed of several chicken cage detection units, which are composed of eight foot rings and one detection terminal; The system software is mainly composed of communication front-end processor, data server, web monitoring client and app.

Web monitoring client
Detection terminal

System method
The measurement method adopted by the system is to measure the displacement through the acceleration sensor, and there are many related researches. Bi et al. [17] measured the body trajectory through the acceleration, and Li et al. [18] measured the seismic scene stratification through the built-in acceleration of the mobile phone. In the design of the system, we should first know the principle of acceleration measuring displacement, and then verify the feasibility of the method through simulation experiments.

Control principle of displacement measurement by acceleration
When the acceleration signal is integrated to calculate the displacement, the acceleration data obtained is a group of discrete values [19]. When n > 1, in the discrete domain, the velocity and displacement formula of n point are calculated by acceleration, as shown in Eqs (1) and (2).
In Eqs (1) and (2) (1) and (2), the displacement of the target in one direction at n poin can be obtained, and the calculation formula is Eq (3).

Calculate the three-dimensional total variance
3.2.1. Calculate the one-way displacement variance of time period T • By sampling the acceleration value, the displacement from T1 to T2 is calculated. If the acquisition interval is set as △ t = 100 ms and the acceleration sampling time is 100 ms, the total sampling times from T1 to T2 is n = (t2-t1) / △ T, the real-time motion displacement is s [n], and the calculation formula is Eq (4).
• There are M time periods (t2-t1) in t time, and the calculation formula is Eq (5).

Calculate the displacement variance of time period T
As the variance is the square of the data, it is too different from the detection value itself, so it is difficult for people to measure it intuitively. Therefore, we often use the root of variance to convert it back. This is what we call the standard deviation. The variance describes the degree of deviation and fluctuation. and the calculation formula is Eq (7).

Mobile phone simulation of displacement calculation by acceleration
Almost all mobile phones contain three-axis acceleration. In order to verify the feasibility of the algorithm design, we first write a mobile phone app for simulation test verification. Finally, the design and implementation of the foot ring are completed.

Test three-dimensional acceleration curve
Android operating system is selected for the test mobile phone, which is developed by Android studio tool. The three-axis acceleration is tested by using sensormanager class. In the static state, the three-axis acceleration data curve can be tested in real time. Due to noise interference, the curve will fluctuate [20]. The data curve is shown in Figure 4. Because the z-axis is vertical, the z-axis acceleration is about 9.8 m/s 2 , and the x-axis and y-axis acceleration is about 0.0m/s 2 . Therefore, the data curve of the adjusted three-axis acceleration is shown in Figure 5. In the horizontal direction, when the mobile phone moves slightly, even a few centimeters, the x-axis acceleration or y-axis acceleration will fluctuate. For example, the x-axis acceleration fluctuation curve in the three-axis acceleration is shown in Figure 6. According to the principle of Section 3, the main steps are as follows: • Set the acceleration sampling frequency. Set △T= 100 ms and sample the acceleration once.
Because of the different sensitivity, the first step is to correct. After correction, the three-axis accelerations Gx, Gy and Gz are almost 0.
• Set the positioning time t to calculate the displacement s. Set T = 1 minute, calculate the displacement once in 60 seconds, n = 60 / 0.1 = 600 times, calculate the minute displacement through Eq (4), which are Sx, Sy, Sz respectively. The total displacement S = Sx + Sy + Sz is calculated.
• The cumulative m-minute triaxial displacement variance was calculated. The mean displacement in M minutes is calculated by Eq (6), and then the variance Va, Vb and Vc of triaxial displacement are calculated by Eqs (8)- (10).
• The cumulative M minute displacement variance was calculated. The total variance Vtotal is calculated by Eq (11).
• The maximum displacement Smax of cumulative m minutes is calculated. Total variance Vtotal and maximum displacement Smax are used as the input of machine learning classification algorithm.

Mobile phone interface for testing sensor data
The interface of a group of mobile app real-time data is shown in Figure 7. The process data included in the interface are: three axis real-time acceleration, three axis real-time displacement, cumulative minute, three axis minute displacement. The final calculated data are: maximum minute displacement, total three-dimensional displacement and total variance.

Summary of simulation test
Through the simulation test of the acceleration of the mobile phone, the results are as follows: 1) when the mobile phone is not moving, the maximum total displacement and three-dimensional total variance are almost 0; 2) no matter the mobile phone moves up and down, left and right for 1cm, there will be displacement in three directions; 3) calculate the displacement per minute. By calculating the maximum minute displacement, we can know the maximum activity of the mobile phone, 4) By calculating the variance of three-dimensional displacement per minute, the total variance of three-dimensional displacement can be calculated, so that the deviation and rhythm of mobile phone movement can be known.
It is not difficult to see from the simulation test results of mobile phone that it is feasible to apply this calculation method to the foot ring of chicken. Through the mobile phone test, it provides a feasible technical solution for the implementation of the system.

Design of foot ring and detection terminal
The hardware part of the system is mainly composed of several chicken cage detection units. The chicken cage detection unit is composed of eight foot rings and one detection terminal. The eight foot rings and one detection terminal automatically form a ZigBee wireless network. The detection terminal collects sensor data and displays the activity status of the chicken through the indicator light.

Design of foot ring
The foot ring is mainly composed of sensor unit, battery unit and microprocessor unit. Its composition is shown in Figure 8. • The sensor unit adopts the first sensor MPU-6050 which integrates six axis motion processing components in the world. Compared with the previous multi-component scheme, MPU-6050 avoids the difference between gyroscope and accelerometer, and reduces a large number of packaging space, which makes it compact and efficient. When the chicken ring moves, MPU-6050 produces triaxial acceleration and calculates it by microprocessor, and obtains the maximum displacement and three-dimensional variance of chicken. The detection terminal indicates the activity intensity of chicken after receiving these data.
• The main function of the battery unit is to supply power to the whole equipment and ensure that the equipment can run. In the choice of battery, we need to consider two points: 1) the battery volume is relatively small, to ensure the whole volume of the chicken ring in a small volume, let the chicken wear the chicken ring is more comfortable, will not let the chicken to deliberately break the chicken ring phenomenon. 2) Relative to the maximum power under the volume, the volume ensures the maximum power under the limited basis, which can ensure that the chicken ring can run for a long time without frequent replacement of equipment, so as to save the economic cost and time cost.
• The microprocessor unit adopts the ZigBee chip CC2630 of Texas Instruments (TI). Compared with the same ZigBee bit processor CC2530, the advantages of CC2630 are: more powerful MCU processing power and lower power consumption. CC2630 contains a 32-bit arm cotex-m3 core. Compared with the 8051 core of CC2530, the performance of CC2630 is more powerful and the cost is also lower. At the same time, CC2630 has a very unique ultra-low power sensor controller based on cotex-m0. CC2630 has a rich set of peripheral functions. In addition, the function set is designed to connect with CC2630's unique ultra-low power consumption sensor controller. This unique connection mode can ensure the independent collection of analog and digital data without waking up the main control unit of MCU. Therefore, the data collection is realized through battery power supply in zibgbee network, CC2630 is the best choice.
• The actual development pictures of the foot ring is shown in Figure 9, the physical simulation picture is shown in Figure 9(a), and the actual picture of the foot ring is shown in Figure 9

Design of detection terminal
The detection terminal is mainly composed of storage unit, battery unit, indicator unit, wireless transmission unit and microprocessor unit. The principle block diagram of the detection terminal is shown in Figure 10. • The storage unit is mainly composed of flash chip. The main function of the storage unit is to store the collected data of the foot ring. Wireless transmission of data is very limited consumption, so the collected data can not be uploaded to the front-end computer in the form of real-time data. It needs to be stored and transmitted to the master station at a time.
• The battery cell is used for power supply. Compared with the chicken ring, the battery cell has no volume requirements, and its capacity can be larger. It does not need high size and capacity requirements like the limb ring.
• The indicator light unit is composed of eight LED lights, corresponding to the status of eight chickens in the chicken cage. In this way, the chicken farm managers can more intuitively judge the sick chickens in the chicken cage, so as to improve the efficiency.
• The wireless transmission unit is mainly composed of WiFi module and ZigBee module. The WiFi module is mainly used to upload the collected sensing data to the front-end computer, which is convenient for the master station to analyze. The WiFi module uses the ESP32 of Shanghai Lexin. After the ESP32 is powered on, it is set as the terminal and automatically connects to the wireless router to realize data transmission. ZigBee wireless ad hoc network is a function of microprocessor CC2530.
• Microprocessor unit, CC2530 of Ti. Although CC2630 is also ZigBee network microprocessor, Ti defines CC2630 as the ZigBee network terminal with ultra low power consumption. CC2630 has the function of adding ZigBee network, but not the function of setting up ZigBee network. Therefore, the microprocessor adopts CC2530 chip. CC2530 establishes ZigBee network through panid and channel, and the pin ring adds to the corresponding ZigBee network according to these two parameters to realize the interaction of ZigBee messages, the communication protocol adopts industry standard MODBUS; After the artificial intelligence learning of the collected data of the foot ring, the state of the chicken is analyzed, and the corresponding LED light is illuminated to display the status of the chicken intuitively; Meanwhile, the status information of chicken will be sent to the main station of the front-end computer through WiFi module and via WiFi network, and the alarm information will be sent to the administrator for troubleshooting.

Judging the chicken activity state by machine learning method
Artificial intelligence learning is carried out by supervised learning classification method. The training and learning steps are shown in Figure 11. Firstly, the acceleration sensor is used to collect the data of chicken foot ring; Then, the displacement is calculated to obtain the maximum displacement and the three-dimensional total variance as (x1, x2); The following is divided into two parts: a) through machine learning classification algorithm training data, get the best training model. b) The activity behavior of chicken was identified by training model.

Data preparation
Through the data collected from the gateway by the foot ring sensor, the machine learning is carried out to judge the activity state of the chicken. Since the activity time of chicken is from 5: 00 am to 8: 00 pm, the data is collected from 5: 00 am for 15 hours, and the maximum displacement Smax and total variance vtotal are finally collected.
• Examples of typical sample sets: A typical sample set of four classifications is shown in Table 2.

Machine learning algorithm
Through five kinds of classification algorithm SVM, KNN, DT, NB, BP for abnormal behavior recognition effect.
• SVM is a new learning method proposed by Cortes and Vapnik according to the statistical learning theory. Its biggest feature is that according to the structural risk minimization criterion, it constructs the optimal classification hyperplane with the maximum classification interval to improve the generalization ability of learning, and better solves the problems of nonlinearity, high dimension, local minima and so on [21,22].
• KNN is a case-based classification method. This method is to find out the K training samples closest to the unknown sample x, and gather x into the category that most of the K samples belong to [23].
• DT is a case-based inductive learning algorithm, which aims to infer the classification rules represented by DT from a group of unordered and irregular cases. The purpose of constructing DT is to find out the relationship between eigenvalues and categories, and use it to predict the categories of unknown samples [24,25].
• NB is a simple probability Classification Based on Bayesian theorem of independent hypothesis. Its principle is to use Bayesian formula to calculate the posterior probability through the prior probability of an object, that is, the probability that the object belongs to a certain class, and select the class with the maximum posterior probability as the class that the object belongs to [26][27][28].
• BP neural network is a kind of multilayer feedforward network trained by error back propagation (referred to as error back propagation). Its algorithm is called BP algorithm. Its basic idea is gradient descent method. Gradient search technology is used to minimize the mean square error between the actual output value and the expected output value of the network, Its outstanding advantages are strong nonlinear mapping ability and flexible network structure [29][30][31][32][33].

Experimental results of power consumption and communication performance
In the whole system, the design of power consumption and communication performance of the terminal is very important. It needs to pass the necessary tests to determine whether it meets the requirements of the design and site. The test of terminal equipment is divided into two parts: • Power consumption test: since the feet are powered by batteries, it is necessary to ensure that the batteries will not be changed in a chicken breeding cycle (400 days), so there is a design requirement: the power consumption should be less than 400 mAh. CC2630 chip is used in the design, which has very low power consumption, is usually in sleep state, and uploads to the detection terminal once every 10 minutes. The measured power consumption data of the foot ring 0.9 mAh per day, then 360 mAh per 400 days. Only one detection terminal is placed in a chicken cage unit, so the battery is easy to replace and can be replaced once a month. Therefore, there is a design requirement: the power consumption should be less than 2000 mAh. CC2530 chip is used in the design, which also has very low power consumption and can collect sensor data, the power consumption in one day is 62.5 mAh, then 1875 mAh in 30 days. The specific data are shown in Table 3. • Because the dead chicken is inactive, the maximum displacement Smax and three-dimensional total variance vtotal are almost 0, the recognition accuracy of the five kinds of chicken is 100%, and the recognition accuracy of the active strong chicken is almost 100%. The key point is that it is difficult to distinguish the sick chicken and the active weak chicken. Because some good chickens are weak in activity and behave like sick chickens, it is sometimes difficult to distinguish them. However, due to the weak activity of chicken to eat, the maximum displacement will be large, so it can also be distinguished, but the recognition accuracy will be low.
• Through the operation of five classification algorithms, BP algorithm has the highest recognition rate, so BP is selected as the final classification algorithm.
• If the sick chicken and the weak chicken are classified into one category, then the recognition rate is higher, but in the practical application, more than once, but the detection of the sick chicken will not be missed.

Comparative analysis of operation cost
Through field research, suppose a chicken shed with 40,000 chickens needs 4 workers for artificial breeding and 2 workers for systematic breeding. The salary cost of a worker is 100,000 yuan a year, and the material cost of a chicken foot ring is 10 yuan (about 10 yuan in fact). Then, compare and analyze the total cost of labor and system, and the comparison results are shown in Table 5. It can be seen from the results that the cost of running the system for 2 years is equivalent to that of labor, and the cost can be saved after 2 years.  1  2  20  40  60  2  2  20  40  80  3  2  20  40  100  4  2  20 40 120 From the results in Table 5, it can be seen that the total cost of running the system will continue to decrease over time. The comparison of cost histograms for four years is shown in Figure 12. According to the results in Table 5, we can also analyze and calculate the total cost trend of 8-year operation, and compare it with the labor operation cost. The cost trend curve is shown in Figure 13. Through the comparison curve of cost trend in Figure 12, we can see that: 1) the cost can be recovered after 2 years of operation, 2) the cost can be reduced by 25% after 4 years of operation, 3) the economic benefit of one million will be produced after 8 years of operation, and 4) the greater economic benefit will be produced if a larger scale chicken farm is operated. Therefore, compared with manual operation cost, the system not only improves the recognition accuracy, but also creates higher economic value.

Conclusions
In view of the shortcomings of artificial detection of dead and sick chickens, this paper proposes a detection method of dead and sick chickens based on artificial intelligence. This method measures the three-dimensional displacement of the chicken by fastening a foot ring on each chicken, and designs and calculates the three-dimensional total variance to express the activity intensity of the chicken. Finally, the machine learning classification method is used to identify the status of the chicken, so as to realize the correct judgment of dead chicken and sick chicken. The foot ring and detection terminal are powered by ZigBee ad hoc network and low-power battery. The maximum displacement and three-dimensional total variance are used to represent the activity state of chicken. The experiment shows that the recognition accuracy is 95.6%, which can achieve practical effect, reduce manual labor and improve the work efficiency. However, in the implementation of the whole system, the workload is a bit heavy, there is still room for further research in the aspect of big data mining and analysis after sensor acquisition.
The follow-up work will do further research on big data mining and analysis. In addition, on the cost of installation and implementation, we need to spend more time on research, more efforts should be made to prepare for the large-scale promotion of this technology. If the system can be successfully promoted, it will produce greater economic and practical value for human large-scale breeding.