1. 程式人生 > >列印tensorflow恢復模型中所有變數與操作節點

列印tensorflow恢復模型中所有變數與操作節點

       #引數恢復
        self.sess=tf.Session()
        saver = tf.train.import_meta_graph(os.path.join(model_fullpath,'model.ckpt-7.meta'))
        module_file = tf.train.latest_checkpoint(model_fullpath)
        saver.restore(self.sess, module_file)
        variable_names = [v.name for v in tf.trainable_variables()]
        variable_names = [v.name for v in tf.global_variables()]
        values = self.sess.run(variable_names)
        i=0
        for k, v in zip(variable_names, values):
            i+=1
            if k.find('encode')!=-1:
                print(f"第 {i} 個variable")
                print("Variable: ", k)
                print("Shape: ", v.shape)
                print(v)
        graph = tf.get_default_graph()
        all_ops = graph.get_operations()
        for el in all_ops:
            print(el.name)

輸出結果: