No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_train_data.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. import params
  3. import cv2
  4. import numpy as np
  5. def train_data(file_name):
  6. file_location = "/raw_data/balanced_data/" + file_name
  7. loaded_data = np.load(file_location)
  8. # change the saved data into the form that both human and NN can understand
  9. for data in loaded_data:
  10. # flip the frame because the webcam is mounted upside down on the front windsheild, and cut out the sky portion of the image the size became 256*66
  11. tmp = cv2.flip(data[0],0)
  12. tmp = cv2.flip(tmp,1)
  13. if params.img_channels != 3:
  14. tmp = cv2.cvtColor(tmp, cv2.COLOR_BGR2GRAY)
  15. data[0] = (tmp[70:-5,::]).reshape(params.img_height,params.img_width,params.img_channels)
  16. # change the can data (HEX) to numerical data
  17. tmp = data[1]
  18. hex_data = tmp[-23:-21] + tmp[-20:-18]
  19. hex_decimal = tmp[-3:-1]
  20. int_data = int(hex_data, 16)
  21. int_decimal = int(hex_decimal, 16) / 256
  22. # if the steering wheel angle in in right to the center
  23. if(int_data > 550):
  24. int_data = int_data - 4096
  25. int_decimal = 1 - int_decimal
  26. final_data = int_data - int_decimal
  27. else:
  28. # put the int and the decimal together
  29. final_data = int_data + int_decimal
  30. data[1] = final_data
  31. #print(final_data)
  32. #did cut out the first few frames because the webcam need time to adjust the exposure
  33. # but seems like still the white out frames exist
  34. #loaded_data = loaded_data[30:]
  35. train_X = np.array([i[0] for i in loaded_data]).reshape([-1, params.img_height,params.img_width,params.img_channels])
  36. train_Y = np.array([i[1] for i in loaded_data]).reshape([-1,1])
  37. return train_X, train_Y
  38. #finishing making the training data