简体   繁体   English

使用 Keras 在 Tensorflow 2.0 中无需训练即可保存模型

[英]Save model without training in Tensorflow 2.0 with Keras

I use Tensorflow 2.0 and the Keras sequential API to build a model.我使用 Tensorflow 2.0 和 Keras 顺序 API 来构建模型。 I would like to save an untrained model for baseline comparison.我想保存一个未经训练的模型用于基线比较。 How do I do that?我怎么做? I tried to set epochs=0 and period=0 which did not work.我试图设置epochs=0period=0这不起作用。

Here is my code:这是我的代码:

network = NeuralNetwork() # sequential neural network
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath='./models/', save_weights_only=False, period=0)
network.fit(x_train, y_train, epochs=0, callbacks=[cp_callback])

How can I save an untrained model?如何保存未经训练的模型?

You simply have to call model.save after instanciation of your model :您只需在模型实例化后调用 model.save :

network = NeuralNetwork() # sequential neural network
network.save("/your/path/.h5") 

ModelCheckpoint can only be called as a callback, so during the training. ModelCheckpoint 只能作为回调调用,所以在训练期间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow 2.0-Keras培训 - Tensorflow 2.0 - keras training 在 tensorflow2.0 中,如果我使用 tf.keras.models.Model。 我可以通过模型训练批次的数量来评估和保存模型吗? - In tensorflow2.0, if I use tf.keras.models.Model. Can I evaluate and save the model by the number of model training batches? 在没有 Tensorflow 的情况下为生产模式保存 keras 模型 - Save keras model for production mode without Tensorflow 如何使用 Tensorflow 2/Keras 保存和继续训练具有多个模型部分的 GAN - How to save and resume training a GAN with multiple model parts with Tensorflow 2/ Keras 如何在 tensorflow 2.0 w/keras 中保存/恢复大模型? - How to save/restore large model in tensorflow 2.0 w/ keras? Tensorflow 2.0 如何从 Keras 模型导出预测和训练模式 - Tensorflow 2.0 how to export predictions and training-mode from Keras model Tensorflow 2.0 Keras 的训练速度比 2.0 Estimator 慢 4 倍 - Tensorflow 2.0 Keras is training 4x slower than 2.0 Estimator Tensorflow Keras:在 model.fit() 上进行训练 - Tensorflow Keras: Training Holting on model.fit() 用于 tensorflow keras model 训练的 SparseTensor 生成器 - SparseTensor generator for tensorflow keras model training 从 tensorflow 和 keras 中的 mnist 训练 model 的问题 - problem with training model from mnist in tensorflow and keras
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM