03_process_data.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import numpy as np
  2. import os
  3. AU = ["Person", "Case", "Confidence", "AU01", "AU02", "AU04", "AU05", "AU06", "AU07", "AU09","AU10","AU12","AU14","AU15","AU17","AU20","AU23",
  4. "AU25","AU26", "AU45"]
  5. # folder where output csv files of OpenFace are stored
  6. folder = '/home/valapil/Project/ForkCausal_Adithya/csv_files'
  7. csv_files = [file for file in os.listdir(folder) if file.endswith('.csv')]
  8. # load the offset values
  9. offset = np.load(f'/home/valapil/Project/ForkCausal_Adithya/offset_values.npy')
  10. length = {}
  11. same = np.unique(offset[1:, 0])
  12. for i in same:
  13. same_rows = offset[offset[:, 0] == i]
  14. length[i] = max(abs(int(same_rows[0][2]) - int(same_rows[0][1])), abs(int(same_rows[1][2]) - int(same_rows[1][1])))
  15. for file in csv_files:
  16. base_name, extension = os.path.splitext(file)
  17. new_name = base_name.split('.')[0]
  18. f1 = new_name[:-2]
  19. f2 = new_name[-1:]
  20. file_path = os.path.join(folder, file)
  21. len = length[new_name[:-3] + new_name[-1]]
  22. start = np.where(offset[1:, 3] == new_name)[0][0]
  23. start = int(offset[start+1, 1])
  24. data_all = np.genfromtxt(file_path, delimiter=',', skip_header=1)
  25. data = data_all[start:len-200, 679:696]
  26. selected_columns = np.hstack((np.full((data.shape[0], 2), [f1, f2]), data_all[start:len-200, [3]], data))
  27. AU = np.row_stack((AU, selected_columns))
  28. # save each offset data here
  29. np.save(f'/home/valapil/Project/ForkCausal_Adithya/data/{new_name}.npy', data)
  30. # save all offset data with the particular case and confidence value here
  31. np.save(f'/home/valapil/Project/ForkCausal_Adithya/processed_data.npy', AU)