def forwardBackward(xi, x, y, MT, time_queue, good_queue, DELTA_queue): A = neural_forward(xi, x, MT) check = argmax(A[-xi[-1]:]) # send back some progress statistic if y[check]-1 == 0: good = good_queue.get() good += 1 good_queue.put(good) good_queue.task_done() time = time_queue.get() time += 1 time_queue.put(time) time_queue.task_done() DELTA = DELTA_queue.get() DELTA = DELTA + back_propagation(y, A, MT, xi) DELTA_queue.put(DELTA) DELTA_queue.task_done()
def start(self): '''start learning process for zone2 of facial keypoints analysis''' while False: self.data = self.zone2queue.get() self.zone2queue.task_done() self.x = self.data[:,0] self.y = self.data[:,1] self.A = neural_forward(self.xi, self.x, self.MT) self.DELTA = back_propagation(self.y, self.A, self.MT, self.xi) self.errors = sqrt((self.A[-self.xi[1]:]-self.y)**2) self.MT = self.MT - self.alpha*self.DELTA - self.beta*self.MT self.DELTA = 0*self.DELTA if self.counter == self.save_when: savetxt(self.file_out, self.MT, delimiter=',') print 'saved zone2 data to ' + self.file_out + '\t', print 'errors zone2: ' + str(sum(self.errors)) + '\tmax error arg: ' + str(argmax(self.errors)) + '\t MEAE Z2: ' + str(int(amax(self.errors))) + '\tmin error arg: ' + str(argmin(self.errors)) + '\t MinEAE Z2: ' + str(int(amin(self.errors))) self.counter = 0 # reset self.counter += 1
from numpy import * from PIL import Image, ImageDraw from neural_forward import * MTA = genfromtxt('MT_zoneA_backup.csv', delimiter=',') MTB = genfromtxt('MT_zoneB_backup.csv', delimiter=',') data = genfromtxt('mini_mini_training.csv', delimiter=',') data = data[0:10,30:]/255. dims = shape(data) xi1 = [96*96, 30] xi2 = [30, 30] counter=0 for eachline in range(0,dims[0]): x = data[eachline,:] A = neural_forward(xi1, x, MTA)[-30:] B = neural_forward(xi2, A, MTB)[-30:]*96. im = x.reshape((96,96))*255.0 im = Image.fromarray(im).convert('RGB') nums = [2*j for j in range(0,15)] #draw = ImageDraw.Draw(im) #for i in nums: # xcoord = B[i] # ycoord = B[i+1] # print str(xcoord)+', '+str(ycoord) # draw.ellipse((xcoord-1,ycoord-1,xcoord+1,ycoord+1), fill='red', outline='red') imstring = 'fk_'+str(eachline)+'.png' im.save(imstring)
# from numpy import * from neural_forward import * data = genfromtxt('test.csv', delimiter =',')[:,1:]/255. dims = shape(data) MTZ1 = genfromtxt('MT_zoneA.csv', delimiter=',') MTZ2 = genfromtxt('MT_zoneB.csv', delimiter=',') lookup_table = open('IdLookupTable.csv', 'rb') xi1 = [96*96, 30] xi2 = [30, 30] headings = ['left_eye_center_x','left_eye_center_y','right_eye_center_x','right_eye_center_y','left_eye_inner_corner_x','left_eye_inner_corner_y','left_eye_outer_corner_x','left_eye_outer_corner_y','right_eye_inner_corner_x','right_eye_inner_corner_y','right_eye_outer_corner_x','right_eye_outer_corner_y','left_eyebrow_inner_end_x','left_eyebrow_inner_end_y','left_eyebrow_outer_end_x','left_eyebrow_outer_end_y','right_eyebrow_inner_end_x','right_eyebrow_inner_end_y','right_eyebrow_outer_end_x','right_eyebrow_outer_end_y','nose_tip_x','nose_tip_y','mouth_left_corner_x','mouth_left_corner_y','mouth_right_corner_x','mouth_right_corner_y','mouth_center_top_lip_x','mouth_center_top_lip_y','mouth_center_bottom_lip_x','mouth_center_bottom_lip_y'] print 'RowId,Location' for i in range(0,dims[0]): x = data[i,:] z1out = neural_forward(xi1, x, MTZ1) z2in = z1out[-30:] results = neural_forward(xi2, z2in, MTZ2)[-30:] lookup_iterator = open('IdLookupTable.csv', 'rb') for eachline in lookup_iterator: values = eachline.split(',') row_id = int(values[0]) image_id = int(values[1]) feature_name = values[2].rstrip('\r\n') if image_id == i+1: get_value = headings.index(feature_name) print str(row_id) + ',' + str(96*results[get_value])