zoukankan      html  css  js  c++  java
  • tensorflow如何加载模型

    #https://blog.csdn.net/huachao1001/article/details/78501928
    import data01
    import tensorflow as tf
    import numpy as np
    
    # 读入测试数据
    # 导入数据
    print("loading data... ")
    X_train, y_train = data01.get_mstar_data("train", 64, 64, 96)
    X_test, y_test = data01.get_mstar_data("test", 64, 64, 96)
    
    X_train = np.reshape(X_train, [X_train.shape[0], X_train.shape[1] * X_train.shape[2]])
    X_test = np.reshape(X_test, [X_test.shape[0], X_test.shape[1] * X_test.shape[2]])
    print(X_train.shape, y_train.shape)
    print(X_test.shape, y_test.shape)
    
    print("shuffling ... ")
    X_train, y_train = data01.data_shuffle(X_train, y_train)
    X_test, y_test = data01.data_shuffle(X_test, y_test)
    
    print("one_hot ...")
    y_train, y_test = data01.one_hot(y_train, y_test)
    print(y_train.shape)
    print(y_test.shape)
    
    # 将每一张图片用一个64x64的矩阵表示
    X_train = X_train.reshape(-1, 64, 64, 1)
    X_test = X_test.reshape(-1, 64, 64, 1)
    print(X_train.shape)
    print(X_test.shape)
    
    # 主要的程序
    with tf.Session() as sess:
    
        # 1.先加载图和参数变量
        saver = tf.train.import_meta_graph('model/sar10.ckpt.meta')
        saver.restore(sess, tf.train.latest_checkpoint('model/'))
    
        # 2.访问placeholders变量,并且创建feed-dict来作为placeholders的新值
        graph = tf.get_default_graph()
        X = graph.get_tensor_by_name("X:0")
        Y = graph.get_tensor_by_name("Y:0")
        feed_dict = {X:X_test,Y: y_test}
    
        # 接下来,访问你想要执行的op
        predict_op = graph.get_tensor_by_name("predict_op:0")
        corr_te = np.mean(np.argmax(y_test, axis=1) == sess.run(predict_op, feed_dict=feed_dict))
    

      

  • 相关阅读:
    SHELL种类,版本及选择
    delete
    ctrl+alt+l:linux 锁屏 win+l:windows锁屏
    inux关于readlink函数获取运行路径的小程序
    网络版shell之网络编程练习篇--telnet服务端
    CentOS 6.5配置nfs服务
    linux操作系下RAR的使用
    BLOB二进制对象(blob.c/h)
    循环队列
    java的System.getProperty()方法能够获取的值
  • 原文地址:https://www.cnblogs.com/wylwyl/p/10868290.html
Copyright © 2011-2022 走看看