def get_all_data_no_split(): import keras ##Grabbing dat, lab = data_grab.all_data(currentdir, data_dir) lab = [0 if x == -1 else 1 for x in lab] dat_n = np.array(dat) lab_n = np.array(lab) lab_n = np.expand_dims(lab_n, axis=1) return dat_n, lab_n
def get_datasets(test=True): import keras ##Grabbing dat, lab = data_grab.all_data(currentdir, data_dir) lab = [0 if x == -1 else 1 for x in lab] dat_n = np.array(dat) lab_n = np.array(lab) lab_n = np.expand_dims(lab_n, axis=1) ## Shuffle at subject level - not slice level dat_index = np.arange(len(dat)) dat_index = np.expand_dims(dat_index, axis=1) if test: X_train_idx, X_test_idx, y_train, y_test = train_test_split( dat_index, lab_n, test_size=0.3, stratify=lab_n) x_train = dat_n[X_train_idx] x_test = dat_n[X_test_idx] x_train = x_train.reshape(x_train.shape[0], 100, 100, 100, 1) x_test = x_test.reshape(x_test.shape[0], 100, 100, 100, 1) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_test /= 255 print('x_train shape:', x_train.shape) print(x_train.shape[0], 'train samples') print(x_test.shape[0], 'test samples') # Convert class vectors to binary class matrices. y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes) else: x_train = dat_n x_train = x_train.reshape(x_train.shape[0], 100, 100, 100, 1) x_train = x_train.astype('float32') x_train /= 255 print('x_train shape:', x_train.shape) print(x_train.shape[0], 'train samples') y_train = keras.utils.to_categorical(lab_n, num_classes) x_test = None y_test = None # Convert class vectors to binary class matrices. #y_train = keras.utils.to_categorical(y_train, num_classes) return x_train, y_train, x_test, y_test
def get_datasets(): def gen_portion(indexes, data, portion=3): ratio = int(indexes.shape[0] / portion) train = data[ratio:, :] test = data[:ratio, :] return train, test ##Grabbing dat, lab = data_grab.all_data(currentdir, data_dir) lab = [0 if x==-1 else 1 for x in lab] dat_n = np.array(dat) lab_n = np.array(lab) lab_n = np.expand_dims(lab_n, axis=1) ## Shuffle at subject level - not slice level dat_index = np.arange(len(dat)) dat_index = np.expand_dims(dat_index, axis=1) X_train_idx, X_test_idx, y_train, y_test = train_test_split(dat_index, lab_n, test_size=0.33, stratify=lab_n) x_train = dat_n[X_train_idx] x_test = dat_n[X_test_idx] x_train = x_train.reshape(x_train.shape[0], 80, 80, 80, 1) x_test = x_test.reshape(x_test.shape[0], 80, 80, 80, 1) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train/=255 x_test/=255 print('x_train shape:', x_train.shape) print(x_train.shape[0], 'train samples') print(x_test.shape[0], 'test samples') # Convert class vectors to binary class matrices. y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes) return x_train, y_train, x_test,y_test
num_classes = 2 epochs = 100 data_augmentation = False save_dir = os.path.join(os.getcwd(), 'saved_models') model_name = 'keras_deepmriqc_cnnv13D_trained_model.h5' def gen_portion(indexes, data, portion=3): ratio = int(indexes.shape[0] / portion) train = data[ratio:, :] test = data[:ratio, :] return train, test ##Grabbing dat, lab = data_grab.all_data() lab = [0 if x == -1 else 1 for x in lab] dat_n = np.array(dat) lab_n = np.array(lab) lab_n = np.expand_dims(lab_n, axis=1) ## Shuffle at subject level - not slice level dat_index = np.arange(len(dat)) dat_index = np.expand_dims(dat_index, axis=1) X_train_idx, X_test_idx, y_train, y_test = train_test_split(dat_index, lab_n, test_size=0.33, stratify=lab_n) #indexes_train_subjects, indexes_test_subjects = gen_portion(dat_index, dat_index)