def _load_data(self): utils.thick_line() print('Loading data...') utils.thin_line() if self.cfg.DATABASE_MODE is not None: preprocessed_path_ = join( '../data/{}'.format(self.cfg.DATABASE_MODE), self.cfg.DATABASE_NAME) else: preprocessed_path_ = join(self.cfg.DPP_DATA_PATH, self.cfg.DATABASE_NAME) x = utils.load_pkls(preprocessed_path_, 'x_test' + self.append_info, tl=self.tl_encode, add_n_batch=1) y = utils.load_pkls(preprocessed_path_, 'y_test' + self.append_info) imgs = utils.load_pkls(preprocessed_path_, 'imgs_test' + self.append_info) utils.thin_line() print('Data info:') utils.thin_line() print('x_test: {}\ny_test: {}\nimgs_test: {}'.format( x.shape, y.shape, imgs.shape)) return x, y, imgs
def _load_bottleneck_features(self): """Load preprocessed bottleneck features.""" utils.thick_line() print('Loading data...') utils.thin_line() x_train = utils.load_pkls(self.preprocessed_path, 'x_train') x_valid = utils.load_pkls(self.preprocessed_path, 'x_valid', add_n_batch=1) y_train = utils.load_pkls(self.preprocessed_path, 'y_train') y_valid = utils.load_pkls(self.preprocessed_path, 'y_valid') utils.thin_line() print('Data info:') utils.thin_line() print('x_train: {}\ny_train: {}\nx_valid: {}\ny_valid: {}'.format( x_train.shape, y_train.shape, x_valid.shape, y_valid.shape)) return x_train, y_train, x_valid, y_valid
def _load_data(self): """Load preprocessed data.""" utils.thick_line() print('Loading data...') utils.thin_line() x_train = utils.load_pkls(self.preprocessed_path, 'x_train', tl=self.tl_encode) x_valid = utils.load_pkls(self.preprocessed_path, 'x_valid', tl=self.tl_encode, add_n_batch=1) imgs_train = utils.load_pkls(self.preprocessed_path, 'imgs_train') imgs_valid = utils.load_pkls(self.preprocessed_path, 'imgs_valid') if imgs_train.shape == x_train.shape: print('[W] imgs_train.shape == x_train.shape') del imgs_train del imgs_valid gc.collect() imgs_train = x_train imgs_valid = x_valid y_train = utils.load_pkls(self.preprocessed_path, 'y_train') y_valid = utils.load_pkls(self.preprocessed_path, 'y_valid') utils.thin_line() print('Data info:') utils.thin_line() print('x_train: {}\ny_train: {}\nx_valid: {}\ny_valid: {}'.format( x_train.shape, y_train.shape, x_valid.shape, y_valid.shape)) print('imgs_train: {}\nimgs_valid: {}'.format(imgs_train.shape, imgs_valid.shape)) return x_train, y_train, imgs_train, x_valid, y_valid, imgs_valid
# x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1) # x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1) # # x_train = x_train.astype('float32') # x_test = x_test.astype('float32') # x_train /= 255 # x_test /= 255 # y_train = utils.to_categorical(y_train, num_classes) # y_test = utils.to_categorical(y_test, num_classes) # x_train = mutils.load_pkls('../data/preprocessed_data/mnist', 'x_train') # x_test = mutils.load_pkls('../data/preprocessed_data/mnist', 'x_test') # y_train = mutils.load_pkls('../data/preprocessed_data/mnist', 'y_train') # y_test = mutils.load_pkls('../data/preprocessed_data/mnist', 'y_test') x_train = mutils.load_pkls('../data/preprocessed_data/radical', 'x_train') x_test = mutils.load_pkls('../data/preprocessed_data/radical', 'x_test') y_train = mutils.load_pkls('../data/preprocessed_data/radical', 'y_train') y_test = mutils.load_pkls('../data/preprocessed_data/radical', 'y_test') #准备自定义的测试样本 #对测试集重新排序并拼接到原来测试集,就构成了新的测试集,每张图片有两个不同数字 idx = list(range(len(x_test))) np.random.shuffle(idx) X_test = np.concatenate([x_test, x_test[idx]], 1) Y_test = np.vstack([y_test.argmax(1), y_test[idx].argmax(1)]).T X_test = X_test[Y_test[:, 0] != Y_test[:, 1]] #确保两个数字不一样 Y_test = Y_test[Y_test[:, 0] != Y_test[:, 1]] Y_test.sort(axis=1) #排一下序,因为只比较集合,不比较顺序 # #搭建普通CNN分类模型