栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Keras中从HDF5文件加载模型?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Keras中从HDF5文件加载模型?

load_weights
仅设置网络的权重。您仍然需要在调用之前定义其体系结构
load_weights

def create_model():   model = Sequential()   model.add(Dense(64, input_dim=14, init='uniform'))   model.add(LeakyReLU(alpha=0.3))   model.add(BatchNormalization(epsilon=1e-06, mode=0, momentum=0.9, weights=None))   model.add(Dropout(0.5))    model.add(Dense(64, init='uniform'))   model.add(LeakyReLU(alpha=0.3))   model.add(BatchNormalization(epsilon=1e-06, mode=0, momentum=0.9, weights=None))   model.add(Dropout(0.5))   model.add(Dense(2, init='uniform'))   model.add(Activation('softmax'))   return modeldef train():   model = create_model()   sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)   model.compile(loss='binary_crossentropy', optimizer=sgd)   checkpointer = ModelCheckpoint(filepath="/tmp/weights.hdf5", verbose=1, save_best_only=True)   model.fit(X_train, y_train, nb_epoch=20, batch_size=16, show_accuracy=True, validation_split=0.2, verbose=2, callbacks=[checkpointer])def load_trained_model(weights_path):   model = create_model()   model.load_weights(weights_path)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/641433.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号