Keras 中文文件學習筆記 快速上手Keras

2021-08-14 10:11:50 字數 1698 閱讀 5238

基於中文官方文件與英文官方文件的學習筆記,較系統的總結學習歷程。

keras的核心資料結構是「模型」,模型是一種組織網路層的方式。keras中主要的模型是sequential模型,sequential是一系列網路層按順序構成的

# -*- coding: utf-8 -*-

"""created on sun jan 7 22:17:57 2018

keras快速上手

@author: brucewong

"""#匯入sequential模型

import keras

from keras.models import sequential,model

## generate dummy data

import numpy as np

x_train = np.random.random((1000, 20))

y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)

x_test = np.random.random((100, 20))

y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)

model = sequential()

#model.add()

#將一些網路通過.add()堆疊起來,就構成乙個完整的模型

from keras.layers import dense,activation

#model.add(dense(units = 64,input_dim = 20)) #輸入維度input_dim,指x資料的維度,列的數量

model.add(dense(units = 64,input_shape = (20,)))#輸入維度input_dim

model.add(activation('relu'))

model.add(dense(units = 10))

model.add(activation('softmax'))

#完成模型的搭建後,我們需要使用.compile()方法來編譯模型

model.compile(loss='categorical_crossentropy',optimizer = 'sgd',metrics = ['accuracy'])

#編譯模型時必須指明損失函式和優化器,如果你需要的話,也可以自己定製損失函式。

#完成編譯後,在訓練資料集上按batch進行一定次數的迭代來訓練網路

model.fit(x_train,y_train,epochs=5,batch_size = 32)

'''#也可以手動乙個個batch的資料送人網路中訓練:

#model.train_on_batch(x_batch,y_batch)

'''#隨後可以對模型進行評估:

loss_and_metrics = model.evaluate(x_test,y_test,batch_size = 128)

#或者對新的資料進行**:

classes = model.predict(x_test,batch_size = 128)

Hugo中文文件 快速開始

1.二進位制安裝 推薦 簡單 快速 mac下直接使用homebrew安裝 brew install hugo2.原始碼安裝 原始碼編譯安裝,首先安裝好依賴的工具 設定好gopath環境變數,獲取原始碼並編譯 如果需要更新所有hugo的依賴庫,增加 u引數 go get u v github.com ...

react 中文文件學習筆記(一)

function tick setinterval tick,1000 定時器,setinterval tick,1000 每一秒重新整理一次。class welcome extends react.component function welcome props const element rea...

golang中文文件 Golang學習筆記

最近在學習go語言,花了兩周看完了 the go programming language 和 go in action 並看了乙個原始碼,訊息佇列 nsq。以便更好地掌握這門語言。現在深入了解golang標準庫的內容和一些原始碼的實現。學習的過程中記錄golang的知識點,以便以後鞏固知識點。1 ...