keras搬磚系列 模型視覺化

2021-08-12 00:15:52 字數 1137 閱讀 8746

當我們在程式設計的時候最怕的不是空氣突然安靜而是不知道我們在寫啥,這篇文章好早就想寫了,可耐拖延症。。。恐怖如斯

keras的視覺化不像tensorboard一樣能夠準確預估。大概能擼出是啥模型

需要安裝的

pip install pydot;pip install pydot-ng;pip install graphviz。還有乙個graphviz.msi,不過我整了很久,在我的anaconda中還是沒法用,只能在命令列中使用。。。。

code:

# encoding: utf-8

import numpy as np

from keras.models import sequential

from keras.layers import dense,activation

from keras.optimizers import sgd

from keras.utils import np_utils

from keras.utils import plot_model

def run():

model = sequential()

model.add(dense(4,input_dim=2))

model.add(activation('relu'))

model.add(dense(2))

model.add(activation('sigmoid'))

sgd = sgd(lr=0.001,decay=1e-6,momentum=0.9,nesterov=true)

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

plot_model(model,to_file='model.png')

if __name__=='__main__':

run()

大概結果:

keras搬磚系列 正則化

1,正則化簡介 以邏輯回歸來對正則化進行介紹 邏輯回歸原來的代價函式為 minw,b j w,b minw,b1m mi 1 l y i y i 其中 w r nx,b r加入正則化為 j w,b 1m mi 1 l y i y i 2 m w 22 其中 w 2 nx j 1 wtw 上述式子為l...

keras搬磚系列 重溫函式式模型

keras函式式模型介面是使用者定義多輸出模型,非迴圈有向模型或具有共享層的模型等複雜模型的途徑。需要多個輸出,應該選擇函式式模型。輸入是張量,輸出也是乙個框架就是乙個模型,通過model定義。from keras.layers import input,dense from keras.model...

keras搬磚系列 正則項

正則項在優化的過程中層的引數或者層的啟用值新增懲罰項,這些懲罰項將與損失函式一起作為網路的最終優化目標。懲罰項是對層進行懲罰,目前懲罰項的介面與層有關。主要由 kernel regularizer 施加在權重上的正則項,為keras.regularizer.regularizer物件 bias re...