資源簡介
數(shù)據(jù)集為usps手寫數(shù)據(jù)集(.mat形式),共9298張圖片,維度16*16,內(nèi)附有python版的使用代碼

代碼片段和文件信息
import?numpy?as?np??#用于數(shù)據(jù)處理
import?matplotlib.pyplot?as?plt??#?用于展示圖片
import?scipy.io?as?sio??#?用于讀取.mat
def?load_dataset(dataset=‘usps‘):
????#?加載usps數(shù)據(jù)集
????if?dataset?==?‘usps‘:
????????data?=?sio.loadmat(‘usps_resampled.mat‘)
????????x_train?y_train?x_test?y_test?=?data[‘train_patterns‘].T?data[‘train_labels‘].T?data[‘test_patterns‘].T?data[‘test_labels‘].T
????????x?=?np.concatenate((x_train?x_test))
????????y_train?=?[np.argmax(l)?for?l?in?y_train]??#?將onehot編碼轉(zhuǎn)成一般編碼
????????y_test?=?[np.argmax(l)?for?l?in?y_test]??#?將onehot編碼轉(zhuǎn)成一般編碼
????????y?=?np.concatenate((np.array(y_train)?np.array(y_test))).astype(np.int32)
????????x?=?x.reshape((-1?16?16?1)).astype(np.float32)???#?便于使用卷積層
????????#?x?=?x.reshape((x.shape[0]?16*16)).astype(np.float32)???#?便于使用全連接層
????????x?=?np.divide(x?255.)??#?歸一化
????????print(‘USPS:‘?x.shape?y.shape)??#?(9298?16?16?1)
????????return?x?y
????else:
????????print(‘The?dataSet?name?is?useless‘)
????????exit(0)
def?show_figure(data):??#?顯示前200張圖片
????digit_size?=?data.shape[1]??#?16?或者?28
????data?=?np.squeeze(data)??#?去掉1維
????figure?=?np.zeros((digit_size?*?10?digit_size?*?20))
????t?=?0
????for?i?in?range(10):??#?10行
????????for?j?in?range(20):??#?每行展示20個數(shù)據(jù)
????????????figure[i?*?digit_size:?(i+1)?*?digit_size?j?*?digit_size:?(j+1)?*?digit_size]?=?data[t]
????????????t?=?t?+?1
????plt.figure(figsize=(15?15))
????plt.imshow(figure)
????plt.show()
if?__name__?==?‘__main__‘:
????#?load?dataset
????x?y?=?load_dataset(‘usps‘)
????print(y[:200])??#?展示前200個樣本的標(biāo)簽
????show_figure(x)??#?展示前200個樣本數(shù)據(jù)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-05-25?10:11??usps手寫數(shù)據(jù)集+使用代碼\
?????文件????????1759??2020-05-25?10:14??usps手寫數(shù)據(jù)集+使用代碼\test_usps.py
?????文件????19228688??2006-03-13?20:48??usps手寫數(shù)據(jù)集+使用代碼\usps_resampled.mat
評論
共有 條評論