我的问题是内存泄漏 . 注意:“GPU内存没问题 . ”

环境:

使用Theano后端 . Keras == 1.1.1,Theano == 0.9.0在Ubuntu 16.04上 . 16GB RAM和SWAP . GPU:GTX1080

对于多个输出,训练中的代码是由自己设计的 .
查看以下功能和培训代码 .

功能:

def customGenerator(X,Y1,Y2):
    while True:
        idx = np.random.permutation(X.shape[0])
        datagen = ImageDataGenerator(rescale=1./255)
        batches = datagen.flow( X[idx], batch_size=32, shuffle=False)
        labels = [Y1[idx],Y2[idx]]
        idx0 = 0
        for batch in batches:
            idx1 = idx0 + batch.shape[0]
            yield batch, [labels[0][idx0:idx1],labels[1][idx0:idx1]]
            idx0 = idx1
            if idx1 >= X.shape[0]
                break

培训代码:

model.fit_generator(customGenerator(X_train,Y_train,Y_train2),
                    samples_per_epoch=X_train.shape[0]
                    nb_epoch=nb_epoch,
                    validation_data=customGenerator(X_val,Y_val,Y_val2),
                    nb_val_samples=X_val.shape[0],
                    verbose=1)

在训练网络时,它进入了6个时期并导致内存错误 .
观察存储器状态表明存储器使用率随着时期的推移而增加 .

我认为自定义函数存在问题,但我无法找到问题所在 .

你可以帮帮我吗?