我有一个DDPG类,它是张量流神经网络。当我添加self.saver = tf.train.Saver()
时会报告错误
“文件” C:\ Users \ Harry \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ training \ saver.py“,行1131,在_build中 引发ValueError(“没有要保存的变量”)“
这是我的代码的一部分。
def __init__(self, action_dimension, state_dimension):
self.memory = np.zeros((MEMORY_CAPACITY, state_dimension*2+action_dimension+1), dtype = np.float32)
self.memory_pointer = 0
self.sess = tf.Session()
self.action_dimension = action_dimension
self.state_dimension = state_dimension
# define state space as x * state dimension matrix
self.current_state = tf.placeholder(tf.float32, [None, state_dimension], 'current_state')
self.next_state = tf.placeholder(tf.float32, [None, state_dimension], 'next_state') # same as above
self.reward = tf.placeholder(tf.float32, [None, 1], 'reward')
self.saver = tf.train.Saver()
def save_model(self):
path = self.saver.save(self.sess, "/saved_model/model.ckpt")
print("Model saved in path: %s" % path)
def load_model(self):
self.saver.restore(self.sess, "/saved_model/model.ckpt")
print("Model restored.")
我想知道我在做什么是错误的?谢谢。
答案 0 :(得分:0)
可能是因为您尚未初始化变量。如果您在声明所有变量之后且在您之前运行tf global variables initializer
self.saver
你应该没事