@@ -0,0 +1,2445 @@
+from skimage import io%0Aimport numpy as np%0Aimport os%0Afrom sklearn import svm%0Afrom sklearn.decomposition import PCA%0Afrom sklearn.model_selection import GridSearchCV%0A%0A#open tagged filelist%0Afh = open(%22truthtable_new_16July2016.csv%22,%22r%22)%0A%0A#read truthtable into memory%0Afh.readline()%0Adata = fh.readlines()%0Afh.close()%0A%0A#initialise arrays for data%0A#dataset shape is size of flattened image array length*width in pixels%0A#the first column labels the data as having eggs present or not%0A#this is a bit of a hack%0Adataset = np.zeros((1,788066))%0A%0Aprint %22INFO: Building dataset%22%0A%0A#interate through list of tagged files and find ones that exist%0Afor line in data:%0A%0A    line = line.split(%22,%22)%0A    line%5B0%5D = line%5B0%5D%5B1:-1%5D%0A%0A    #images are expected to be unzipped into a directory called images%0A    path = %22images/%22+line%5B0%5D    %0A    isfile = os.path.isfile(path)%0A%0A    #if file exist, add contents to data arrays%0A    if isfile==True:%0A%0A        #check if eggs are expected in the image%0A        eggs = int(line%5B1%5D.rstrip())%0A        if eggs%3E0:%0A            eggs=1%0A%0A        #import image%0A        image = io.imread(path,as_grey=True)%0A        image = np.reshape(image,(788065,1))%0A%0A        #join image array and label%0A        example = np.vstack((eggs,image))%0A        #this is a row vector with label and image%0A        example = np.transpose(example) %0A%0A        #append to data array%0A        dataset = np.vstack((dataset,example))%0A%0A#remove first row from initialisation%0A#this is a hack%0Adataset = dataset%5B1:%5D%0A%0A#initialise classifier%0Aclassifier = svm.SVC()%0A%0A#save this many data samples from the dataset for testing%0Atest_samples = 14%0A%0A#setup training and test data and target arrays%0Atraining_data = dataset%5B:-test_samples,1:%5D%0Atraining_target = dataset%5B:-test_samples,0%5D%0A%0Atest_data = dataset%5B-test_samples:,1:%5D%0Atest_target = dataset%5B-test_samples:,0%5D%0A%0A#pca, todo grid search parameters for PCA%0An_comp = 50%0Aprint(%22INFO: PCA, n_components=%22+str(n_comp))%0Apca = PCA(n_components=n_comp,whiten=True,svd_solver='auto')%0Apca.fit(training_data)%0Atraindata_pca = pca.transform(training_data)%0Atest_pca = pca.transform(test_data)%0A%0A#train model via grid search%0Aprint(%22INFO: Grid search%22)%0Agsc = GridSearchCV(estimator=svm.SVC(),%0A                param_grid=%7B 'C': %5B1, 2, 3, 4, 5%5D,%0A                'kernel': %5B 'linear', 'poly', 'rbf', 'sigmoid' %5D %7D,%0A                cv=5 )%0Agsc.fit(traindata_pca,training_target)%0A%0A#print results%0Ares = gsc.score(test_pca,test_target)%0Aprint(%22%253f%22%25(res))%0A#result 0.714%0A

add python script to detect that can detect presence of eggs