def __data_generation(self, list_IDs_temp): 'Generates data containing batch_size samples' # X : (n_samples, *dim, n_channels) # Initialization X = np.empty((self.batch_size, *self.dim, self.n_channels), dtype = float) y = np.empty((self.batch_size), dtype = int) # Generate data for i, ID in enumerate(list_IDs_temp): data = extend_ts(self.h5file[ID]['ecgdata'][:, 0], self.sequence_length) data = np.reshape(data, (1, len(data))) if self.augment: # dropout bursts data = zero_filter(data, threshold = 2, depth = 10) # random resampling data = random_resample(data) # Generate spectrogram data_spectrogram = spectrogram(data, nperseg = self.nperseg, noverlap = self.noverlap)[2] # Normalize data_transformed = norm_float(data_spectrogram, self.data_mean, self.data_std) X[i,] = np.expand_dims(data_transformed, axis = 3) # Assuming that the dataset names are unique (only 1 per label) y[i] = self.labels[ID] return X, keras.utils.to_categorical(y, num_classes=self.n_classes)
def __data_generation(self, list_IDs_temp): 'Generates data containing batch_size samples' # X : (n_samples, *dim, n_channels) # Initialization X = np.empty((self.batch_size, *self.dim, self.n_channels), dtype=float) y = np.empty((self.batch_size), dtype=int) # Generate data for i, ID in enumerate(list_IDs_temp): data = extend_ts(self.h5file[ID]['ecgdata'][:, 0], self.sequence_length) data = np.reshape(data, (1, len(data))) if self.augment: # dropout bursts data = zero_filter(data, threshold=2, depth=10) # random resampling data = random_resample(data) # Generate spectrogram data_spectrogram = spectrogram(data, nperseg=self.nperseg, noverlap=self.noverlap)[2] # Normalize spectrogram #data_transformed = norm_float(data_spectrogram, self.data_mean, self.data_std) data_norm = (data_spectrogram - np.mean(data_spectrogram)) / np.std(data_spectrogram) X[i, ] = np.expand_dims(data_norm, axis=3) # Assuming that the dataset names are unique (only 1 per label) y[i] = self.labels[ID] return X, keras.utils.to_categorical(y, num_classes=self.n_classes)
plt.tight_layout() plt.show() fig.savefig('physionet_ECG_spectrogram.png', bbox_inches='tight', dpi=150) from physionet_processing import zero_filter, random_resample data_zero = [] # collect the zero burst data here data_resampled = [] # list for resampled data runs = 4 for i in range(runs): data_zero.append( zero_filter(np.expand_dims(ts_extended, axis=0), threshold=2, depth=10)[0]) data_resampled.append( random_resample(np.expand_dims(ts_extended, axis=0))[0]) # Plot the result fig, axarr = plt.subplots(runs, 2, figsize=(15, 8)) x_lim = [6, 8] # zoom in on x axis x_ticks = np.arange(x_lim[0], x_lim[1] + 0.5, 0.5) # ticks x_label = 'Time [s]' y_label = 'Potential [mV]' for row in range(runs): # Plot the dropout burst data ax = axarr[row, 0] ax.plot(time, ts_extended, 'k') ax.plot(time, data_zero[row], 'r') ax.set(xlim=x_lim, xticks=x_ticks)