Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何解决资源枯竭的问题?为什么有这么大的张量?_Python_Tensorflow_Out Of Memory - Fatal编程技术网

Python 如何解决资源枯竭的问题?为什么有这么大的张量?

Python 如何解决资源枯竭的问题?为什么有这么大的张量?,python,tensorflow,out-of-memory,Python,Tensorflow,Out Of Memory,我的损失函数应该是tf.loss.mean_squared_error,但是使用这个函数,就会出现ResourceDeputureError。 因此,我尝试自己实现损失函数: diff = tf.subtract(ground_truth_ph, self.pred, name='sub') loss_op = tf.math.square(diff, name='squared') 我仍然得到错误: ResourceExhaustedError: OOM when allocating t

我的损失函数应该是tf.loss.mean_squared_error,但是使用这个函数,就会出现ResourceDeputureError。 因此,我尝试自己实现损失函数:

diff = tf.subtract(ground_truth_ph, self.pred, name='sub') 
loss_op = tf.math.square(diff, name='squared')
我仍然得到错误:

ResourceExhaustedError: OOM when allocating tensor with shape[1138314,1138314] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
     [[{{node sub}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
My self.pred的形状为(1138314,1),ground_truth_ph(初始化为(None,1))

我不明白为什么需要为元素减法分配这么多内存


提前谢谢

ground\u truth\u ph
tf.placeholder()
的一个实例吗?你能告诉我它是如何实例化的吗?另外,请包括你的代码的其余部分。看起来您看到的错误可能是由所示的两行以外的原因造成的。如果
self.pred
是由神经网络做出的预测,那么做出该预测很可能就是导致错误的原因。上面的两条线不会产生一个平方张量,除非通过一个。