python-3.x - tensorflow 在使用 tf.map_fn 时消耗太多内存
问题描述
我有以下代码:
@tf.function
def c(self, point_instances, instances, alpha):
def inner_comp(j):
print(j.shape)
print(tf.transpose(instances).shape)
print(alpha.shape)
print(tf.linalg.matvec(tf.transpose(instances), alpha).shape)
tmp = tf.tensordot(j, tf.linalg.matvec(tf.transpose(instances), alpha), 1)
print(tmp.shape)
return tmp
return tf.reduce_max(tf.abs(tf.map_fn(inner_comp, point_instances)))
我注意到当tf.map_fn
完成第二次迭代时,由于内存不足,它被杀死了。所以控制台输出如下:
(245245,)
(245245, 460)
(460,)
(245245,)
()
(245245,)
(245245, 1040)
(1040,)
(245245,)
()
Killed
虽然我的数据是大规模的,但输出的inner_comp
始终是标量。我试图分配 200 GB 的内存,但它仍然被杀死。原因是什么?
解决方案
推荐阅读
- mysql - 跨表获取 mysql 中的总销售额数据。查询超时
- python-2.7 - python setup.py egg_info" 失败,错误代码 1 在 /tmp/pip-install-vdozlB/libvirt-python/
- angular - 如何使用角度 4 在两个 mat-select 中检索对象数组
- java - 从 S3 存储桶访问时出现 java.io.FileNotFoundException?
- javascript - 使用 react-dates 和 setState 不起作用
- python - Python:将变量传递给导入的函数与将循环和字典保持在同一模块中
- javascript - Angular 4 - 在可观察订阅中对“this”的引用似乎是指旧数据
- python - 通过 Trie 搜索问题
- d3.js - D3 - 将每个数据类别绑定到 g
- shake-build-system - 根据 node_modules 目录摇动