Functional模型
导入functional模型
导入Keras函数模型入门
from keras.models import Model
from keras.layers import Dense, Input
inputs = Input(shape=(100,))
x = Dense(64, activation='relu')(inputs)
predictions = Dense(10, activation='softmax')(x)
model = Model(inputs=inputs, outputs=predictions)
model.compile(loss='categorical_crossentropy',optimizer='sgd', metrics=['accuracy'])model.save('full_model.h5') # save everything in HDF5 format
model_json = model.to_json() # save just the config. replace with "to_yaml" for YAML serialization
with open("model_config.json", "w") as f:
f.write(model_json)
model.save_weights('model_weights.h5') # save just the weights.载加你的Keras模型
KerasModel
Last updated
Was this helpful?