key: cord-0898492-04l9mgmx authors: Jiang, Wei; Ma, Yuhanxiao; Chen, Ruiqi title: Gutter oil detection for food safety based on multi-feature machine learning and implementation on FPGA with approximate multipliers date: 2021-11-16 journal: PeerJ Comput Sci DOI: 10.7717/peerj-cs.774 sha: 55ec704ce0fc920fab5d586362fe490d015bece0 doc_id: 898492 cord_uid: 04l9mgmx Since consuming gutter oil does great harm to people’s health, the Food Safety Administration has always been seeking for a more effective and timely supervision. As laboratory tests consume much time, and existing field tests have excessive limitations, a more comprehensive method is in great need. This is the first time a study proposes machine learning algorithms for real-time gutter oil detection under multiple feature dimensions. Moreover, it is deployed on FPGA to be low-power and portable for actual use. Firstly, a variety of oil samples are generated by simulating the real detection environment. Next, based on previous studies, sensors are used to collect significant features that help distinguish gutter oil. Then, the acquired features are filtered and compared using a variety of classifiers. The best classification result is obtained by k-NN with an accuracy of 97.18%, and the algorithm is deployed to FPGA with no significant loss of accuracy. Power consumption is further reduced with the approximate multiplier we designed. Finally, the experimental results show that compared with all other platforms, the whole FPGA-based classification process consumes 4.77 µs and the power consumption is 65.62 mW. The dataset, source code and the 3D modeling file are all open-sourced. Gutter oil is usually obtained by mixing and refining illegally reused cooking oil, waste animal oil from slaughterhouses, and waste vegetable oil (Lu & Wu, 2014) . It is reported to bring prominent health issues like diarrhea and vomiting, or even cause long-term diseases like fatty liver, hyperlipidemia and cancer (Wong, 2020) . Now, not only commercial restaurants (Li, Cui & Liu, 2016) but also some education-related outsourcing providers, like university canteens, use gutter oil for cooking to reduce operation costs (China Daily, 2017) . According to recent news articles, this problem even affects the whole world, and becomes even more severe in the period of COVID-19 (Star, 2020; TheSmartLocal, 2020) . Due to its noteworthy adverse impacts, Food Safety Administration, for example, has always been working on effective distinguishment and follow-up supervision of gutter oil (China Daily, 2019) . However, past detection methods are mainly based on chemical analysis in the lab (Geng, Liu & Beachy, 2015) , and qualitative analysis on the spot (Liu, Liu & Lei, 2020) . Lab analysis requires field sampling and purification before detection, which is relatively costly and time-consuming, greatly delaying the enforcement process. A more practical way to achieve detection for law enforcement is field qualitative analysis with sensors. Although the detection time is shortened and the devices are more portable, the performance of it is not quite desirable since they are mostly threshold-based and with only one indicator. The problem is, given the fact that different cooking conditions will affect the physical and chemical properties of different types of oil in a very complex and unpredictable way, selecting a one-size-fits-all threshold in actual detection seems arbitrary and absolute. Moreover, illegal businesses may exploit loopholes of single indicator, using chemicals to adjust single indicator used in past detection methods (such as pH value and peroxide value) into the range of normal cooking oil to avoid legal punishment (Li, Cui & Liu, 2016) . Hence, there is an urgent need for a more comprehensive and well-rounded portable detector that could take different properties into account and make judgement based on machine learning approaches, instead of threshold-based approaches. The most common methods to classify oil varieties or to distinguish gutter oil in the laboratory are spectroscopic and chromatographic methods. Liquid chromatography is one example (Wang et al., 2017) . After the oil sample undergoes dissolution in isopropanol and extraction, the linear range of the corresponding long-chain aldehydes is detected in different fluorescence ranges to further perform classification. A similar recognition method is adopted: injecting the oil sample into quartz tube, burning optical fiber into a channel using femtosecond laser so that the oil sample can flow through, and finally observe and record its dynamic optofluidic refractive index to complete detection (Lin et al., 2018) . Raman spectroscopy (SERS), as the most representative method of chemical analysis, is widely used in the field of liquid component analysis (Gojani et al., 2019; Guo et al., 2020; Hu et al., 2019) . It is difficult to filter the capsaicin component in gutter oil, but this component will have an obvious peak value in SERS test, which can be used to quickly identify (Tian et al., 2018) of gutter oil. Detecting gutter oil is inherently chemical analysis. Traditional experimental methods are more accurate and reliable than computer-aided design (Wong, 2020) . However, its disadvantage is that the oil samples to be tested need to be brought back to the laboratory for a complete experimental process before the final result can be obtained, which will lead to poor timeliness of testing, professional requirements for testing personnel, and increased costs. Moreover, although there are discriminatory data like capsaicin (Tian et al., 2018) and conductivity (Hu et al., 2019) , these laboratory methods have high experimental requirements (Lu & Wu, 2014) and are only applicable for chemically treated (purified) gutter oil. It means that it is not practical enough to be used in field tests, where oils are adulterated. The most common way for detection with sensors is to electrize the test oil and measure relevant parameters to detect harmful components in gutter oil B A ( Baranowska et al., 2008) . In literature (Wang, 2020) , also based on capsaicin component, differential pulse voltammetry was used to analyze the linear response signal of the oil sample. If the signal is within a specific range, the sample will then be classified as gutter oil. Similarly, the test of gutter oil can also be completed by measuring the conductivity of oil samples after water bath heating (Hu Xueyao, 2013) . Since this method only detects parameters of a single dimension, the accuracy of test results will be affected by temperature, impurities of the sample to be tested and other factors. At the same time, relevant instruments using such methods usually use microprocessor level development platform to complete the corresponding data processing, such as STM32, ESP32, MSP 430, etc. (Ge et al., 2019) , which are limited by power consumption and performance. Aiming at the problems of poor real-time performance, high cost and large error in previous methods, this paper designed a portable low-power real-time detection system for gutter oil based on FPGA, as shown in Fig. 1 . In view of the discrimination error caused by a single feature in previous portable detection, we added multiple data dimensions. A machine learning algorithm is introduced to enhance the accuracy of discriminant classification in the case of multi-dimensional data. In addition, all processing operations are completed locally, and the final discriminant classification results are output directly, rather than sending pre-processed data to the high-performance processor to complete the operation. Considering the cost and limited hardware resources of the low-power platform, we further explored the k-Nearest Neighbor accelerator using approximate multiplier to realize the classification and detection of gutter oil. The above functions are realized by FPGA and are compared with other embedded platforms (such as Raspberry Pi). Our main contributions are as follows: 1. A flexible detection system for gutter oil is proposed for the first time based on multi-dimensional features and machine learning. A series of classifiers based on machine learning algorithms are used to comprehensively analyze the multi-dimensional features of gutter oil. 3. An approximate multiplier is proposed based on Intel FPGA platform to save the hardware multiplier and LUT resource consumption in the design process. 4. The classification model k-NN is deployed flexibly on FPGA platform to realize the local classification of oil as well as the detection of gutter oil. 5. The dataset, 3D modeling file for the detector, and the related source code have been made public to help spark progress in the field of food safety testing, and it can also be transferrable to the design of other multi-disciplinary embedded systems. The rest of the paper is organized as follows: 'Related work' reviews relevant literature. 'Methods' introduces our research methods in a detailed manner, including our research object, feature acquisition, feature selection and the comparisons between different machine learning classifiers. 'Hardware implementation of the system' gives a detailed description of the proposed approximate multiplier. How we implemented the classifier on FPGA and how the system works are explained in 'The design of approximate multiplier and the deployment results'. In 'Results and discussion', we analyzed and evaluated the system in the aspects of performance, resource, and power consumption. Finally, in 'Conclusions', we conclude the paper. Just as mentioned in the 'Introduction', existing gutter oil detection methods are based on single feature dimension. However, in actual gutter oil detection environments, the mixing of different kinds of oil (Ng et al., 2015) , the addition of cooking seasonings (Tokiko Nakayama, 1998) and other external factors make the process even harder. Similar problems exist in the identification of adulterants in edible oils. Instead of single-feature dimension, the researchers proposed multi-feature detection and greatly improved the results. Giacomelli, Mattea & Ceballos (2006) tested the ability of four principal components, including FA composition, tocopherol levels, CIF (Commission Internationale de l'Eclairage) parameters, and photometric color index in the analysis of edible oils. Data processing algorithm is then implemented on the four-feature original data matrix to classify different vegetable oils. Zhang et al. (2014) proposed a highly effective approach to identify oil authenticity by analyzing the proportions of various fatty acids components, such as caprylic acid, capric acid, lauric acid, and 25 other fatty acids. They further proposed the one-class partial least squares classifier (Zhang et al., 2015) for the identification of peanut oils and the high-precision detection of edible oil adulteration with adulterants even less than 4%. Thus, based on existing relevant literature, our design draws on both multi-feature detection and their subsequent evaluation process, to the detection of gutter oil. Furthermore, there is hidden correlation under multiple features, so machine learning algorithm can achieve high performance with less feature extraction requirements (Wang et al., 2020b) . This is also the reason why machine learning algorithms have been widely used to solve multi-feature problems in various fields. Liakos et al. (2018) reviewed and concluded that the farming efficiency can be improved by machine learning methods based on multi-sensor's data. And the works analyzed were categorized in crop management, livestock management, water management, and soil management. The framework is able to produce fast and precise results for simple and compound sentences. Lim et al., (2020) presented a machine learning method to uncover fatty acid patterns discriminative for ten different plant oil types and intra-variability. Moreover, they present a supervised end-to-end learning method that can be generalized to oil composition of any given mixtures. These methods got 50th percentile absolute error between 1.4-1.8% and a 90th percentile error of 4-5.4% for any 3 kinds of oil mix up. According to the application of the above machine learning algorithms, it can be deduced that the machine learning algorithm brings better results to the problems of multiple data dimension. However, the more features, the more the system needs to compute. Hence most of the tasks are completed in the cloud by general-purpose processors and GPUs with high computing power. It requires a large amount of communication time for the IoT edge terminals (Gubbi et al., 2013) , and evidently not suitable for our application scenario. In order to detect gutter oils on the spot and in real time, machine learning algorithms should be deployed to an edge device becomes the central problem to be addressed. One kind of typical IoT end-point device is the microcontroller unit (MCU). Sakr et al. (2020) investigated machine learning on mainstream microcontrollers and then tested the ability of serial STM MCUs to run machine learning algorithms. Four algorithms were tested, artificial neural network (ANN), decision tree (DT), k-Nearest Neighbors (k-NN), and support vector machine (SVM), with an accuracy above 80% and low power consumption. Ge et al. (2019) implemented a convolutional neural network on FPGA with a Cortex-M3 IP core for image processing. In order to reduce latency, accelerators are designed to be parallel, which further improves its comprehensive performance. Based on current social context and past research experiences, we first propose a multi-feature machine learning algorithm in the field of gutter oil identification. And then we deployed it to an edge device for on-site detection. Hope it sets the foundation and provides valuable references for future works. This section mainly explains our research object, feature acquisition, feature selection and the chosen machine learning algorithm. The quality of data greatly affects the accuracy results of machine learning algorithms (Xie et al., 2018) , so we carefully chose our research object and conducted the following data acquisition (will be explained in detail in 'Feature acquisition and preliminary analysis'). The research object of this paper is a variety of oils, including gutter oil, chili oil, soybean oil, rapeseed oil, peanut oil and olive oil. With the purpose of simulating real detection environment and different cooking methods, we mixed different types of oils and added different reasoning, adding to the richness of our research object. These oil samples are used for subsequent feature acquisition to form the dataset used in the machine learning algorithm. The two gutter oil samples are legally acquired from the Food Safety Administration in Fujian Province and Fuzhou Market Supervisory Authority, and they are reported to be the most representative and generalizable ones. Apart from mixing different oils, we also added seasoning that are commonly used in Chinese food, with the quantity they are normally used. They are 5 g sugar, 3 g salt, 2 g monosodium glutamate, 2 g chicken essence, 5 g soy sauce and 10 g vinegar. (Sethi, Chauhan & Anurag, 2017; Wang et al., 2020a; China Daily, 2012; China Daily, 2014; Our study involved in total 3,600 different oils and was made up of 4 groups. There are 15 oils in Group 1, 210 oils in Group 2, 225 oils in Group 3, and 3,150 oils in Group 4. We respectively refer to them as pure oil, pure oil with seasoning, mixed oil, and mixed oil with seasoning, as illustrated in Fig. 2 . In Group 1, as shown in Table 1 , there are in total 15 pure oils, 2 gutter oil samples and 13 oil samples chosen from 5 types of cooking oils (chili oil, soybean oil, rapeseed oil, peanut oil and olive oil). 4 common brands of chili oil are selected as our sample because this type of oil contains a large amount of capsaicin, which is also an important indicator of gutter oil detection (Tian et al., 2018) . Hence taking into account more chili oil will effectively improve the generalization ability of the whole system. The other oils (soybean oil, rapeseed oil, peanut oil, olive oil) are the most common edible oils used in daily cooking (Shen et al., 2018) . The 15 kinds of pure oils are labeled into 6 kinds accordingly. Group 2 is derived from Group 1 pure oils and there are in total 225 samples as listed in Table 2 . We take 25 g of each Group 1 pure oils and respectively add seasonings to them. Based on Chinese cooking habits (Pu et al., 2019) , four seasonings are selected from the total of six: 5 g sugar, 3 g salt, 2 g monosodium glutamate, 2 g chicken essence, 5 g soy sauce and 10 g vinegar. Therefore, there are 15 combinations of seasonings to be added to For each oil in Group 1 (15 oils), there will be 15 different combinations of seasonings, so a total of 225 oils (15 × 15) are obtained. And they are labeled in six types just as in Group 1 oils. The reason why we mix seasoning with pure oils is that in field tests, the testing oils are normally used cooking oils collected from food scraps. In this way, various cooking ingredients should be present in testing samples. Group 3 contains 210 oils, they are obtained by mixing two pure oils (15 × 14), as shown in Table 3 . The reason why these mixed oils are taken into the research object is that law enforcement officials reported that some businesses mix edible oils and gutter oils in actual tests to get away with a single-feature detection (Wong, 2020) . We set the mixing ratio at 80%:20%, because according to past experiences of authorities, gutter oil is usually mixed with edible oils with more than 30 percent to reduce cost and to avoid detection. In our system, we decided to raise the detection to a higher standard, detecting adulterated oils even when gutter oil is less than 20%. The oil will be labeled as gutter oil as long as gutter oil is mixed into the sample. The other samples are labeled according to the 80% part of it (for example, a mixture of 80% chili oil and 20% soybean oil is labeled as chili oil). Group 4 oils are mixed oils with seasoning, and it consists of 3,150 samples as shown in Table 4 . It is obtained by adding seasoning just as introduced in Group 2 oils. The same 15 combinations of seasonings are added by the same amount to each 25 g Group 3 mixed oil. Therefore, there are in total 210 × 15 = 3150 different oils. And this group of oils is the The features should be significant enough to reflect the differences between various types of oil. As our ultimate goal is to design a low power consumption, low-cost and portable gutter oil system, the process of feature acquisition should be simple and convenient. For this reason, we consulted a large number of literatures, and based on the portable sensors available in the market, we chose PH0-14 (Hussin, Othman & Tahar, 2019) , DJS-1C (Cai et al., 2006) , DOM-24 (https://www.atago.net/product/?l=en&f=products-dom-top.php), P3-101 (https://i-item.jd.com/10021382704123.html) to collect pH value, peroxide value, electrical conductivity value and refractive index. Considering that data collection in these previous studies was completed under pure oil samples (Turrini, Zunin & Boggia, 2021) , we test the usability of the above sensors and conduct preliminary feature analysis with the above four types of feature data on the Group1 research object (Pure Oil). Gutter oil is usually found in a high percentage of animal fats and bleach, which usually lowers the pH value (Kuuluvainen et al., 2015) . PH value sensors (pH 0-14) were used to detect the pH value of 15 pure oil samples selected from 6 different oil types at 25. The pH values of the two gutter oil samples are 3.93 and 8.85, not in the range of normal cooking oils (6.58-7.17). The former one, 3.93, is consistent with the results of previous studies that gutter oil normal has lower pH value. However, the latter 8.85, is obtained by adding excessive alkaline additives. This is probably because illegal traders wanted to lift the pH value but tried too hard (Lu & Wu, 2014) . In addition, temperature has an impact on the pH value of cooking oil (Yang, Qin & Li, 2002) , so we need to take it into account. In most previous studies, the upper limit temperature of the test was set at 55 • C 65 • C (Ariaeenejad et al., 2018; Fu et al., 2010) . In this paper, instead of acquiring pH value at 25 • C, we took the average and set the upper measuring temperature after heating at 60 • C. According to the data in Table 5 , it can be found that the pH value of cooking oil does not change significantly with the increase in temperature, while the change of gutter oil is relatively large as the impurities in it are more sensitive to changes in temperature. Fifteen pure oil samples from Group 1 were heated in a water bath. N-hexane and Deionized water were added to the oil samples at different bath temperatures, and the mixture was continuously oscillated to ensure mixing (Ortega et al., 2019) . Then the aqueous phase can be separated and separated through communicators. Conductivity sensor(DJS-1C) was used to measure the conductivity value of its aqueous phase. The average value of oil samples of the same kind was taken, as shown in Fig. 3 . It can be found from the data in Fig. 3 that the increase of temperature can effectively reflect the difference between oils through the conductivity value. Therefore, electrical conductivity can be regarded as one of the distinguishing features of gutter oil. Compared with other oil samples, the conductivity value and change rate of gutter oil are generally higher, and the difference increases with the rise of temperature. But after reaching a certain temperature, the change slows down, because the impurities or ions in the oil are limited. On the other hand, according to the latest research (Wang et al., 2019; Okafor & Nwoguh, 2019) , there is a hidden relationship between the variation of conductivity at different temperatures and the quality of oil. Therefore, the difference of conductivity at different temperatures can also be used as a distinguishing feature. Considering that the water bath heating will consume a lot of time and the change will slow down after the temperature rises, we set the upper limit of the water bath temperature at 60 • C just the same as the temperature we set for the pH data collection. Finally, conductivity value at 25 • C conductivity value at 60 • C and the conductivity value difference between 25 • C and 60 • C are selected to be candidate features. A large amount of peroxide will be produced in cooking oil after heating, so the peroxide value can be used as a distinguishing feature of oil detection (Oishi et al., 1992; ISO 27107:2008 ISO 27107: , 2008 . DOM-24, a special sensor for peroxide value measurement, was used in the experiment. The peroxide value of different types of oils at 25 • C and 60 • C are shown in Fig. 4 . It can be seen from the figure that the peroxide value of gutter oil is relatively high, even at 25. The reason is that gutter oil is used repeatedly, the content of decomposable oxides in gutter oil is less than that in cooking oil under same temperature. And after water bath, the peroxide value of all oil samples increases. While the peroxide value of normal cooking oil shows great differences before and after the heating, gutter oil has no great value changes. Due to this experimental results and the previous conductivity value difference, we proposed to introduce the peroxide value difference between 25 • C and 60 • C. Finally, Peroxide Value at 25 • C, the peroxide value at 60 • C and the difference between the peroxide value at 25 • C and 60 • C are selected to be the candidate features. Refractive Index is a simplified parameter in the spectrum method and can also be applied to measure the quality of cooking oil (Balestrini et al., 2018) . Using P3-101 type refractive index sensor, the refractive index value of oil samples to be tested can be obtained directly. The value of refractive index shows no significant changes with the increase in temperature (Winkler, Proietti & Knoche, 2018) , so only the refractive index at 25 • C is considered to be one of the candidate features. Based on the data obtained by the above mentioned sensors and the preliminary analysis, we listed nine specific candidate features out of four main feature types as shown in Table 6 . The data of these nine features obtained as well as their corresponding labels from the dataset of our experiment. Through the above operation and preliminary analysis, we finally selected the pH value at 25 • C, the peroxide value at 25 • C, conductivity value at 25 • C, the conductivity value at 60 • C, the difference between 60 • C and 25 • C, the peroxide value between 60 • C and 25 • C, and the refractive index at 25 • C as the candidate features as shown in Table 6 . In particular, the peroxide value difference between 25 • C and 60 • C is a feature inspired by conductivity value difference. The nine-feature data is visualized through a Parallel Coordinates Plot (Inselberg, 1985) as shown in Fig. 5 . A parallel Coordinates plot can be used to represent the independent effect of each feature on target prediction. The specific analysis is based on two principles: 1. Whether the broken lines of the same color are concentrated. If the broken lines of the same color are concentrated in a certain feature and there is a certain space between different colors, it indicates that this feature is of great help to predict the label category. 2. If lines are disordered and colors are mixed on a feature dimension, it is more likely that this attribute is of no value for tag category determination. Since our ultimate goal is to make a low power and low-cost gutter oil detection system, the algorithm should not be too complicated. Therefore, five groups of popular and simple supervised classifiers, including ANN, DT, k-NN, RF and SVM are selected to further evaluate each feature of 3600 oil samples. On the PC side, based on Python, each feature is respectively trained by five classifiers with the scikitlearn machine learning library. Algorithm-specific Configuration Parameters are set by default. For the dataset, we divided the training set and testing set by the ratio of 6:4. And k-fold cross validation was performed with the default cv value (3). Figure 6 shows the accuracy results of each feature under different classifiers. The red line indicates the level of average accuracy of the nine candidate features. Although machine learning algorithm cannot achieve satisfactory results, the classification accuracy of all features is less than 70% . Therefore, the multi-dimensional feature is put forward as the input for the classification and discrimination of gutter oil. Considering that the ultimate goal is a low-power and low-cost gutter oil detection system, limiting the number of input features can reduce the system's computational burden, thus achieving the savings of operation time and power consumption. In order to seek a balance between accuracy and input dimensions, we gradually increased the number of input features in the classifier and tested the performance of the eight sets of features. The features are added to the classifier based on their accuracy under single feature dimension, and we recorded each accuracy result obtained in the operation. The results are shown in Table 7 from row 1 to row 8. According to the data in the table, it can be found that when the feature dimension increases, the classification accuracy increases accordingly. And it's noteworthy that when there are four input features (row 3), dvconduc+60ox+25ox+60conduc, adding new features no longer has an edge in increasing accuracy. In addition, considering that the heating process takes time in real detection environment, we additionally conducted a multi-feature input classification training for all the features under 25 • C (25pH, 25conduc, 25ox, reindex), to see if the model can achieve a satisfactory result even without heating. However, as shown in Table 7 row 9, the four features obtained at room temperature is not good enough. Its accuracy is 5.24% lower than that of another four-feature input dvconduc+60ox+25ox+60conduc (row 3). We further used T-Distributed Stochastic Neighbor Embedding (T-SNE) to measure the clustering result of different sets of features as in Fig. 7 . T-SNE is a nonlinear technology that preserves the neighborhood relationship between data (Maaten, 2014), it reduces the dimension of the multi-dimensional features and can better visualize the results. It can be proven that when the feature dimension is 4 or more, the clustering result is already considerable. Further increasing the feature dimension will not bring significantly better results. Therefore, we finally choose to adopt dvconduc+60ox+25ox+60conduc, and we believe that they are more than sufficient to ensure the correctness of the classification and will not put too much pressure on the resource and power consumption. Our goal is to design a low-power and portable device, therefore we need to make the most use of power and area by adopting the most effective features. Moreover, to save data acquisition and processing time, we finally chose four features out of the nine specific features as the input of our classifier, including conductivity value difference between 25 • C and 60 • C, peroxide value at 25 • C, peroxide value at 60 • C, and peroxide value difference between 25 • C and 60 • C. This paper proposes a multi-feature input machine algorithm to classify gutter oil based on four features: conductivity difference between 60 • C and 25 • C, peroxide value at 25 • C, peroxide value at 60 • C, peroxide value difference between 25 • C and 60 • C. This section explores the performance between classifier ANN, DT, k-NN, RF, and SVM to determine the final deployed classifier. Accuracy is usually an important index to evaluate the classification performance, but there will be some deviations when dealing with unbalanced data sets (Le, 2019) . In this paper, other evaluation indexes are also introduced to jointly serve as the evaluation of classifiers. Table 8 shows relevant parameters used to evaluate measures based on confusion matrix statistics. For the calculation of three basic evaluation parameters, including Precision, Recall and F1-score (Le et al., 2021) , we introduced the weight parameter w according to the proportion of samples to reduce the operation error of the unbalanced dataset. The corresponding operation is as shown in Eqs. (2)-(4). Kappa is an important metric, especially in terms of unbalanced data sets (Ul Haq Tahir et al., 2019) . It measures the result of the classifier from the numerical value. Theoretically, its value range is [−1,1], and the paper rescale to [0,1]. The greater the Kappa value, the better the classification performance of the model. We assume that all the predicted numbers are N , then Kappa Definition is given in Eq. (5): where Hamming Loss can also be used to evaluate the performance of multi-classification models, and its value represents the proportion of misclassification tags (Park & Read, 2019) . This is a loss function, so the optimal value is zero. The number of predicted samples is denoting N , and the number of labels is denoting M (6 in this paper), then hamming-loss definition is given in Eq. (8) Hammingloss y andŷ are respectively actual class label and predicted class label. In the case of 3,600 oil samples, the training set and testing set are divided by a ratio of 6:4, and 5 different classifiers are tested based on the above evaluation indicators. The numerical results of relevant indicators on the final statistical test set are shown in Table 9 . Although RF has the highest accuracy rate, k-NN has a better performance in unbalanced data when combined with other assessment indicators. Therefore, k-NN is used as the classification model for final deployment. In addition, in order to better evaluate the performance of the following classifiers, the Receiver Operating Characteristics (ROC) and Area Under Curve (AUC) are used as another two indexes, as shown in Fig. 8 (Le et al., 2020) . As k-NN, again, demonstrated its strength, it is selected to be the classifier model for the final deployment. After the selection of features and the comparison of models, specific functional design can be carried out based on relevant results. The whole system completes the data acquisition and classification operation based on the device shown in Fig. 1 . The specific process is shown in Fig. 9 . Before the operation of the system, the high temperature resistant container 1 shall be filled with pure water to provide a water bath environment, and the oil sample to be tested shall be added to the reaction tube 4. After that, the system shall be started. Firstly, the water bath is heated by electric heating bar 5, while the temperature sensor 6 monitors the water bath temperature in real time. When the water bath temperature reaches 25 • C, relevant sensor 7 (the specific model is described in 'Feature acquisition and preliminary analysis') is used to complete the collection and cache of the peroxide value, and electrical conductivity value under 25 • C into THE RAM of FPGA. After that, the water bath was heated to 60 • C. At this point, the peroxide value under 60 • C was collected through sensor 7, and the difference between the peroxide values before and after was calculated into THE RAM of FPGA. At the same temperature, after the peroxide value was collected and calculated, N-hexane and deionized water were added to reaction tube 4. As described in 'Feature acquisition and preliminary analysis', the container needs to be oscillated to achieve full mixing. Here, the whole container is oscillated by means of the stepper motor 9 and the corresponding transmission mechanical structure 10, 11. After the oscillation, open the pressure valve 2 and complete the acquisition of water phase through communicator 3. The 60 • C conductivity was measured using the conductivity sensor, and the difference between the front and rear conductivity was calculated. The peroxide value at 25 • C, peroxide value difference, the conductivity value at 60 • C, and the conductivity difference are fed into the k-NN module for oil classification. The above process of hardware control, data acquisition and data calculation are all completed in FPGA. Hardware control can be realized by outputting corresponding signals through IO pins, while sensor data acquisition is all realized by ADC. The implementation of the core machine learning algorithm is described in detail here. In order to realize the low power k-NN classifier, we made a balance between parallel extensibility and pipeline to reduce the complex operation process as much as possible. Data is allocated and scheduled through Finite State Machine (FSM) to maximize the reuse of computing modules (Attaran et al., 2018) . As shown in Fig. 10 , the FPGA implementation is explained in detail as follows. Euclidean distance is selected as the distance function: There are 600 training samples and labels in the ROM block. As shown in Fig. 10B , it scheduled up to four parallel multipliers. Hence, there were two clock cycles to calculate the Euclidian distance (d i ) that from input features and training samples. Next, the d i was inputted into the sort network and label finder module (SNLF) that was showed in Fig. 10C . The mux, comparator, and cache registers constitute the SNLF. The mux was used to control d i transmit in different clock cycles. The comparator was used to compare with new d i and storing dis in cache registers. There were 14 cache registers (Ox and Ex) used for storing d i . Specifically, Ox registers were used to store the 7 smallest dis in 'odd' clock cycles. Ex registers were used to store the 7 smallest dis in 'even' clock cycles. The ping-pong cache was used to rank the d i in different clock cycles for the SNLF, as shown in Fig. 9A . From those dis, 7 could be identified to be the smallest. Initially we set the register's value to the maximum. The d i value compared with each Ox's value when clock cycle was jth (j = 3,5,7,...) period. It would be dropped, if d i value was bigger than ever Ox's values in next period. Otherwise, d i value was inserted into Ox and the biggest value in 7 Ox's would be dropped. Similarly, Ex's values were updated in (j + 1)th (j + 1 = 4,6,8...) period. The cycles were repeated until all of 600 training samples had been calculated with input features. Finally, comparing all the 14 registers and getting the smallest 7 value from them. The result was voted from the smallest 7 value of registers. Among all kinds of operations involved in the deployment of k-NN classifier to FPGA, multiplication operation is the most core. Most FPGAs achieve multiplication by calling IP core or DSP module (Perri et al., 2020) . However, there are no related modules on some low-power and low-cost FPGA (Ullah, Nguyen & Kumar, 2020) . Therefore, combined with the low power consumption and low-cost design requirements in this paper, an approximate multiplier is proposed according to the device features of Intel FPGA. The above classifier can be provided to complete the corresponding multiplication operation, and at the same time, the resource consumption caused by EDA's direct multiplication Module Instance can be reduced. This section describes the design and deployment results of this approximate multiplier. In this paper, the approximate multiplier is realized by recoding some results in the operation process. During the multiplication operation, the multiplier can be split, and the corresponding partial results can be divided into partial product and advance digit, and then the whole multiplication operation process can be completed by adding (Ullah et al., 2018) . Because of the split of multiplier in the process of operation, some results can be encoded to enumerate the corresponding results, which is very suitable for LUT (look-up table) structure. The specific introduction of this approximate multiplier design process is chosen 4 × 4 approximate multiplier as an example. The 4×4 approximate multiplier consists of 4-input LUT, 5-input LUT, and 6-input LUT. The 4-input LUT is a preliminary resource of Intel FPGA. The 5-input LUT is composed of two 4-input LUTs and the 6-input LUT consists of four 4-input LUTs. As shown in Fig. 11A , the p 0 was obtained by n 1 n 0 × m 1 m 0 , and the p 1 was obtained by n 3 n 2 × m 3 m 2 . The p 1 from shifting 2 bits and p 0 were added to produce part of productions (PPs). PPs were summed up to yield the result. Specifically, p 0i (i = 0,...,5) from PPs of p 0 , p 1j (j = 0,...,5) from PPs of p 1 , and pp k (k = 0,...,7) from PPs of 4 × 4 approximate multiplier. All PPs were performed by LUT with enumeration of all possible permutations (initial value), shown in Table 10 . The pp 0 and pp 1 were immediately given by p 00 and pp 1 . The pp 2 from initial value without carry. The remaining PPs were performed by 4 bits carry-lookahead adder as shown in Fig. 11B . The r i and g i (i = 0,...,2) from initial value. An 8 × 8 approximate multiplier was obtained by four 4 × 4 approximate multipliers as shown in Fig. 12 . The PPs of 4 bits (0 to 3) from the first 4×4 approximate multiplier (P0) immediately, and the PPs of 4 bits (12 to 15) from the fourth 4 × 4 approximate multiplier (P3) immediately. The remaining PPs were performed by summing all 4 × 4 approximate Table 10 Initial value and configuration for 4 × 4 approximate multiplier based on LUT. Lut4 0 χ χ 1 1 m 0 n 0 8000 P 00 Lut4 1 χ χ m 1 m 0 n 1 n 0 6aco P 01 Lut5 0 χ m 1 m 0 n 2 n 1 n 0 b4ccf000 P 02 Lut6 0 m 2 m 1 n 3 n 2 n 1 n 0 c738f0f0ff000000 P 03 Lut6 1 m 2 m 1 n 3 n 2 n 1 n 0 07c0ff0000000000 P 04 Lut6 2 m 2 m 1 n 3 n 2 n 1 n 0 f800000000000000 P 05 Lut4 2 χ χ m 3 m 2 n 1 n 0 6aco P 11 Lut5 1 χ m 3 m 2 n 2 n 1 n 0 b4ccf000 P 12 Lut6 3 m 3 m 2 n 3 n 2 n 1 n 0 c738f0f0ff000000 P 13 Lut6 4 m 3 m 2 n 3 n 2 n 1 n 0 07c0ff0000000000 P 14 Lut6 5 m 3 m 2 n 3 n 2 n 1 n 0 f800000000000000 P 15 Lut5 2 χ P 11 P 03 m 2 n 0 P 02 ffeaea00 g 0 Lut5 3 χ P 11 P 03 m 2 n 0 P 02 007f7f80 r 0 Lut4 3 χ χ 1 1 P 12 P 04 8000 g 1 Lut4 4 χ χ 1 1 P 12 P 04 6000 r 1 Lut4 5 χ χ 1 1 P 13 P 05 8000 g 2 Lut4 6 χ χ 1 1 P 13 P 05 6000 r 2 Lut4 7 χ χ 1 P 02 m 2 n 0 7800 pp 2 multipliers without carry. The addition operation implemented on LUT with initial value. Finally, we implement the k-NN with 8 × 8 approximate multiplier. Using Verilog hardware description language and primitive, an 8×8 approximate multiplier was deployed to the Intel FPGA Cyclone 10LP 10CL006ZU256I8G devices which is targeted on Intel Evaluation Kit. The results of the deployment are compared with the relevant -13 studies, as shown in Table 11 . The approximate multiplier proposed in this paper is a design based on the balance of area, performance and power consumption. Therefore, although it is not the optimal design in the single dimension of area, performance and power consumption, the proposed approximate multiplier has the optimal performance in the comprehensive index PDP. Figure 13 shows the Proportion of Error effects that is a well-adopted quality metric (Rehman et al., 2016) proposed. It can be found that the design of approximate multiplier proposed in this paper controls the errors within the finite size range and frequency. The Intel Evaluation Kit with Intel Cyclone 10LP FPGA as the core serves as a portable platform for low-power gutter oil detection. A driver for external sensors and a k-NN machine learning kernel for feature classification were developed using Verilog. The whole design is based on the design idea of highly parallel and highly pipelined, and an approximate multiplier is designed for devices to further reduce power consumption and resource consumption. Table 12 summarizes the results of the proposed gutter oil detection system conducted by k-NN using an 8×8 approximate multiplier on Cyclone 10LP FPGA. And for reference and comparison, a column of LE-based IP performance results is added. While the accuracy of using the original LE-based IP is 97.29%, the classification accuracy after deploying approximate multiplier is 97.18%. Moreover, the entire k-NN design saves approximately 18.7% LUT and reduces 28.90% power consumption. It proves that the design and introduction of approximate multiplier further strengthen the system to be low-cost and low-power. In order to further evaluate the performance of the proposed portable and low-power waste oil detection system, several common embedded development platforms (Rockchip RK3399 Pro, Jetson Nano, Raspberry Pi 3B+, STM32L496) were selected for comparison. Rockchip RK3399 Pro uses Cortex-A72 as its processor core and 2.0 GHz as its main frequency. It is packed with a special NPU module for machine learning. Jetson Nano is cortex-A57 as the core, the main frequency is 1.43 ghz, with a 128-core NVIDIA Maxwell based GPU. The raspberry comes with a 1.2 ghz Cortex-A53 core. STM32L496 is the most common terminal of the Internet of Things, with Cortex-M4 as the core and 80MHz working frequency. On Raspberry Pi and STM32L496, we used serial C language to perform k-NN-based gutter oil detection (Hussin, Othman & Tahar, 2019) . In order to perform parallel processing on the GPU, we used PyCuda (Calabrese et al., 2020) on the Jetson Nano platform to achieve parallel processing of k-NN (100 threads processing 600 training data). On the Rockchip platform, the RK-NN-Toolkit tool is used to realize k-NN parallel processing (Lan et al., 2020) . Table 13 shows the comparison results for all platforms. In terms of computing performance, Jetson Nano is the best among all platforms due to the GPU's high frequency multithreaded parallel processing capability. But in a portable scenario, power and cost become more important: Jetson Nano sells for $129, while Cyclone 10LP FPGA costs just $49. The power latency production (PLP) comparison between all platforms is provided in Fig. 14 , which can effectively evaluate the comprehensive performance of the platform (A Kandhalu, 2010) . It can be found that THE PLP of FPGA implementation is greatly reduced compared with other platforms. To sum up, FPGA solution, with the best PLP, provides programmability and low development cost, is the best choice for portable and low-power gutter oil detection. In this paper, a low-power portable detection system for gutter oil is proposed, which uses multi-feature k-NN algorithm with an approximate multiplier deployment on FPGA. It can complete oil classification much more accurately than traditional single dimension detectors. In actual environment for oil detection, laboratory detection methods require the oils to be purified beforehand, which makes the supervision work significantly lagged behind and brings unnecessary economic costs. Moreover, the multi-feature k-NN algorithm proposed in this paper can effectively extract the hidden associations between different features and results, and the final accuracy reaches 97.18%. Finally, the entire system is deployed on FPGA using approximate multiplier, and it brings the best overall performance compared to other popular embedded platform. Although the proposed approach and deployment have excellent performance, there is still room for further improvement. While the oil samples we used in this paper were mixed and doped in order to simulate the real detection scene, increasing the samples of gutter oil can help us further train the classifier. Apart from increasing test samples, doping gutter oil with ratios lower than 20% would improve our exploration into the effectiveness of different features and may boost the detection results. However, due to many restrictions beyond our control during the time when the study was conducted, we would add relevant experiments and results in future works. Gutter oil used in the catering industry has significant adverse impacts on people's health and even the society as a whole. Food Safety Administration achieves supervision by sampling and testing oils used by local businesses. However, as gutter oil can be blended with other complex chemicals, existing threshold-based single feature detection could not satisfy the demanding actual detection environment where various interferences may be brought in. In this paper, a portable and low-power gutter oil detection system is designed using machine learning algorithms for the first time to our knowledge. And with our original method that has multi features taken into account, it is much more comprehensive and accurate than past portable detectors. Based on relevant features including peroxide value and electrical conductivity that have been experimentally proven to be effective, the machine learning classifiers are compared and k-NN was selected for this task. Test results show that all the relevant evaluation parameters perform well under complex detection environment, and the accuracy rate of oil sample classification is up to 97.18%, much higher than previous studies. Finally, relevant designs are deployed on FPGA, and the core k-NN design achieves a balance between parallel scalability and pipeline to meet the demand of low power consumption. An approximate multiplier is designed for the core multiplication operation, which further reduces the power and resource consumption of the system. While the accuracy of classification model is reduced by only 0.5%, the introduction of approximate multiplier saves 18.7% of resource consumption and 28.9% power consumption. This paper also compares and discusses various embedded IoT terminals to evaluate our design in the aspects of power consumption and performance that offset each other. Experimental results show that the performance of FPGA proposed in this paper is close to two times of Cortex-A53, and PLP improves 2.5 times compared with embedded GPU platform. Under this condition, the circuit resource consumption is only 1,049LUT, and precious hardware multiplication resources are not used because of the introduction of approximate multiplier, so it can fully meet the design requirements of low-power portable gutter oil detection. U-connect: a low-latency energy-efficient asynchronous neighbor discovery protocol A computational method for prediction of xylanase enzymes activity in strains of Bacillus subtilis based on pseudo amino acid composition features Embedded low-power processor for personalized stress detection Improvement of safflower oil quality for biodiesel production by integrated application of PGPR under reduced amount of NP fertilizers Determination of selected drugs in human urine by differential pulse voltammetry technique Low temperature conditioning reduces postharvest chilling injury in loquat fruit Solar-powered deep learning-based recognition system of daily used objects and human faces for assistance of the visually impaired Sauteed shredded pork with lettuce & black fungus sweet and sour style 8 healthy Spring Festival recipes in flu season Food safety tests must be done by certified bodies Chinese police crack down on food-related crimes during holidays Nanxiang steamed stuffed buns Production of low-trans fatty acids edible oil by electrochemical hydrogenation in a diaphragm reactor under controlled conditions Compact convolutional neural network accelerator for New food safety law of China and the special issue on food safety in China Analysis and classification of liquid samples using spatial heterodyne raman spectroscopy Area-efficient fast truncated 8 ×8 soft multipliers for field programmable gate array accelerators Internet of Things (IoT): a vision, architectural elements, and future directions Modified PCA and PLS: towards a better classification in Raman spectroscopybased biological applications Safety analysis of edible oil products via Raman spectroscopy Improvement on the rapid detection method of waste oil based on electrical conductivity Development of portable water quality monitoring system using apps Animal and vegetable fats and oils: determination of peroxide value: potentiometric end-point determination Properties of adsorbents used for bleaching of vegetable oils and animal fats FeatherCNN: fast inference computation with TensorGEMM on ARM architectures XGBoost improves classification of MGMT promoter methylation status in IDH1 wildtype glioblastoma Radiomicsbased machine learning model for efficiently classifying transcriptome subtypes in glioblastoma patients from MRI SNARE-CNN: a 2D convolutional neural network architecture to identify SNARE proteins from high-throughput sequencing data Gutter oil: an overview of Chinese food safety issues and policies Machine learning in agriculture: a review Analysis and characterization of edible oils by chemometric methods Pattern recognition based on machine learning identifies oil adulteration and edible oil mixtures Optofluidic gutter oil discrimination based on a hybrid-waveguide coupler in fibre Research progress in identification technology of gutter oil China food safety hits the gutter Accelerating t-SNE using tree-based algorithms Rapid screening of mixed edible oils and gutter oils by matrix-assisted laser desorption/ionization mass spectrometry Rapid and simple coulometric measurements of peroxide value in edible oils and fats A study of viscosity and thermal conductivity of vegetable oils as base cutting fluids for minimum quantity lubrication machining of difficult-to-cut metals Self-powered smart patch for sweat conductivity monitoring A blended metric for multi-label optimisation and evaluation Parallel architecture of powerof-two multipliers for FPGAs Study on the use of cooking oil in chinese dishes Machine learning on mainstream microcontrollers Architectural-space exploration of approximate multipliers A systematic review of fuzzing based on machine learning techniques Rapid determination of long-chain aliphatic aldehyde in gutter oil by fluorescent derivatization-high performance liquid chromatography Predicting osmotic potential from measurements of refractive index in cherries, grapes and plums Managing food waste, improving food safety? The case of gutter oil in China DeepNitro: prediction of protein nitration and nitrosylation sites by deep learning A rapid method for edible oil acid value analysis One-class classification based authentication of peanut oils by fatty acid profiles Classification and adulteration detection of vegetable oils based on fatty acid profiles The authors would also like to acknowledge the technical support from VeriMake Innovation Lab. This research was funded by the Corporate Practice Training Program for young teachers in Jiangsu Polytechnic College (No.z0021). The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript. The following grant information was disclosed by the authors: The Corporate Practice Training Program for young teachers in Jiangsu Polytechnic College: No.z0021. The authors declare there are no competing interests. Yuhanxiao Ma and Ruiqi Chen are two visiting researchers for VeriMake Innovation Lab of Nanjing Renmian Integrated Circuit Co., Ltd. • Wei Jiang and Ruiqi Chen conceived and designed the experiments, performed the experiments, analyzed the data, performed the computation work, prepared figures and/or tables, authored or reviewed drafts of the paper, and approved the final draft.• Yuhanxiao Ma analyzed the data, prepared figures and/or tables, authored or reviewed drafts of the paper, and approved the final draft. The following information was supplied regarding data availability: Data and code are available at GitHub: https://github.com/verimake-team/Gutteroildetector.