keras中如何保存model的数据,以及如何利用保存的数据

本文利用的demo的是之前写好的: addition_lstm.py, 详细的源代码请看: http://blog.csdn.net/zjm750617105/article/details/51321889

json_string = model.to_json()  #等价于 json_string = model.get_config()
open('my_model_architecture.json','w').write(json_string)  
model.save_weights('my_model_weights.h5')  
#加载模型数据和weights
model = model_from_json(open('my_model_architecture.json').read())  
model.load_weights('my_model_weights.h5')  
a = model.get_config()
print("model config is ",a)
'''
('model config is ', [
{'class_name': 'LSTM', 'config': {'inner_activation': 'hard_sigmoid', 'trainable': True, 'inner_init': 'orthogonal', 'output_dim': 128, 'unroll': False, 'consume_less': 'cpu', 'init': 'glorot_uniform', 'dropout_U': 0.0, 'input_dtype': 'float32', 'batch_input_shape': (None, 7, 12), 'input_length': None, 'dropout_W': 0.0, 'activation': 'tanh', 'stateful': False, 'b_regularizer': None, 'U_regularizer': None, 'name': 'lstm_1', 'go_backwards': False, 'input_dim': 12, 'return_sequences': False, 'W_regularizer': None, 'forget_bias_init': 'one'}},
{'class_name': 'RepeatVector', 'config': {'trainable': True, 'name': 'repeatvector_1', 'n': 4}},
{'class_name': 'LSTM', 'config': {'U_regularizer': None, 'name': 'lstm_2', 'inner_activation': 'hard_sigmoid', 'go_backwards': False, 'activation': 'tanh', 'trainable': True, 'unroll': False, 'consume_less': 'cpu', 'stateful': False, 'init': 'glorot_uniform', 'inner_init': 'orthogonal', 'dropout_U': 0.0, 'dropout_W': 0.0, 'input_dim': 128, 'return_sequences': True, 'b_regularizer': None, 'W_regularizer': None, 'output_dim': 128, 'forget_bias_init': 'one', 'input_length': None}},
{'class_name': 'TimeDistributedDense', 'config': {'input_length': None, 'W_constraint': None, 'b_constraint': None, 'name': 'timedistributeddense_1', 'activity_regularizer': None, 'trainable': True, 'init': 'glorot_uniform', 'input_dim': None, 'b_regularizer': None, 'W_regularizer': None, 'activation': 'linear', 'output_dim': 12}},
{'class_name': 'Activation', 'config': {'activation': 'sigmoid', 'trainable': True, 'name': 'activation_1'}}
])
'''

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">Note that you will first need to install HDF5 and the Python library h5py, which do not come bundled with Keras.</span>

需要安装HDF5 和  h5py , 没有安装成功





  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值