小编use*_*067的帖子

tf.keras model.predict 导致内存泄漏

在谷歌 Colab 工作。使用tf.kerastensorflow版本2.3.0我变得疯狂,因为我无法使用我训练过的模型来运行预测,model.predict因为它耗尽了CPU RAM。我已经能够用一个非常小的例子重现这个问题。

import numpy as np
import tensorflow as tf
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Input,Conv2D, Activation

matrixSide = 512 #define a big enough matrix to give memory issues

inputL = Input([matrixSide,matrixSide,12]) #create a toy model
l1 = Conv2D(32,3,activation='relu',padding='same') (inputL) #120
l1 = Conv2D(64,1,activation='relu',padding='same')(l1)
l1 = Conv2D(64,3,activation='relu',padding='same')(l1)
l1 = Conv2D(1,1,padding='same')(l1)
l1 = Activation('linear')(l1)
model = Model(inputs= inputL,outputs = l1)


#run predictions
inImm = np.zeros((64,matrixSide,matrixSide,12))
for i in range (60):
  print(i) …
Run Code Online (Sandbox Code Playgroud)

python keras tensorflow google-colaboratory

18
推荐指数
4
解决办法
1万
查看次数

标签 统计

google-colaboratory ×1

keras ×1

python ×1

tensorflow ×1