| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import numpy as np
- from numpy import save
- import os
- # AU = ["AU01", "AU02", "AU04", "AU05", "AU06", "AU07", "AU09","AU10","AU12","AU14","AU15","AU17","AU20","AU23",
- # "AU25","AU26","AU45","AU01_c","AU02_c","AU04_c","AU05_c","AU06_c","AU07_c","AU09_c","AU10_c","AU12_c","AU14_c","AU15_c","AU17_c",
- # "AU20_c","AU23_c","AU25_c","AU26_c","AU28_c","AU45_c"]
- reference_au = ["File", "AU01", "AU02", "AU04", "AU05", "AU06", "AU07", "AU09","AU10","AU12","AU14","AU15","AU17","AU20","AU23",
- "AU25","AU26", "AU45"]
- # finding reference values
- ref_au = {}
- ref = []
- # get all offset data
- data_all = np.load(f'/home/valapil/Project/ForkCausal_Adithya/processed_data.npy')
- # data = np.concatenate(data_all[:3], data_all[4:])
- data = np.delete(data_all, 2,1)
- activation = []
- unique = np.unique(data[1:, 0])
- for i in unique:
- same_rows = data[data[:, 0] == i]
- mean = np.mean(same_rows[:, 2:19].astype(np.float64), axis=0)
- std = np.std(same_rows[:, 2:19].astype(np.float64), axis=0)
- ref_au = mean + (0.5 * std)
- # ref_au.append(mean + (0.5 * std))
- ref = np.hstack((i, ref_au))
- reference_au = np.row_stack((reference_au, ref))
- # folder where each offset data is stored
- folder = '/home/valapil/Project/ForkCausal_Adithya/data'
- csv_files = [file for file in os.listdir(folder) if file.endswith('.npy')]
- for file in csv_files:
- EXP = ["Happiness upper", "Happiness lower", "Surprise upper", "Surprise lower", "Disgust lower", "Fear upper",
- "Fear lower", "Sadness upper", "Sadness lower", "Anger upper", "Anger lower"]
- # Get data
- file_path = os.path.join(folder,file)
- # data = np.genfromtxt(file_path, delimiter=',', skip_header=1)
- data = np.load(file_path)
- # find the particular person
- base_name, extension = os.path.splitext(file)
- new_name = base_name.split('.')[0]
- f1 = new_name[:-2]
- selected_columns = data
- index = np.where(reference_au[1:, 0] == f1)[0]
- # AU activation
- change = np.subtract(selected_columns, reference_au[index+1, 1:].astype(np.float16))
- activation = np.where(change >= 0, 1, 0)
- expression_labels = np.zeros((activation.shape[0], 11), dtype=int)
- # Define expressions based on specific AUs
- expression_labels[:, 0] = np.any(activation[:, [4]], axis=1) # AU06 is 4th au in order. [4] to get results with []
- expression_labels[:, 1] = np.all(activation[:, [8, 14]], axis=1) # AU12 and AU25
- expression_labels[:, 2] = np.all(activation[:, [0, 1, 3]], axis=1) # AU01, AU02, AU05
- expression_labels[:, 3] = np.any(activation[:, [15]], axis=1) # AU26
- expression_labels[:, 4] = np.all(activation[:, [6, 7, 14]], axis=1) # AU09, AU10, AU25
- expression_labels[:, 5] = np.all(activation[:, [0, 1, 2, 3]], axis=1) # AU01, AU02, AU04, AU05
- expression_labels[:, 6] = np.all(activation[:, [12, 14]], axis=1) # AU20, AU25
- expression_labels[:, 7] = np.all(activation[:, [0, 2]], axis=1) # AU01, AU04
- expression_labels[:, 8] = np.all(activation[:, [10, 11]], axis=1) # AU15, AU17
- expression_labels[:, 9] = np.all(activation[:, [2, 3, 5]], axis=1) # AU04, AU05, AU07
- expression_labels[:, 10] = np.all(activation[:, [11, 13]], axis=1) # AU17, AU23
- EXP = np.row_stack((EXP, expression_labels))
- # Save the result to a new NumPy file
- # Each file has expressions for each frame based on activation of AU in that frame
- np.save(f'/home/valapil/Project/ForkCausal_Adithya/test/{new_name}.npy', EXP)
|