def make_and_save_dataset(patch_len, name, leads_names): json_data = select_and_load_json() numpy_data = get_numpy_from_json(json_data, patch_len, leads_names) file_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".json" np_to_json(numpy_data, file_path) print("np dataset saved to " + str(file_path)) print("shape: " + str(numpy_data.shape))
def save_np_u_selectors(cutted_signals_batch, contexts_batch, name): signal_patches_filename = PATH_TO_SELECTORS + name + ".sig" measurs_filename = PATH_TO_SELECTORS + name + ".conext" np_to_json(np.array(cutted_signals_batch), signal_patches_filename) np_to_json(np.array(contexts_batch), measurs_filename) print("Saved signal: " + signal_patches_filename) print("Saved context: " + measurs_filename)
def save_sample(np_validities, np_measuremens, name): path = PATH_TO_SAMPLES_FROM_MODELS + name val_name = path + ".valid" meas_name = path + ".measur" np_to_json(np_validities, val_name) np_to_json(np_measuremens, meas_name) print('Saved: ' + val_name + ", of shape "+ str(np_validities.shape)) print('Saved: ' + meas_name + ", of shape "+ str(np_validities.shape))
def downsample_and_save_np_dataset(name, np_arr=None): if np_arr is None: np_arr = select_and_load_np_data() downsampled_np = downsample_dataset(np_arr) path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".np" np_to_json(downsampled_np, path) print("np dataset saved to " + str(path)) print("shape: " + str(downsampled_np.shape))
def make_and_save_random_dataset(patch_len, name, leads_names, amount_of_patches): json_data = select_and_load_json() numpy_data, numpy_labels = get_numpy_from_json(json_data, patch_len, leads_names, amount_of_patches) signal_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".np" np_to_json(numpy_data, signal_path) label_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".sig" np_to_json(numpy_labels, label_path) print("np dataset saved to " + str(signal_path)) print("shape: " + str(numpy_data.shape))
def show_and_save_output(batch_size, name, gen_model=None): if gen_model is None: gen_model = restore_model_from_file() z, label_input_one_hot, code_input, label_input_int\ = sample_input_for_generator(gen_model, batch_size) gen_model.cuda() out = gen_model(z, label_input_one_hot, code_input) np_out = out.cpu().detach().numpy() show_np_dataset_1st_lead(np_out) #---------save it as dataset------ file_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".json" np_to_json(np_out, file_path) print("np dataset saved to " + str(file_path))
def experiment(patch_len, dispersion): leads_names = ['i'] from settings import PATH_TO_METADATASETS_FOLDER name = str(patch_len) + "_t_i_normal_cs_stdepr" + str(int(dispersion)) path1 = PATH_TO_METADATASETS_FOLDER + "\\7_pacients_ideally_healthy_and_normal_axis.json" json_data1 = select_and_load_json(path1) numpy_data1, labels1 = get_numpy_from_json(json_data1, patch_len, leads_names) meta_label1 = np.full(labels1.shape, 0) path2 = PATH_TO_METADATASETS_FOLDER + "\\st_depression6.json" json_data2 = select_and_load_json(path2) numpy_data2, labels2 = get_numpy_from_json(json_data2, patch_len, leads_names) meta_label2 = np.full(labels2.shape, 1) numpy_data = np.concatenate((numpy_data1, numpy_data2)) shift_labels = np.concatenate((labels1, labels2)) meta_labels = np.concatenate((meta_label1, meta_label2)) numpy_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".np" label_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".labels_shifts" meta_labels_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".labels_meta" np_to_json(numpy_data, numpy_path) np_to_json(shift_labels, label_path) np_to_json(meta_labels, meta_labels_path) print("np dataset saved to " + str(numpy_path)) print("shape: " + str(numpy_data.shape))
def make_and_save_from2jsons(patch_len, name, leads_names): json_data1 = select_and_load_json() numpy_data1, labels1 = get_numpy_from_json(json_data1, patch_len, leads_names) meta_label1 = np.full(labels1.shape, 0) json_data2 = select_and_load_json() numpy_data2, labels2 = get_numpy_from_json(json_data2, patch_len, leads_names) meta_label2 = np.full(labels2.shape, 1) numpy_data = np.concatenate((numpy_data1, numpy_data2)) shift_labels = np.concatenate((labels1, labels2)) meta_labels = np.concatenate((meta_label1, meta_label2)) numpy_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".np" label_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".labels_shifts" meta_labels_path = PATH_TO_NUMPY_DATA_FOLDER + "\\" + name + ".labels_meta" np_to_json(numpy_data, numpy_path) np_to_json(shift_labels, label_path) np_to_json(meta_labels, meta_labels_path) print("np dataset saved to " + str(numpy_path)) print("shape: " + str(numpy_data.shape))