当前位置: 首页 > wzjs >正文

个人可以做慈善网站吗搜索引擎优化的含义和目标

个人可以做慈善网站吗,搜索引擎优化的含义和目标,宁波建设网住建委,用软件做seo网站关键词推广1、model.save() and model.load() 此种方法可保存模型的结构、参数等内容。加载模型后无需设置即可使用! 保存模型: model.save(my_model.h5) 加载模型: # 加载整个模型 loaded_model tf.keras.models.load_model(my_model.h5) 注意&…

1、model.save() and model.load()

此种方法可保存模型的结构、参数等内容。加载模型后无需设置即可使用!

保存模型:

model.save('my_model.h5')

加载模型:

# 加载整个模型
loaded_model = tf.keras.models.load_model('my_model.h5')

注意,创建的模型不能使用自定义的loss函数等方法,否则导入时会出错!

示例:

model_file = "data/model/multi_labels_model.h5"    # 模型文件路径
def model_handle(x_train, y_train):if os.path.exists(model_file):print("---load the model---")model = tf.keras.models.load_model(model_file) # 导入已存在的模型else:# 模型构建model = tf.keras.Sequential([tf.keras.layers.LSTM(128),tf.keras.layers.Dense(class_num, activation='softmax', kernel_regularizer=tf.keras.regularizers.l2())])# 编译模型,不能使用自定义函数方法,否则导入模型会有问题model.compile(loss="BinaryCrossentropy", optimizer='adam', metrics=['accuracy'])history = model.fit(x_train, y_train, epochs=epoch_num, batch_size=1, verbose=1, callbacks=[PrintPredictionsCallback(x_train, y_train)])model.summary()model.save(model_file)return model

2、model.save_weight() and model.load_weight()

此方法只保存和加载模型的权重。

保存权重:

# 只保存权重
model.save_weights('my_model_weights.h5')

加载权重:

# 创建一个新的模型实例(确保架构与原始模型相同)
new_model = tf.keras.models.Sequential([tf.keras.layers.Dense(10, activation='relu', input_shape=(32,)),tf.keras.layers.Dense(1)
])
# new_model.build(input_shape=x_train.shape) # 如果模型创建时没有规定input_shape,需要创建
# 加载权重到新模型
new_model.load_weights('my_model_weights.h5')

此方法的模型可以使用自定义的函数方法。

注意:以H5格式加载子类模型的参数时,需要提前建立模型,规定输入网络的shape,否则会报错!

ValueError: Unable to load weights saved in HDF5 format into a subclassed Model which has not created its variables yet. Call the Model first, then load the weights.

示例:

def model_handle(x_train, y_train):# 模型构建,多分类的激活函数使用sigmoid 或 softmaxmodel = tf.keras.Sequential([tf.keras.layers.LSTM(128),tf.keras.layers.Dense(class_num, activation='softmax', kernel_regularizer=tf.keras.regularizers.l2())])if os.path.exists(model_file):print("-----load model weights-----")model.build(input_shape=x_train.shape)  # 以H5格式加载子类模型的参数时,需要提前建立模型,规定输入网络的shape,否则会报错model.load_weights(model_file)else:# 编译模型,使用自定义loss函数model.compile(loss=custom_loss, optimizer='adam', metrics=['accuracy'])# model.compile(loss="BinaryCrossentropy", optimizer='adam', metrics=['accuracy'])history = model.fit(x_train, y_train, epochs=epoch_num, batch_size=1, verbose=1, callbacks=[PrintPredictionsCallback(x_train, y_train)])model.summary()model.save_weights(model_file)return model

3、model.checkpoint

主要是用于模型的断点续训。用法参考如下:

checkpoint_save_path = "./checkpoint/my_checkpoint.ckpt"if os.path.exists(checkpoint_save_path + '.index'):print('-------------load the model-----------------')model.load_weights(checkpoint_save_path)cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_save_path,save_weights_only=True,save_best_only=True,monitor='val_loss')history = model.fit(x_train, y_train, batch_size=64, epochs=50, validation_data=(x_test, y_test), validation_freq=1,callbacks=[cp_callback])model.summary()

http://www.dtcms.com/wzjs/396298.html

相关文章:

  • 莱芜手机网站建设电话关键词是什么意思
  • 动漫网站开发毕业设计百度网站大全首页
  • 深圳乐安居网站谁做的免费广告网
  • 万维网站2021最火营销方案
  • jtbc网站开发教程市场营销方案怎么写
  • 武汉网站建设服务网站seo方案策划书
  • google网站建设广东网站seo策划
  • 教人怎么做网页的网站视频推广平台
  • 一个网站需要什么广告营销策略
  • 建设部网站官网 施工许可百度指数怎么查
  • 政府部门网站模版中国教育培训网
  • 网站建设免备案免费空间带佣金的旅游推广平台有哪些
  • 桂林腾达网是什么网seo搜索推广费用多少
  • 凡客网站建立百度搜索风云榜单
  • 成都网站建设 培训班2023网站seo
  • 南宁手机平台网站百度指数分是什么
  • 昌吉州住房和城乡建设局网站阿里云建网站
  • 网站上百度要怎么做的迅雷磁力链bt磁力天堂
  • 旅游景区宣传软文seo排名赚下载
  • 设计素材网站酷p哪家公司做推广优化好
  • 未来的门户网站重庆二级站seo整站优化排名
  • 苏州做网站优化哪家好宁波关键词网站排名
  • 帝国cms做中英文网站网上营销网站
  • 信用平台网站建设建议2022最新永久地域网名
  • asp 网站 购物车sem竞价课程
  • Wordpress 建站 软件网址域名查询
  • 自学html做网站要多久下载百度 安装
  • 怎么做网站的学校的大图可口可乐软文营销案例
  • 十大室内设计师排名页面seo优化
  • 珠海做网站需要多少钱百度明星人气榜