Ubuntu下面的Keras可视化+权重维度获取-Netron的安装使用
環境:
| Ubuntu | 19.10 |
| Python ? | 3.6.10 |
| Keras | 2.3.1 |
#---------------------------------------------------------------------------------------------------------------------------------------
操作過程如下:
$ snap install netron
$ netron
Serving at http://localhost:8080
然后在瀏覽器打開http://localhost:8080
在Open Model上傳自己的.h5模型即可。
?
#---------------------------------------------------------------------------------------------------------------------------------------
準備好數據集:
tsocks wget https://s3.amazonaws.com/img-datasets/mnist.npz
mv mnist.npz ~/.keras/datasets
#---------------------------------------------------------------------------------------------------------------------------------------
運行如下代碼(來自[1]):
from keras.models import Model from keras.layers import Input, Dense from keras.datasets import mnist from keras.utils import np_utils(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train=x_train.reshape(x_train.shape[0],-1)/255.0 x_test=x_test.reshape(x_test.shape[0],-1)/255.0 y_train=np_utils.to_categorical(y_train,num_classes=10) y_test=np_utils.to_categorical(y_test,num_classes=10)inputs = Input(shape=(784, )) x = Dense(64, activation='relu')(inputs) x = Dense(64, activation='relu')(x) y = Dense(10, activation='softmax')(x)model = Model(inputs=inputs, outputs=y)model.save('m1.h5') model.summary() model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) model.fit(x_train, y_train, batch_size=32, epochs=10) #loss,accuracy=model.evaluate(x_test,y_test)model.save('m2.h5') model.save_weights('m3.h5')運行后我們得到m1,m2,m3三個文件
| 文件名 | 保存的函數 | 保存了圖結構 | 保存了模型參數 | 可否用Neutron打開 |
| m1.h5 | save() | √ | X | √ |
| m2.h5 | save() | √ | √ | √ |
| m3.h5 | save_weights() | X | √ | √ |
m1.h5打開結果
m2.h5打開結果
?
m3.h5打開結果
從上面可以看到權重的維度。
所以如[1]所說,沒啥事兒的話,盡量使用save()而不是save_weights()
#---------------------------------------------------------------------------------------------------------------------------------------
Reference:
[1]keras保存模型中的save()和save_weights()
?
?
?
總結
以上是生活随笔為你收集整理的Ubuntu下面的Keras可视化+权重维度获取-Netron的安装使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 诛仙对战道法怎么提升
- 下一篇: LSTM原理解读汇总