更新时间:2023-08-31 21:49:58
如果您正在使用TensorFlow后端,则将为for循环中的每个img建立一个模型。 TensorFlow只是将图形追加到图形等上,这意味着内存刚刚增加。这是一个众所周知的情况,当您要构建许多模型时,必须在超参数优化期间进行处理。
If you are using TensorFlow backend you will be building a model for each img in the for loop. TensorFlow just keeps appending graph onto graph etc. which means memory just rises. This is a well known occurrence and must be dealt with during hyperparameter optimization when you will be building many models, but also here.
from keras import backend as K
并将其放在预测()的末尾:
and put this at the end of predict():
K.clear_session()
或者您可以只构建一个模型并将其作为预测函数的输入,因此不必每次都构建一个新模型。
Or you can just build one model and feed that as input to the predict function so you are not building a new one each time.