我尝试通过以下代码来训练我的模型。
sess.run([train_op, model.global_step, model.loss, model.prediction], feed_dict)
但是,当我运行“model.prediction”时,我发现内存使用量动态增加。
我从不在迭代过程中保留“sess.run()”的结果。
“模型.预测”是
@property
def prediction(self):
return [tf.argmax(self.logits_b, 1),
tf.argmax(self.logits_m, 1),
tf.argmax(self.logits_s, 1),
tf.argmax(self.logits_d, 1)]
我不知道为什么会这样。 请帮助我。
最佳答案
每次使用属性预测
时,您都会在图中创建新的操作。您应该只预先创建一次操作并将它们返回到属性中:
def create_model(self):
# Hypothetical function that creates the model, only called once
# ...
self._prediction = (tf.argmax(self.logits_b, 1),
tf.argmax(self.logits_m, 1),
tf.argmax(self.logits_s, 1),
tf.argmax(self.logits_d, 1))
# ...
@property
def prediction(self):
return self._prediction
关于python - sess.run 动态增加内存使用量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53634675/