Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def _generator(X, Y, win_len, batch_size, num_leads=None):
- """
- :param X: экгшки (все 12 отведений)
- :param y: соотв. им диагнозы
- :param win_len: какиой длины куски экг вырезать
- :param batch_size: сколько пациентов брать в батч
- :return:
- """
- all_ecg_len = X.shape[1]
- num_pacients = X.shape[0]
- while True:
- batch_x = []
- batch_y = []
- for i in range(0, batch_size - 1):
- starting_position = np.random.randint(0, all_ecg_len - win_len)
- ending_position = starting_position + win_len
- rand_pacient_id = np.random.randint(0, num_pacients)
- x = X[rand_pacient_id, starting_position:ending_position, :]
- y = Y[rand_pacient_id]
- batch_x.append(x)
- batch_y.append(y)
- batch_x= np.array(batch_x)
- batch_y = np.array(batch_y)
- if num_leads is not None:
- batch_x = batch_x[:, :, 0:num_leads]
- yield (batch_x, batch_y)
Add Comment
Please, Sign In to add comment