十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
小編給大家分享一下關(guān)于keras分類模型中輸入數(shù)據(jù)與標簽維度的案例,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
在《python深度學(xué)習(xí)》這本書中。
一、21頁mnist十分類
導(dǎo)入數(shù)據(jù)集 from keras.datasets import mnist (train_images, train_labels), (test_images, test_labels) = mnist.load_data() 初始數(shù)據(jù)維度: >>> train_images.shape (60000, 28, 28) >>> len(train_labels) 60000 >>> train_labels array([5, 0, 4, ..., 5, 6, 8], dtype=uint8) 數(shù)據(jù)預(yù)處理: train_images = train_images.reshape((60000, 28 * 28)) train_images = train_images.astype('float32') / 255 train_labels = to_categorical(train_labels) 之后: print(train_images, type(train_images), train_images.shape, train_images.dtype) print(train_labels, type(train_labels), train_labels.shape, train_labels.dtype) 結(jié)果: [[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]](60000, 784) float32 [[0. 0. 0. ... 0. 0. 0.] [1. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 1. 0.]] (60000, 10) float32