Guest User

Untitled

a guest
Aug 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def _generator(X, Y, win_len, batch_size, num_leads=None):
  4. """
  5.  
  6. :param X: экгшки (все 12 отведений)
  7. :param y: соотв. им диагнозы
  8. :param win_len: какиой длины куски экг вырезать
  9. :param batch_size: сколько пациентов брать в батч
  10. :return:
  11. """
  12.  
  13. all_ecg_len = X.shape[1]
  14. num_pacients = X.shape[0]
  15.  
  16. while True:
  17. batch_x = []
  18. batch_y = []
  19. for i in range(0, batch_size - 1):
  20. starting_position = np.random.randint(0, all_ecg_len - win_len)
  21. ending_position = starting_position + win_len
  22. rand_pacient_id = np.random.randint(0, num_pacients)
  23.  
  24. x = X[rand_pacient_id, starting_position:ending_position, :]
  25. y = Y[rand_pacient_id]
  26. batch_x.append(x)
  27. batch_y.append(y)
  28.  
  29. batch_x= np.array(batch_x)
  30. batch_y = np.array(batch_y)
  31. if num_leads is not None:
  32. batch_x = batch_x[:, :, 0:num_leads]
  33. yield (batch_x, batch_y)
Add Comment
Please, Sign In to add comment