程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python pig face recognition_ A pig face recognition method and process

編輯:Python

Hello everyone , I meet you again , I'm your friend, Quan Jun .

The invention relates to the technical field of artificial intelligence , In particular, the invention relates to an automatic recognition method for a pig face .

Background technology :

The current pig farm is in the process of batch pig raising , Farmers need to know the diet of each pig 、 A healthy state 、 Growth status and emotional information , Therefore, identifying the identity information of each pig provides convenience for farmers to master the basic situation of the farm , At present, there is no accurate and effective identification method for pig identity management in large pig farms , This led to confusion and mistakes in the process of pig management , therefore , The lack of pig face recognition technology is not conducive to the promotion of large-scale accurate pig breeding .

Technical implementation elements :

The object of the invention is , For the above problems , A pig face recognition method is provided , Pig face recognition through artificial intelligence technology , Identify the pig , Establish a pig image recognition database , The invention solves the problem that the prior art lacks the pig face recognition technology .

In order to achieve the above purpose , The technical scheme adopted by the invention is :

A pig face recognition method , It includes the following steps :S1. A plurality of pig pens with pig pen entrances are arranged side by side , The interior of each pigsty is respectively provided with a camera facing the entrance of the pigsty ;S2. The camera simultaneously takes pictures of the pigs entering the entrance of the pigsty , A plurality of the cameras synchronously collect video source data of the pig ;S3. The video source data passes through FTP Upload to the server , Processing the video source data into a pig face picture on the server side ;S4. Filter and mark the pig face picture , The valid pig face picture and the coordinate information marking the pig face picture are retained , The filtered pig face image and the corresponding coordinate information are used as the image data source ;

S5. A model for recognizing a pig face is trained according to the picture data source , It includes the following steps :

S51. Converting the picture data source into a data source conforming to Tensorflow System format ;

S52. The picture source data is divided into a training set and a test set in proportion ;

S53. Pass the training set through Tensorflow The training script of the system trains the model that can recognize the pig face ;

S54. The model is verified by the test set ;

S55. adopt Tensorflow The system exports the script to generate the trained model to recognize the pig face ;

S6. According to the trained pig face recognition model , Automatically process the pig face picture , It includes the following steps :

S61. For steps S3 The obtained pig face picture is input into the trained pig face recognition model , adopt Tensorflow The system judges whether the input pig face image contains a valid pig face image and returns the judgment result ;

S62. Determining whether to save the pig face picture as a valid pig face picture according to the returned judgment result .

By using the camera to collect the video source data of pigs , Use the program to convert the video source data into picture source data , Re pass Tensorflow Systematically train the model of pig face recognition , Through this model, the automatic recognition of pig face is realized , The identifiable quantity is large , High recognition accuracy .

In the above scheme , To optimize , Further , step S3 The processing of the video source data into a pig face picture is realized by the following steps : According to the video source data, a main directory of each pig and a sub directory included in the main directory are established , And reading frames of the video source data , Convert the frame into a pig face picture , Storing the pig face picture in the subdirectory .

Further , step S4,S61 and S62 The effective pig face pictures in include clear front face pictures and side face pictures .

Further , The steps are S53 The ratio of the training set to the test set in is 4:1.

Further , step S1 in , Each pigsty is provided with left and right symmetrical cameras .

Due to the adoption of the above technical scheme , The invention has the following beneficial effects :

1、 Shoot a pig with multiple cameras at the same time , Collect data synchronously , Get a lot of pig video source data , Use the program to process the video source data into pig face pictures and mark the coordinate information of each pig face picture , Re pass Tensorflow Systematically train the model of pig face recognition , The pig face is automatically recognized by this model , It can realize automatic recognition of pig face , The recognition method of pig face is established , Can identify the identity information of pig face , It provides convenience for farmers to master the information of each pig ; The number of pigs that can be identified by this model is large , High recognition accuracy , Pass the verification , after 20 ten thousand step After training , The verification accuracy of the test set reaches 99% above .

2、 Set the pigsty side by side , The entrance of the pigsty is on the same horizontal line , When pigs enter the pigsty , Multiple cameras shoot the video of the pig at the same time , To get a lot of videos about the pig , The program automatically processes a large number of pig videos to generate a large number of pig face pictures with an accuracy of 95% above , It provides a solid data base for the training of pig face recognition model , Reduce data error , Improve recognition accuracy .

3、 Through the pig face picture and marked coordinate information , Refine the identification area , Improve the accuracy of recognition .

4、 Effective pig face images include front face images and side face images , It can carry out multi-directional pig face recognition , Reduce identification error .

5、 After the video source data is processed, the main directory and sub directory of each pig information are established , The main directory is helpful to distinguish from other pigs , The subdirectory is helpful to identify the characteristic information of a single pig , The main directory and sub directory jointly determine the identity information of the pig .

6、 Through a large number of experiments by technicians , The ratio of training set to test set is 4:1 when , It not only ensures the adequacy of data when training the model , And ensure the reliability of the validation data , The recognition accuracy of the pig face recognition model is high .

7、 Set up two symmetrical cameras in each pigsty , It can shoot pig face video in all directions , Avoid shooting dead corners .

Description of drawings

chart 1, Structure diagram of the pigsty .

chart 2, Pig face recognition model training flow chart .

chart 3, Program automation flow chart .

In the attached drawings ,1. pigsty ;2. Pig pen entrance ;3. Drinking water level ;4. Feed chute ;5. camera

Specific embodiments

The specific implementation of the invention will be further described below in combination with the accompanying drawings .

Pictured 1、 chart 2 Sum graph 3 Shown , The embodiment provides a pig face recognition method , It includes the following steps :S1. There will be pig pen entrances 2 More than one pigsty 1 Set side by side , At the entrance of each pigsty 2 On the same horizontal line , Every pigsty 1 There is a drinking place inside 3 And chute 4, At the water table 3 And chute 4 The pig pen entrance is respectively set at the 2 's camera 5;S2. camera 5 At the same time, the entrance to the pigsty 2 Of pigs , Multiple cameras 5 Synchronous acquisition of pig video source data ; In this embodiment , Each pig farm is equipped with 6 A pigsty synchronously collects video source data , Every pigsty 1 Set left and right symmetrical cameras , The format of video source data is MP4 video ;S3. adopt FTP The tool uploads the video source data to the server , On the server side, the video source data is processed by a program to generate a pig face picture ; The video source data collected on the same day passes through FTP Upload the tool to the server , After a period of collection , The server has accumulated more than 25000 Video source data of , The number of pigs exceeds 12500 head , By calling Opencv Standard library method to read video frames , The video frame rate is 25 Frames per second , One hour of video source data has 90000 Frame video image , The video source data of each pig will be generated 90000 A picture of a pig face , The total number of pig face pictures reached 2.25 One hundred million , use Opencv The standard library method saves these pig face pictures , These pig face images include valid pig face images and invalid pig face images ;

S4. Filter and label the pig face pictures , Keep valid pig face image and coordinate information of marked pig face image , The filtered pig face image and the corresponding coordinate information are used as the image data source ;

S5. Train the model of pig face recognition according to the image data source , It includes the following steps :

S51. Convert the picture data source to conform to Tensorflow System format ;

S52. The image source data is divided into training set and test set in proportion ; The ratio of training set to test set is 4:1;

S53. Pass the training set through Tensorflow The training script of the system trains the model that can recognize the pig face ;

S54. The model of pig face recognition is verified by the test set ;

S55. adopt Tensorflow The system exports the script to generate the trained model to recognize the pig face ;

S6. According to the trained pig face recognition model , Automatically process pig face pictures , It includes the following steps :

S61. For steps S3 The obtained pig face image is input into the trained pig face recognition model , adopt Tensorflow The system judges whether the input pig face image contains a valid pig face image and returns the judgment result ;

S62. Decide whether to save the pig face image as a valid pig face image according to the returned judgment result .

among , step S3 The processing of video source data into pig face image is realized through the following steps : use python The language establishes the main directory and sub directories of each pig according to the video source data , And call Opencv The method of the standard library reads the frame of the video source data , Convert the frame into a pig face picture , Store pig face pictures in subdirectories .

step S4, step S61 And steps S62 The effective pig face pictures in include clear front face pictures and side face pictures .

Will step S62 Save as an effective pig face image and call the convolution neural network structure recognition model to calculate the pig face image , Identify the pig ID.

Input : step S62 Valid pig face pictures in ;

Convolution neural network structure model calculation : The convolution neural network structure model is used to calculate whether the pig is a new pig or an existing pig , If a new pig is added, the global unique pig identity will be generated ID, If you already have pigs, you can identify them ID;

Output : The newly created pig identity calculated by convolution neural network structure model ID Or identify the existing pig identity ID.

The above convolution neural network structure model is obtained through the following steps :

ST1: Firstly, a convolutional neural network is constructed to automatically extract pig facial features , And set the training parameters of convolutional neural network ; Then collect the pig face image set with front face and side face as a training sample , The convolutional neural network is trained with the first training sample , Stop training until the set training parameters are reached , That is to generate a pig face feature code generator ;

ST2: The front and side face image sets of a known pig are input into the pig face feature code generator as data sources , After signal processing, the output end of the pig face feature code generator outputs the corresponding feature code of the pig and the pig ID;

ST3: Repeat the above steps ST2, Then the characteristic code of each known pig and its corresponding pig are obtained respectively ID, The characteristic code of each known pig and pig ID That is to say, it constitutes a pig signature library ;

ST4: The convolutional neural network is trained by using the pig characteristic code library as the secondary training sample , Stop training until the set training parameters are reached , That is to generate a pig face classifier ;

ST5: Input the feature code of the pig face picture of the pig to be recognized into the pig face classifier , Output whether the pig is a new pig through the output end of the pig face classifier . Because the front and side face image sets of new pigs have not been entered into the pig face feature code generator , Therefore, there is no record in the pig signature database and pig face classifier .

The convolutional neural network structure may include n Convolution layers 、m Pool layers and k A full link layer , Convolution layer and pooling layer are set in turn , And the pooling layer adopts the pooling method based on the maximum value , among n、m、k Are all ≥1 The integer of .n、m and k The value of can be the same value , It can also be different from each other or the same value . Preferred ,n、m、k Values are 3, That is to say, three full connection layers are used to predict the characteristic response map of the extracted pig characteristic code , Get the similarity score , And output the matching results ; Then we use the error between the matching result and the real result , To train the training parameters of convolutional neural network structure model .

In this embodiment ,Tensorflow The system is an existing artificial intelligence system .

The above description is a detailed description of the preferred and feasible embodiments of the present invention , However, the embodiments are not intended to limit the scope of patent application of the invention , Any equivalent change or modification made under the technical spirit indicated by the invention , All of them belong to the patent scope of the invention .

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151876.html Link to the original text :https://javaforall.cn


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved