Research on Intelligent Embedded Fan System Based on YOLOv2 Lightweight Algorithm

With the development of artificial intelligence, the application of intelligent algorithms to low-power embedded chips has become a new research topic today. Based on this, this study optimizes the YOLOv2 algorithm by tailoring and successfully deploys it on the K210 chip to train the face object detection algorithm model separately. The intelligent fan with YOLOv2 model deployed in K210 chip can detect the target of the character and obtain the position and size of the character in the machine coordinates. Based on the obtained information of character coordinate position and size, the fan's turning Angle and the size of air supply are intelligently perceived. The experimental results show that the intelligent fan design method proposed here is a new embedded chip intelligent method of cutting and improving the YOLOv2 algorithm. It innovatively designed solo tracking, crowd tracking, and intelligent ranging algorithms, which perform well in human perception of solo tracking and crowd tracking and automatic air volume adjustment, improve the accuracy of air delivery and user comfort, and also provide good theoretical and practical support for the combination of AI and embedded in other fields.


Introduction
Artificial intelligence is an important part of the future society. It is also a trend of social development to combine home life with artificial intelligence and form a smart home.
Product automation has been developing for more than 70 years since automatic control began after the 1950s as an important means to improve productivity. e concept of smart home emerged in the late 1980s, and people began to have a sense of change from automation to intelligence, but now the so-called smart home, more accurately said should be the Internet of things home, is more inclined to home product interconnection and communication, rather than to give products with intelligence [1,2]. e current smart home products are not intelligent and have more inclined automation and networking functions. e main reason for this situation is that the traditional embedded chips cannot meet the requirements of high-speed massive numerical computing. Traditional embedded chips are not powerful enough to carry out large-scale parallel computing and run model files generated by deep neural networks. Traditional sensors such as temperature and humidity sensors [3], human infrared sensing sensors, and various gas sensors collect extremely limited information. To gradually transform the traditional automated home or other automation devices into a smart home or smart device, an AI-embedded chip platform that can perform neural network processing is needed [4].
At present, most smart devices work by transmitting photographs, audio, and other data to the cloud server for computing and then returning the computing results to the terminal. Although this way can give full play to the powerful computing power of cloud servers, it makes the devices have a strong dependence on the network, with low real-time performance, and it is not suitable for small intelligent devices with high real-time requirements. How to better combine artificial intelligence technology and hardware products in different fields is a problem worth studying in intelligent product design at this stage [5][6][7][8].
e design conducts information collection and feedback through AI, deploys AI model into embedded devices, and upgrades embedded to intelligent embedded, to improve the intelligence of traditional embedded products. Here, we take the design implementation of an intelligent fan product as an example to illustrate the practical significance of this design idea and method.
Today, although air conditioning has entered thousands of households, the traditional electric fans still occupy a large market share. Since the advent of the electric fan, the degree of automation has been continuously improved. e original electric fan canonly supply air in one direction, to the later in a fixed Angle to supply air, and now through the remote control fan switch, speed, and so on [9]. e current electric fan cannot be realized, intelligent judging the distance between people and the fan, automatically adjusting the speed of the fan. And the fan steering cannot change with the change of the person's position. Based on the above analysis of the research situation of home products, intelligent devices, and fans, this study studies this situation in depth, through the YOLOv2-based intelligent embedded fan system lightweight algorithm research, and strives to solve the problem of home intelligent product design [10].

Domestic-Related Work.
At present, the fan in the domestic market, for example, household electric fan, has air conditioning fan, intelligent floor fan, leafless fan, etc. ese traditional fan wind speeds on the market cannot be adaptively adjusted when selected, and the air volume cannot be automatically changed when the distance between the user and the fan changes. Part of the fan can shake the head within the set range, but cannot according to the position of the person, and to change the head range of the fan, blowing air does not blow people, resulting in empty waste. Fans in the domestic market generally lack a low degree of intelligence, operation, and adjustment machinery and empty range waste [11]. Figure 1, a foreign intelligent fan is composed of fan, power supply circuit, control circuit, infrared remote control sensor, and the swing motor used to make the fan swing, and this intelligent electric fan adopts 8 frequency conversion wind design, low noise, double circulation of the fan blade, 101 cutting airflow, 85°up and down, 60°left and right, the height of three adjustable, the use of the same as natural wind and air supply distance is far, but the fan cannot change with the position of people, follow people to turn.

Foreign-Related Work. As shown in
is fan is a typical representative of the traditional automatic fan, through the cycle execution control program to achieve the set function, and the overall function is still more traditional. Traditional automation can only obtain simple information such as temperature and humidity, but cannot identify and extract relatively complex information such as face and human body [12] and cannot achieve more advanced intelligence of the product based on this information.

Based on the Lightweight YOLOv2 Algorithm Process and
Working Ideas. YOLOv2 paper full name is as follows: YOLO9000: Better, Faster, Stronger. Although YOLOv1 has a fast detection speed, it is inferior to R-CNN in accuracy, which is not accurate enough in object location and has a low recall rate. YOLO system consists of 24 convolutional layers and 2 fully connected layers. e convolutional layer extracted features, and the fully connected layer predicted the probability of image location and object category. e fully connected layer was removed, so that the SS(B5 + C) structure behind it would stop at the location of 77 channels, and the previous pooling layer was abandoned for the convenience of later calculation. us, it can be obtained that this step is the situation of 1313 channels, and it starts to use the RPN of faster R-CNN for reference to select anchor and use anchor to predict the boundary box. So, YOLOv2 has changed the predictable range from 772 to 1313 * num_ anchors, which has resulted in a huge increase in the number of predictable boxes [13].
e reason why YOLOv2 is selected is that the relatively new model consumes huge memory resources, while YOLOv2, as an early model, consumes less resources, and the work in this study is mainly about object detection and classification [14,15]. YOLOv2 is enough to meet the requirements and can adapt to the embedded microcontroller with limited resources through clipping [16]. In addition,    [17] and then combined with the face detection model to realize face recognition [18][19][20]. e specific programming idea is shown in Figure 2.
YOLOv2 makes the number of predicted boxes more by introducing anchor boxes, and Table 1 is the difference between not introducing anchor boxes and introducing anchor boxes.
Kanzhi K210 is an edge-side AI chip independently developed by Kanan Technology, based on RISC-V architecture and built-in convolutional neural network accelerator KPU.
Model files in H5 format are trained through Keras model library. e h5 file is converted to tflite file, and then, the nncase file is converted to kmodel model. e kmodel model has v3 and v4, and the model is converted with nncase v0.1.0. RC5 is v3 model. v3 has less code, less memory, and high efficiency, but less operators. Finally, the kmodel model was downloaded into the flash of k 210 with the following loading code: import KPU as kpu model_addr_in_flash � 0 × 300000 task � kpu.load(model_addr_in_flash) e model_addr_in_flash here is the offset address of the model in the Flash code � kpu.run_yolo2(task, img) Images were object-detected by running the YOLOv2 network.

Single-Person Tracking Algorithm Design Based on
YOLOv2.
rough the YOLOv2 target detection of the  image, we can easily get the position coordinates and prediction box size of the target in the image [24]. rough location information, we can obtain the relative position of the target and the camera with the camera as the reference frame. Next, a central position and central area are determined in the image collected by the camera, and the central position is the position of the position coordinates of the target. e central area is the area that determines whether the fan is facing the target. If the position is in this area, it indicates that the fan is facing the target, and if the position is outside this area, the fan needs to control the steering gear, so that the position coordinates of the target coincide with the central area. Coincident means that the fan has been realigned to the target. erefore, the process of the program is as follows: the face position coordinates obtained by the face detection algorithm are compared with the central position and the central area. When the fan is still and the face position is within the central area, it indicates that the fan is facing the user. When the face position is outside the central area, the deviation between the face position and the central position is calculated, and the rudder is determined according to the deviation size, as shown in Figure 3. e rotation direction and rotation speed of the machine reduce the deviation to the allowable range. e greater the deviation, the faster the rotation speed, and the smaller the deviation. e fan can quickly track the face and ensure the steering gear, reduce the noise of tracking, and prolong the service life of the steering gear. e flow of steering gear to control the fan is shown in Figure 4.
When running the single-person tracking mode, the fan is initialized and scanned in the rotation range, moving first to the left to the left boundary, then from the left boundary to the right boundary, and then left from the right boundary to the original position. When the fan has not detected the face at the end of an initialization cycle, the initialization cycle procedure is repeated. When the fan detects the face, it jumps to the initialization loop program and runs the singleperson tracking algorithm to continuously track the user. e deviation of the face and camera center and the rotation parameters of the steering gear are as follows.
In the following formula, E is the new gear angle input variable and angle is the current gear angle parameter.  First, the fan controls the horizontal steering gear from left to right, and when the fan first identifies the user and the user is in the middle of the fan, the current fan orientation of the angle is recorded, which is the left boundary of the crowd. en, the fan continues to rotate from left to right. When the fan recognizes the user again and the user is in the middle of the fan field, the orientation angle of the current fan is the right boundary. is step is repeated to update the right boundary position in real time until the initialization scan is completed. e flow chart of crowd tracking algorithm is shown in Figure 5.
When the left boundary of the fan reaches the left boundary, the camera detects whether the fan is to the left of the fan, records the current steering angle as the new left boundary, and then controls the steering machine to turn right. When turning right to the right boundary, the above procedure is performed.

Calculation of Human-Fan Distance.
e dynamic air volume adjustment of fans first calculates the distance between human fans through visual ranging and then controls the speed of the fan motor based on different distances, to realize the dynamic adjustment of the air volume with the distance between people and fans, so that the body sensing air volume blowing to the user remains relatively constant.
As one of the basic technologies in the field of machine vision, visual ranging has been widely paid attention to. It plays an important position in the field of robot and is widely used in machine vision positioning, target tracking, visual obstacle avoidance, etc. Machine vision measurement is mainly divided into monocular visual measurement, binocular visual measurement, and multilocular visual measurement. e synergy between cameras in binocular and multilocular systems is not well controlled, and the monocular visual system can overcome the aforementioned synergy between cameras. In terms of production cost, monocular vision is more cost-saving than binocular and binocular systems. Monocular visual ranging has the advantages of simple structure, fast computing speed, and low cost, which is suitable for scenes with low-ranging accuracy requirements. erefore, this design adopts single-visual distance to human distance measurement. e principle of single-visual ranging is similar to that of pore imaging.
As shown in Figure 6, assume a target or object of width W. is target is placed at a D distance from the camera. e object is photographed with a camera and the pixel width P of the object is measured.
is gives the following formula for the focal length of the camera:  (2) When continuing to move the camera near or away from the object or target, you can use a similar triangle to calculate the distance of the object from the camera: us, if the focal length of the camera and the size of the target object are known, the distance between the targets to the camera can be obtained according to the formula (2). e fan wind speed can be adjusted according to the distance.
By measuring the size of several groups of prediction frames and the data of the distance between the human fan and the prediction frame, the function of the distance between the human fan and the prediction frame is constructed to calculate the distance between the human fan and the prediction frame. As shown in Table 2, the prediction box and fan distance function are built to realize the fan distance estimation, and the figure is the prediction box pixel width (W), pixel height (H), pixel diagonal length (X), and fan distance (Y).
By curve fitting the data in Table 2 with MATLAB, Figure  7 and Formula 4 can be obtained as follows: In particular, p1 � −4.055e-05, p2 � 0.01971, p3 � −3.203, and p4 � 196.6; according to formula (4), we can draw from the diagonal of the prediction box the distance between the target and the camera. e calculation of human-fan distance is realized.
According to the X-Y function curve in the above figure, the human-fan distance Y can be estimated through the diagonal X of the prediction box, to adjust the air volume.

Dynamic Adjustment Algorithm of Wind Volume.
e essence of air volume control is to control the motor speed. According to the different working power supplies, the motor can be divided into DC motor and AC motor.
ere are two common methods to change the rotation speed of the AC motor: the first is to change the frequency of the alternating current at the input end, which can be achieved through the frequency converter; the second is to change the rotation speed at the output end, that is, to change the gear speed of the AC motor in proportion, which can be achieved through the deceleration box. For a DC motor, its power supply voltage is a DC input, which can be controlled by PWM technology.
Considering the simple speed regulation mode of the DC motor, the wide range of adjustable speed, more air shift, soft wind, farther air supply distance, and the use of the DC motor, with better silent fan effect and energy-saving effect, this design adopts the DC motor.
In terms of motor drive, the motor drive module is selected as TB6612FNG for this design. e dual-way DC motor drive is based on TB6612FNG drive IC design and adopts a special logical control mode, and only 4 tube feet can realize dual-way motor control, saving valuable IO resources.
PWM is the abbreviation of pulse width modulation. It is the number of analog signal levels by modulating the width of a series of pulses, equivalent to the required waveform. Pulse width modulation is a very effective technique that uses the digital output of microprocessors to control analog circuits, which is widely used in many fields, from measurement and communication to power control and transformation.
Changes in the duty cycle of the PWM can regulate changes in signal, energy, etc. e duty cycle refers to the percentage of the signal at high level in the whole signal cycle. For example, the duty cycle is 50%.
PWM speed regulation is to adjust the duty ratio to simulate different voltage values, so as to control the voltage at both ends of the motor to achieve speed regulation. e K210 contains 3 timers with 4 channels available for each timer. is design enables the motor speed regulation through the following functions: Table 2: Data table of target detection and prediction box size and  human-fan distance.   W  H  X  Y  135  181  226  12  107  144  179  20  82  111  138  25  64  86  107  30  47  79  92  40  38  63  74  50  37  50  62  60  30  40  50  80  24  32  40  To make the wind volume change dynamically according to the change in the fan distance, the closer the fan distance, the smaller the fan distance, the larger the fan, and the distance between the fan and the difference, and considering the different requirements for fan gear, the gear should also be one of the input quantities of the air volume dynamic regulation algorithm. First, all possible values for the predicted human-fan distance were normalized, with the normalized values multiplied by the 60% motor duty cycle. At this point, the duty cycle obtained between 0% and 60% is the duty cycle that can be dynamically adjusted according to the human-fan distance. To combine the gear and the air volume, the remaining 40% duty cycle is divided into two gears, and 20% is superimposed on the original duty cycle to realize the fan motor speed based on the dynamic adjustment of the fan distance. To facilitate debugging, a bias item PT_x is superimposed on each output. If the air volume at this position is slightly different from that expected, it can be adjusted through the bias item: Here, y is the diagonal length of the input prediction box, y _max is the maximum value that the diagonal can take, and tap_position is the selected block. Since a target has nine possible prediction boxes, there are nine different biases; namely, each prediction box corresponds to one PT_x.

Computational Intelligence and Neuroscience
As shown in Figure 9, the face detected the wind based on K210. e fan has a good recognition effect and can track the movement of the user stably. After testing, the image recognition speed on the K210 device is 11 frames/s, enough to ensure the normal operation of the system.

Conclusions and Future Work
is study presents a lightweight algorithm study of intelligent embedded fan system based on YOLOv2 and discusses and analyzes the current situation, existing problems, and solutions of traditional smart home products. In this paper, YOLOv2 target detection algorithm is deployed on Kanzhi K210 chip. Combined with single person tracking algorithm, crowd tracking algorithm, and dynamic air volume adjustment algorithm, the intelligent fan realizes the real-time tracking of individual position changes, as well as the realtime tracking of crowd range, and accurate air supply. e air volume can be dynamically adjusted according to the distance between the user and the fan. e experimental results show that the algorithm can improve the accuracy of fan and realize the intelligence. However, there are some remaining problems in the content of this study, which need further analysis. In the current recognition process, limited by the size of the model input image, only 224224 images are identified, reducing the success rate of target detection in a complex environment. e K210 has 6 MB universal RAM and 2 MB KPU dedicated RAM, which can only load about 4 MB of models when running MaixPy code, requiring pruning optimization for too large models. Follow-up work will continue to optimize the target detection and pruning algorithms. At the same time, in the subsequent research, we will focus on the application of other AI algorithms in embedded systems, to improve the efficiency and accuracy of execution, and further expand the new ideas of lightweight AI algorithms.
is study provides a good example of the lightweight transplantation of AI algorithms into embedded systems. With the development of artificial intelligence chips, it will become easier and easier to deploy neural networks to embedded chips. Now, the mainstream AI development boards are Jetson Nano, Jetson TX2, K210, etc. ese AI development boards enable object recognition, object detection and tracking, speech recognition, and other visual development functions. Based on these features, and with the full imagination, we can develop more interesting and more powerful smart products.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.