landmarks_table = landmarks_excel.sheet_by_index(0) CASIA_test_excel = xlrd.open_workbook('list.xlsx') CASIA_test_table = CASIA_test_excel.sheet_by_index(0) x_data = np.zeros([202599, 39, 39], dtype=np.float32) #input imagematrix_data y_data = np.ones([202599, 10], dtype=np.float32) #correct output landmarks_data CASIA_test = np.zeros([4442, 39, 39], dtype=np.float32) #dataset to be processed newlandmarks = np.zeros(10, dtype=np.float32) ## handle train data for i in range(202599): #train data part 1 #get 39*39 numpy matrix of a single image imagename = landmarks_table.cell(i + 1, 0).value imagematrix = nl.ImageToMatrix(IMAGESAVEURL_F1_CelebA + '\\' + imagename) #extract image size and rawlandmarks data for normalized newlandmarks width = 89 height = 89 rawlandmarks = landmarks_table.row_slice(i + 1, start_colx=1, end_colx=11) #get ten normalized newlandmarks(coordinates of LE,RE,N,LM,RM) for j in range(0, 9, 2): newlandmarks[j] = (rawlandmarks[j].value - 44) / width * 39 for k in range(1, 10, 2): newlandmarks[k] = (rawlandmarks[k].value - 90) / height * 39 #one dimension which represents one grey picture, set the first dimension as index x_data[i, :, :] = imagematrix y_data[i, :] = newlandmarks # read actual test data for i in range(4442):
train_table = train.sheet_by_index(0) test = xlrd.open_workbook('testImageList.xlsx') test_table = test.sheet_by_index(0) x_data = np.zeros([10000, 31, 39], dtype=np.float32) #input imagematrix_data y_data = np.ones([10000, 6], dtype=np.float32) #correct output landmarks_data x_test = np.zeros([3466, 31, 39], dtype=np.float32) y_test = np.ones([3466, 6], dtype=np.float32) newlandmarks = np.zeros(6, dtype=np.float32) ## handle train data for i in range(4151): #train data part 1 #get 39*39 numpy matrix of a single image imagename = train_table.cell(i + 1, 0).value true_imagename = imagename[9:] imagematrix = nl.ImageToMatrix(IMAGESAVEURL_NM1_lfw + '\\' + true_imagename) #extract image size and rawlandmarks data for normalized newlandmarks width = train_table.cell(i + 1, 4).value - train_table.cell(i + 1, 3).value height = train_table.cell(i + 1, 2).value - train_table.cell(i + 1, 1).value rawlandmarks = train_table.row_slice(i + 1, start_colx=9, end_colx=15) #get ten normalized newlandmarks(coordinates of LE,RE,N,LM,RM) for j in range(0, 5, 2): newlandmarks[j] = (rawlandmarks[j].value - train_table.cell( i + 1, 3).value + 0.05 * width) / (1.1 * width) * 39 for k in range(1, 6, 2): newlandmarks[k] = (rawlandmarks[k].value - train_table.cell( i + 1, 1).value - 0.18 * height) / (0.87 * height) * 39 #one dimension which represents one grey picture, set the first dimension as index x_data[i, :, :] = imagematrix y_data[i, :] = newlandmarks
train_table = train.sheet_by_index(0) CASIA_test_excel = xlrd.open_workbook('list.xlsx') CASIA_test_table = CASIA_test_excel.sheet_by_index(0) x_data = np.zeros([10000, 31, 39], dtype=np.float32) #input imagematrix_data y_data = np.ones([10000, 6], dtype=np.float32) #correct output landmarks_data CASIA_test = np.zeros([4442, 31, 39], dtype=np.float32) #dataset to be processed newlandmarks = np.zeros(6, dtype=np.float32) ## handle train data for i in range(4151): #train data part 1 #get 39*39 numpy matrix of a single image imagename = train_table.cell(i + 1, 0).value true_imagename = imagename[9:] imagematrix = nl.ImageToMatrix(IMAGESAVEURL_EN1_lfw + '\\' + true_imagename) #extract image size and rawlandmarks data for normalized newlandmarks width = train_table.cell(i + 1, 4).value - train_table.cell(i + 1, 3).value height = train_table.cell(i + 1, 2).value - train_table.cell(i + 1, 1).value rawlandmarks = train_table.row_slice(i + 1, start_colx=5, end_colx=11) #get ten normalized newlandmarks(coordinates of LE,RE,N,LM,RM) for j in range(0, 5, 2): newlandmarks[j] = (rawlandmarks[j].value - train_table.cell( i + 1, 3).value + 0.05 * width) / (1.1 * width) * 39 for k in range(1, 6, 2): newlandmarks[k] = (rawlandmarks[k].value - train_table.cell( i + 1, 1).value + 0.04 * height) / (0.88 * height) * 39 #one dimension which represents one grey picture, set the first dimension as index x_data[i, :, :] = imagematrix y_data[i, :] = newlandmarks