这篇教程h5 to ckpt写得很实用,希望能帮到您。
3.2.2. h5 to ckpt
import tensorflow as tf
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"]="1"
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
tf.keras.backend.set_session(tf.Session(config=config))
path_to_save_ckpt = '/path/to/keras-ckpt'
model = tf.keras.applications.VGG16()
model_name = 'vgg16'
var_list = slim.get_variables_to_restore(include=None, exclude=['predictions'])
saver = tf.train.Saver(var_list)
saver.save(tf.keras.backend.get_session(),
os.path.join(path_to_save_ckpt, model_name + '.ckpt'))
saver = tf.train.Checkpoint()
model = keras.models.load_model('Model.hdf5', compile=False)
sess = tf.compat.v1.keras.backend.get_session()
save_path = saver.save('model.ckpt') 返回列表 keras学习-不同网络模型融合 |