zoukankan      html  css  js  c++  java
  • Keras模型保存的几个方法和它们的区别

    github博客传送门
    csdn博客传送门

    Keras模型保存简介

    model.save()

    model_save_path = "model_file_path.h5"
    # 保存模型
    model.save(model_save_path)
    # 删除当前已存在的模型
    del model
    # 加载模型
    from keras.models import load_model
    model = load_model(model_save_path)
    

    model.save_weights()

    model_save_path = "model_file_path.h5"
    # 保存模型权重
    model.save_weights(model_save_path)
    # 加载模型权重
    model.load_weights(model_save_path)
    

    model.to_json()

    # 保存模型网络结构
    json_string = model.to_json()
    with open("model_save_file.json", "w") as f:
    	f.write(json_string)  # 将模型转为json文件后的字符串写入本地
    # 读取模型网络结构	
    from keras.models import model_from_json
    with open("model_save_file.json", "r") as f:
    	json_string = f.read()  # 读取本地模型的json文件
    model = model_from_json(json_string)  # 创建一个模型
    

    model.to_yaml()

    # 保存模型网络结构
    yaml_string = model.to_yaml()
    with open("model_save_file.yaml", "w") as f:
    	f.write(yaml_string)  # 将模型转为yaml文件后的字符串写入本地
    # 读取模型网络结构	
    from keras.models import model_from_yaml
    with open("model_save_file.yaml", "r") as f:
    	yaml_string = f.read()  # 读取本地模型的yaml文件
    model = model_from_yaml(yaml_string)  # 创建一个模型
    

    现在我们来说说这四种保存模型的联系与区别

    项目 是否保存模型结构 是否保存模型权重 是否能继续训练网络 是否能进行模型预测
    model.save()
    model.save_weights()
    model.to_json() 加载权重后能进行正常预测
    model.to_yaml() 加载权重后能进行正常预测
    如有测试错误,欢迎指正.谢了.
    print_r('点个赞吧');
    var_dump('点个赞吧');
    NSLog(@"点个赞吧!")
    System.out.println("点个赞吧!");
    console.log("点个赞吧!");
    print("点个赞吧!");
    printf("点个赞吧!
    ");
    cout << "点个赞吧!" << endl;
    Console.WriteLine("点个赞吧!");
    fmt.Println("点个赞吧!")
    Response.Write("点个赞吧");
    alert(’点个赞吧’)
    
  • 相关阅读:
    andrid 上传图片 asp.net 后台接收并保存
    Volley封装
    error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.
    The type android.support.v4.view.ScrollingView cannot be resolved. It is indirectly referenced from
    Recyclerview 实现上拉加载更多
    RecyclerAdapter封装
    项目中自己一直用到的baseAdapter的类
    SwipeRefreshLayout 和RecyclerView 使用
    DrawerLayout 使用
    学习动态性能表 v$sql
  • 原文地址:https://www.cnblogs.com/Mrzhang3389/p/10746300.html
Copyright © 2011-2022 走看看