建立網路的其他寫法
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Model01 = Sequential([Dense(512, activation='relu', input_dim=3),
Dense(1, activation='sigmoid')])
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Activation
Model02 = Sequential([Dense(512, input_dim=3), Activation('relu'),
Dense(1), Activation('sigmoid')])
Model02.summary()
# 儲存網路配置 config
Config_Model02 = Model02.get_config()
from tensorflow.keras.models import Sequential
Model03 = Sequential.from_config(Config_Model02)
Model03.summary() #會發現與Model02的網路一樣
# 儲存網路配置 json
Config_json_Model03 = Model03.to_json()
from tensorflow.keras.models import model_from_json
Model04 = model_from_json(Config_json_Model03)
# 取得權重
model_weights = model.get_weights()
# 儲存權重
MNIST_Model.save_weights('MNIST.Weights')
# 回復權重
model06.load_weights('MNIST.Weights')
from tensorflow.keras.optimizers import RMSprop
# 修改優化器的預設值
My_RMSprop = RMSprop(learning_rate=0.01)
MNIST_Model.compile(optimizer=My_RMSprop, loss = 'categorical_crossentropy', metrics=['accuracy'])
MNIST_Model.fit(X_train, y_train, epochs=5, batch_size=128, verbose=1)