NP2016 Course Summary

Source: Internet
Author: User
Tags svm

Lin Mu SA16222166

    • Course Objectives
    • Course Schedule
    • A1a
    • A2
    • A3
    • Other aspects of the harvest
    • The lesson
Course Objectives

Through the realization of a medical aided diagnosis expert system prototype, in order to achieve the Blood routine test report OCR recognition results, predict the age and gender of the characters, learning machine learning common algorithms, focus on the analysis of neural networks, understand and grasp the use of commonly used algorithms.

Course Schedule
    • Realization of handwritten character recognition system by A1A Neural network
    • Image OCR recognition of A2 blood routine test report
    • A3 predicting age and gender based on data from routine blood tests
Pull Request

A1a

This project belongs to the "Hello world" in the neural network, the goal of this project is to achieve the recognition of the opponent's writing numbers by training a certain amount of numbers. The input image is a 20x20 image with a total of 400 pixels. We add these 400 pixels as input to the input layer of the neural network. We then set the hidden layer to 15 nodes. The output layer is set to 10 nodes, and these 10 nodes are the classification information that the neural network classifies the input image, and we can determine which number is the output. It is then displayed on the Web side.

A2

A2 part of the main is to obtain the test sheet for image preprocessing, using OCR to extract the useful information. such as people's names, time and various test indicators. In this part, my main idea is to use some morphological methods (corrosion expansion) to pre-process the image, the code is as follows:

defpreprocess (Gray):#1. Sobel operator, X-direction gradientSobel = Cv2. Sobel (Gray, Cv2. cv_8u, 1, 0, ksize = 3) Cv2.namedwindow ("Sobel") Cv2.imshow ("Sobel", Sobel) cv2.waitkey (0)#2. Two valueRET, binary = cv2.threshold (Sobel, 0, 255, Cv2. thresh_otsu+Cv2. thresh_binary) Cv2.namedwindow ("binary") Cv2.imshow ("binary", binary) cv2.waitkey (0)#3. Kernel functions for expansion and corrosion operationselement1= Cv2.getstructuringelement (cv2. Morph_rect, (15, 3)) Element2= Cv2.getstructuringelement (cv2. Morph_rect, (17,3))    #4. Inflate once to make the contour stand outdilation = cv2.dilate (binary, element2, iterations = 1) Cv2.namedwindow ("Dilation1") Cv2.imshow ("Dilation1", dilation) cv2.waitkey (0)#5. Corrosion once, remove the details, such as the form line. Note that the vertical line is removed here.erosion = Cv2.erode (dilation, element1, iterations = 1) Cv2.namedwindow ("Erosion") Cv2.imshow ("Erosion", erosion) cv2.waitkey (0)#6. Expand again to make the contour clearDilation2 = cv2.dilate (erosion, element2, iterations = 1) Cv2.namedwindow ("Dilation2") Cv2.imshow ("Dilation2", Dilation2) cv2.waitkey (0)#7. Store the middle pictureCv2.imwrite ("Binary.png", binary) cv2.imwrite ("Dilation1.png", dilation) cv2.imwrite ("Erosion.png", erosion) cv2.imwrite ("Dilation2.png", Dilation2)returnDilation2

Here, it may be explained that the expansion and corrosion operations are performed by a check image for a similar convolution operation, where the expansion operation will make the area of the image larger, and the corrosive operation will make the area of the image smaller. In this example, a gradient is first obtained using a horizontal Sobel operator. In this way, the long horizontal line has been in the horizontal direction, that is, the gradient is approaching 0, after the gradient operation will disappear. Then the swelling--corrosion--expands the operation. The first expansion makes the contour more obvious, the next corrosion operation will remove some noise, the last expansion operation to compensate for the effect of corrosion, so that after the corrosion of the remaining points will be enlarged to make the contour clearer, and the noise will disappear. As shown in the two figure below:

Then, exclude areas where the area is smaller and circle the large area:

Finally, the circled points are taken out and identified using the tesseract.

Finally, however, this approach was abandoned, as numbers and words could not be separated when numbers and text were close together, leading to the identification of numbers and text when words and numbers were identified.

And the last one that was used was the special treatment of the images we were dealing with, the main steps are as follows:

    1. The original image is as follows:

2. Using canny operator to extract edge after opening and closing operation

3. Extract the contours of the three lines with Findcounters:

4. Turn the contour into a line and prepare for the next process, and if more than three lines are selected, the longest three lines will be chosen before the next step. Next, determine the position of the header and footer based on the distance between the three lines:

5. Then, according to the cross-multiplication invariance to determine the starting point, cut down the table for perspective projection transformation.

 

When extracting useful parts, we directly use the distance between the upper and lower lines as a reference distance, so that we can get the coordinates of the pixel points where each column is located, and then extract the exact item name and number. The advantage of this method is that the numbers and text can be precisely separated. However, there may be some problems in changing tables in other formats. Of course, in this project, this method is very efficient and convenient if you only use tables of the same format.

A3

This part of the task is mainly to deal with a large amount of data, and then through the resulting model to predict age and gender. In this section, I used the SVM model in the Sklearn library to achieve a 70% accuracy, the implementation code is as follows:

#coding = Utf-8ImportPickleImportNumPy as NP fromSklearnImportSVM fromSklearnImportMetrics fromSklearn.cross_validationImportTrain_test_splitdefextract (filename): X= Np.loadtxt (filename, skiprows= 1,delimiter=',', usecols= (3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28)) Y= Np.loadtxt (filename, dtype='string', skiprows= 1,delimiter=',', usecols= (1,))  forIinchRange (len (y)):ifY[i] = ='\xc4\xd0': Y[i]= 1Else: Y[i]=0returnx, ydefsplit_test (x, y): X_train, X_test, Y_train, Y_test= Train_test_split (X, y, test_size=0.1)    returnX_train, X_test, Y_train, Y_testdefSave_model (model,name): Pickle.dump (model, open (str)+'. PKL','W'))defLoad_model (name): Model= Pickle.load (The Open (str (name) +'. PKL'))    returnModelif __name__=="__main__": X, y= Extract ('Train.csv') X_train, X_test, Y_train, Y_test=split_test (X, y) CLF= SVM. SVC (kernel='Linear', gamma=0.7, C = 1.0). Fit (X_train, y_train) y_predicted=clf.predict (x_test)PrintMetrics.classification_report (y_test, y_predicted)Print    Print "Test_accuracy_score"    PrintMetrics.accuracy_score (y_test, y_predicted) Save_model (CLF,'Sex') X, y=extract ('Predict.csv') Clf2= Load_model ('Sex') y2_predicted=clf2.predict (X)Print "Accuracy_score"    PrintMetrics.accuracy_score (y, y2_predicted)

Support Vector Machines (SVM) is a classification algorithm, which can improve the generalization ability of the learning machine by seeking the minimum structure risk, realize the minimization of the experience risk and the confidence range, so as to achieve the goal of good statistic law under the circumstance of less statistic sample quantity. In layman's terms, it is a two-class classification model, whose basic model is defined as the most spaced linear classifier on the feature space, that is, the learning strategy of support vector machine is to maximize the interval, and finally can be transformed into a convex two-time programming problem solution.

SVM is developed from the optimal classification surface of the linear sub-conditions. The optimal classification surface is that the classification line can not only separate the two classes correctly (training error rate bit 0), and make the classification interval maximum. SVM is looking for a super plane that satisfies the classification requirements, and is the point distance classification surface of the training set as far as possible, that is, to find a classification surface so that the blank area (margin) on both sides is the largest. A training sample of H1,H2 on a super plane that is closest to the classification surface and parallel to the optimal classification surface in two categories is called a support vector. This is also the origin of the name of the support vector machine.

  

About the specific content of support vector machine, you can refer to the hands-on teaching you to implement the SVM algorithm this series of articles.

NP2016 Course Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.